Ensure MQTT messages are only set if state actually changed

This commit is contained in:
Pim van Pelt
2018-11-05 08:04:21 +01:00
parent b7467e3be1
commit 06241f2581

View File

@ -327,8 +327,10 @@ void channel_override_set(int idx) {
match = timespec_match_now(s_channels[idx].timespec);
if (match != s_channels[idx].relay_state) {
LOG(LL_INFO, ("User state disagrees with timespec, setting override"));
s_channels[idx].channel_override = true;
mqtt_publish_stat("override", "{idx: %d, relay_state: %d, override: %B}", idx, s_channels[idx].relay_state, s_channels[idx].channel_override);
if (!s_channels[idx].channel_override) {
s_channels[idx].channel_override = true;
mqtt_publish_stat("override", "{idx: %d, relay_state: %d, override: %B}", idx, s_channels[idx].relay_state, s_channels[idx].channel_override);
}
return;
}
if (s_channels[idx].channel_override && (match == s_channels[idx].relay_state)) {
@ -345,8 +347,10 @@ void channel_override_clear(int idx) {
return;
}
s_channels[idx].channel_override = false;
mqtt_publish_stat("override", "{idx: %d, relay_state: %d, override: %B}", idx, s_channels[idx].relay_state, s_channels[idx].channel_override);
if (s_channels[idx].channel_override) {
mqtt_publish_stat("override", "{idx: %d, relay_state: %d, override: %B}", idx, s_channels[idx].relay_state, s_channels[idx].channel_override);
s_channels[idx].channel_override = false;
}
return;
}