check if sensortoggle is populated (#501)

Not sure if it will find any edge case.  The use of .getValues() should be programmed in a different way.
This commit is contained in:
unlogisch04
2025-12-05 00:36:01 +01:00
committed by GitHub
parent 8469b6fac6
commit a6aefdfe60

View File

@@ -123,14 +123,21 @@ void Configuration::save() {
file.write((uint8_t*)&config, sizeof(SensorConfig));
file.close();
sprintf(path, DIR_TOGGLES "/%zu", i);
if (i < m_SensorToggles.size()) {
sprintf(path, DIR_TOGGLES "/%zu", i);
m_Logger.trace("Saving sensor toggle state for %d", i);
m_Logger.trace("Saving sensor toggle state for %d", i);
file = LittleFS.open(path, "w");
auto toggleValues = m_SensorToggles[i].getValues();
file.write((uint8_t*)&toggleValues, sizeof(SensorToggleValues));
file.close();
file = LittleFS.open(path, "w");
auto toggleValues = m_SensorToggles[i].getValues();
file.write((uint8_t*)&toggleValues, sizeof(SensorToggleValues));
file.close();
} else {
m_Logger.trace(
"Skipping saving toggles for sensor %d, no toggles present",
i
);
}
}
{