From 41f76c51287fa65388e40770672249ed71cfd08b Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Tue, 3 Sep 2019 22:27:54 +0200 Subject: [PATCH] Add restore power state when limit is restored Add restore power state when limit is restored (#6340) --- sonoff/sonoff.ino | 7 ++++--- sonoff/xdrv_03_energy.ino | 4 ++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/sonoff/sonoff.ino b/sonoff/sonoff.ino index 7368294a3..05d72c8d9 100755 --- a/sonoff/sonoff.ino +++ b/sonoff/sonoff.ino @@ -598,10 +598,11 @@ void SetAllPower(uint8_t state, int source) } } -void RestoreAllPower(power_t power_set, int source) +void RestorePower(power_t power_set, int source) { - if (power != power_set) { - SetDevicePower(power, source); + power_t new_state = power | power_set; + if (power != new_state) { + SetDevicePower(new_state, source); MqttPublishAllPowerState(); } } diff --git a/sonoff/xdrv_03_energy.ino b/sonoff/xdrv_03_energy.ino index d18a62960..7962c628d 100644 --- a/sonoff/xdrv_03_energy.ino +++ b/sonoff/xdrv_03_energy.ino @@ -342,7 +342,7 @@ void EnergyMarginCheck(void) if (Energy.mplr_counter) { Response_P(PSTR("{\"" D_JSON_POWERMONITOR "\":\"%s\"}"), GetStateText(1)); MqttPublishPrefixTopic_P(RESULT_OR_STAT, PSTR(D_JSON_POWERMONITOR)); - RestoreAllPower(Energy.mp_last_power, SRC_MAXPOWER); + RestorePower(Energy.mp_last_power, SRC_MAXPOWER); } else { Response_P(PSTR("{\"" D_JSON_MAXPOWERREACHEDRETRY "\":\"%s\"}"), GetStateText(0)); MqttPublishPrefixTopic_P(STAT, S_RSLT_WARNING); @@ -360,7 +360,7 @@ void EnergyMarginCheck(void) Energy.max_energy_state = 1; Response_P(PSTR("{\"" D_JSON_ENERGYMONITOR "\":\"%s\"}"), GetStateText(1)); MqttPublishPrefixTopic_P(RESULT_OR_STAT, PSTR(D_JSON_ENERGYMONITOR)); - RestoreAllPower(Energy.me_last_power, SRC_MAXENERGY); + RestorePower(Energy.me_last_power, SRC_MAXENERGY); } else if ((1 == Energy.max_energy_state ) && (energy_daily_u >= Settings.energy_max_energy)) { Energy.max_energy_state = 2;