Skip to content

Commit

Permalink
Add Domoticz safeguards
Browse files Browse the repository at this point in the history
  • Loading branch information
arendst committed Apr 18, 2024
1 parent 13cbf26 commit 9b5df76
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions tasmota/tasmota_xdrv_driver/xdrv_07_domoticz.ino
Original file line number Diff line number Diff line change
Expand Up @@ -110,17 +110,21 @@ int DomoticzRssiQuality(void) {
}

uint32_t DomoticzRelayIdx(uint32_t relay) {
if (relay >= MAX_RELAYS_SET) { return 0; }
return (relay < MAX_DOMOTICZ_IDX) ? Settings->domoticz_relay_idx[relay] : Domoticz->relay_idx[relay -MAX_DOMOTICZ_IDX];
}

void DomoticzSetRelayIdx(uint32_t relay, uint32_t idx) {
if (relay >= MAX_RELAYS_SET) { return; }
if (relay < MAX_DOMOTICZ_IDX) {
Settings->domoticz_relay_idx[relay] = idx;
} else {
Domoticz->relay_idx[relay -MAX_DOMOTICZ_IDX] = idx;
}
}

/*********************************************************************************************/

#ifdef USE_SONOFF_IFAN
void MqttPublishDomoticzFanState(void) {
if (Settings->flag.mqtt_enabled && DomoticzRelayIdx(1)) { // SetOption3 - Enable MQTT
Expand All @@ -136,10 +140,12 @@ void MqttPublishDomoticzFanState(void) {
}

void DomoticzUpdateFanState(void) {
if (Domoticz->update_flag) {
MqttPublishDomoticzFanState();
if (Domoticz) {
if (Domoticz->update_flag) {
MqttPublishDomoticzFanState();
}
Domoticz->update_flag = true;
}
Domoticz->update_flag = true;
}
#endif // USE_SONOFF_IFAN

Expand Down Expand Up @@ -174,12 +180,16 @@ void MqttPublishDomoticzPowerState(uint8_t device) {
}

void DomoticzUpdatePowerState(uint8_t device) {
if (Domoticz->update_flag) {
MqttPublishDomoticzPowerState(device);
if (Domoticz) {
if (Domoticz->update_flag) {
MqttPublishDomoticzPowerState(device);
}
Domoticz->update_flag = true;
}
Domoticz->update_flag = true;
}

/*********************************************************************************************/

void DomoticzMqttUpdate(void) {
if (Domoticz->subscribe && (Settings->domoticz_update_timer || Domoticz->update_timer)) {
Domoticz->update_timer--;
Expand Down Expand Up @@ -515,7 +525,6 @@ void DomoticzSensorP1SmartMeter(char *usage1, char *usage2, char *return1, char
DomoticzSensor(DZ_P1_SMART_METER, data);
}


/*********************************************************************************************/

void DomoticzInit(void) {
Expand Down

0 comments on commit 9b5df76

Please sign in to comment.