mirror of
https://github.com/arendst/Tasmota.git
synced 2025-07-28 13:16:32 +00:00
Fix UFS Domoticz regression when no relays/devices are configured
This commit is contained in:
parent
063ea6af3e
commit
86d5b3e727
@ -153,11 +153,13 @@ bool DomoticzSaveData(void) {
|
|||||||
"\"Update\":%u"),
|
"\"Update\":%u"),
|
||||||
Domoticz->Settings.crc32,
|
Domoticz->Settings.crc32,
|
||||||
Domoticz->Settings.update_timer);
|
Domoticz->Settings.update_timer);
|
||||||
|
if (TasmotaGlobal.devices_present) {
|
||||||
ResponseAppend_P(PSTR(",\"Relay\":"));
|
ResponseAppend_P(PSTR(",\"Relay\":"));
|
||||||
for (uint32_t i = 0; i < TasmotaGlobal.devices_present; i++) {
|
for (uint32_t i = 0; i < TasmotaGlobal.devices_present; i++) {
|
||||||
ResponseAppend_P(PSTR("%c%d"), (0==i)?'[':',', Domoticz->Settings.relay_idx[i]);
|
ResponseAppend_P(PSTR("%c%d"), (0==i)?'[':',', Domoticz->Settings.relay_idx[i]);
|
||||||
}
|
}
|
||||||
ResponseAppend_P(PSTR("]"));
|
ResponseAppend_P(PSTR("]"));
|
||||||
|
}
|
||||||
if (Domoticz->keys) {
|
if (Domoticz->keys) {
|
||||||
ResponseAppend_P(PSTR(",\"Key\":"));
|
ResponseAppend_P(PSTR(",\"Key\":"));
|
||||||
for (uint32_t i = 0; i < Domoticz->keys; i++) {
|
for (uint32_t i = 0; i < Domoticz->keys; i++) {
|
||||||
@ -248,7 +250,9 @@ void DomoticzSettingsLoad(bool erase) {
|
|||||||
void DomoticzSettingsSave(void) {
|
void DomoticzSettingsSave(void) {
|
||||||
// Called from FUNC_SAVE_SETTINGS every SaveData second and at restart
|
// Called from FUNC_SAVE_SETTINGS every SaveData second and at restart
|
||||||
uint32_t crc32 = GetCfgCrc32((uint8_t*)&Domoticz->Settings +4, sizeof(DzSettings_t) -4); // Skip crc32
|
uint32_t crc32 = GetCfgCrc32((uint8_t*)&Domoticz->Settings +4, sizeof(DzSettings_t) -4); // Skip crc32
|
||||||
|
if (TasmotaGlobal.devices_present) {
|
||||||
crc32 += GetCfgCrc32((uint8_t*)Domoticz->Settings.relay_idx, TasmotaGlobal.devices_present * sizeof(uintdz_t));
|
crc32 += GetCfgCrc32((uint8_t*)Domoticz->Settings.relay_idx, TasmotaGlobal.devices_present * sizeof(uintdz_t));
|
||||||
|
}
|
||||||
if (Domoticz->keys) {
|
if (Domoticz->keys) {
|
||||||
crc32 += GetCfgCrc32((uint8_t*)Domoticz->Settings.key_idx, Domoticz->keys * sizeof(uintdz_t));
|
crc32 += GetCfgCrc32((uint8_t*)Domoticz->Settings.key_idx, Domoticz->keys * sizeof(uintdz_t));
|
||||||
}
|
}
|
||||||
@ -725,11 +729,13 @@ void DomoticzSensorP1SmartMeter(char *usage1, char *usage2, char *return1, char
|
|||||||
/*********************************************************************************************/
|
/*********************************************************************************************/
|
||||||
|
|
||||||
void DomoticzInit(void) {
|
void DomoticzInit(void) {
|
||||||
if (Settings->flag.mqtt_enabled && TasmotaGlobal.devices_present) { // SetOption3 - Enable MQTT
|
if (Settings->flag.mqtt_enabled) { // SetOption3 - Enable MQTT
|
||||||
Domoticz = (Domoticz_t*)calloc(1, sizeof(Domoticz_t)); // Need calloc to reset registers to 0/false
|
Domoticz = (Domoticz_t*)calloc(1, sizeof(Domoticz_t)); // Need calloc to reset registers to 0/false
|
||||||
if (nullptr == Domoticz) { return; }
|
if (nullptr == Domoticz) { return; }
|
||||||
|
|
||||||
|
if (TasmotaGlobal.devices_present) {
|
||||||
Domoticz->Settings.relay_idx = (uintdz_t*)calloc(TasmotaGlobal.devices_present, sizeof(uintdz_t));
|
Domoticz->Settings.relay_idx = (uintdz_t*)calloc(TasmotaGlobal.devices_present, sizeof(uintdz_t));
|
||||||
|
if (nullptr == Domoticz->Settings.relay_idx) { return; }
|
||||||
for (uint32_t i = 0; i < TasmotaGlobal.devices_present; i++) {
|
for (uint32_t i = 0; i < TasmotaGlobal.devices_present; i++) {
|
||||||
if (ButtonUsed(i)) { Domoticz->keys++; }
|
if (ButtonUsed(i)) { Domoticz->keys++; }
|
||||||
if (SwitchUsed(i)) { Domoticz->switches++; }
|
if (SwitchUsed(i)) { Domoticz->switches++; }
|
||||||
@ -742,9 +748,10 @@ void DomoticzInit(void) {
|
|||||||
Domoticz->Settings.switch_idx = (uintdz_t*)calloc(Domoticz->switches, sizeof(uintdz_t));
|
Domoticz->Settings.switch_idx = (uintdz_t*)calloc(Domoticz->switches, sizeof(uintdz_t));
|
||||||
if (nullptr == Domoticz->Settings.switch_idx) { return; }
|
if (nullptr == Domoticz->Settings.switch_idx) { return; }
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
AddLog(LOG_LEVEL_DEBUG, PSTR(D_LOG_DOMOTICZ "Support %d Device(s), %d Button(s) and %d Switch(es)"),
|
AddLog(LOG_LEVEL_DEBUG, PSTR(D_LOG_DOMOTICZ "Support %d Device(s), %d Button(s), %d Switch(es) and %d Sensors"),
|
||||||
TasmotaGlobal.devices_present, Domoticz->keys, Domoticz->switches);
|
TasmotaGlobal.devices_present, Domoticz->keys, Domoticz->switches, DZ_MAX_SENSORS);
|
||||||
|
|
||||||
DomoticzSettingsLoad(0);
|
DomoticzSettingsLoad(0);
|
||||||
Domoticz->update_flag = true;
|
Domoticz->update_flag = true;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user