Skip to content

Commit

Permalink
Add restore power state when limit is restored
Browse files Browse the repository at this point in the history
Add restore power state when limit is restored (#6340)
  • Loading branch information
arendst committed Sep 3, 2019
1 parent 1478f16 commit 41f76c5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
7 changes: 4 additions & 3 deletions sonoff/sonoff.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Expand Down
4 changes: 2 additions & 2 deletions sonoff/xdrv_03_energy.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
Expand Down

0 comments on commit 41f76c5

Please sign in to comment.