Skip to content

Commit

Permalink
Improvements on PWM cycle reset
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexwijn committed Dec 31, 2024
1 parent cf69a41 commit 4d6bca4
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions custom_components/sat/pwm.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ async def update(self, requested_setpoint: float, boiler: BoilerState) -> None:
self._last_boiler_temperature = boiler.temperature
_LOGGER.debug("Initialized last boiler temperature to %.1f°C", boiler.temperature)

if self._first_duty_cycle_start and (monotonic() - self._first_duty_cycle_start) > 3600:
if self._first_duty_cycle_start is None or (monotonic() - self._first_duty_cycle_start) > 3600:
self._cycles = 0
self._first_duty_cycle_start = None
_LOGGER.info("CYCLES count reset after an hour.")
self._first_duty_cycle_start = monotonic()
_LOGGER.info("CYCLES count reset for the rolling hour.")

elapsed = monotonic() - self._last_update
self._duty_cycle = self._calculate_duty_cycle(requested_setpoint, boiler)
Expand All @@ -98,9 +98,6 @@ async def update(self, requested_setpoint: float, boiler: BoilerState) -> None:
# State transitions for PWM
if self._state != PWMState.ON and self._duty_cycle[0] >= HEATER_STARTUP_TIMEFRAME and (
elapsed >= self._duty_cycle[1] or self._state == PWMState.IDLE):
if self._first_duty_cycle_start is None:
self._first_duty_cycle_start = monotonic()

if self._cycles >= self._max_cycles:
_LOGGER.info("Reached max cycles per hour, preventing new duty cycle.")
return
Expand Down

0 comments on commit 4d6bca4

Please sign in to comment.