Skip to content

Commit 3e23019

Browse files
committed
fix: simplify operator and fix async_dispatcher is removed
1 parent 99843be commit 3e23019

2 files changed

Lines changed: 7 additions & 7 deletions

File tree

custom_components/powercalc/sensors/group/standby.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,12 @@ def __init__(self, hass: HomeAssistant, rounding_digits: int = 2) -> None:
7272
async def async_added_to_hass(self) -> None:
7373
"""Register state listeners."""
7474
await super().async_added_to_hass()
75-
async_dispatcher_connect(
76-
self.hass,
77-
SIGNAL_POWER_SENSOR_STATE_CHANGE,
78-
self._recalculate,
75+
self.async_on_remove(
76+
async_dispatcher_connect(
77+
self.hass,
78+
SIGNAL_POWER_SENSOR_STATE_CHANGE,
79+
self._recalculate,
80+
),
7981
)
8082

8183
async def _recalculate(self) -> None:

custom_components/powercalc/strategy/composite.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,7 @@ async def calculate(self, entity_state: State) -> Decimal | None:
159159
if isinstance(strategy, PlaybookStrategy):
160160
await self.activate_playbook(strategy)
161161

162-
if (
163-
entity_state.state == STATE_OFF and strategy.can_calculate_standby()
164-
) or entity_state.state != STATE_OFF:
162+
if entity_state.state != STATE_OFF or strategy.can_calculate_standby():
165163
value = await strategy.calculate(entity_state)
166164
if value is not None:
167165
if self.mode == CompositeMode.STOP_AT_FIRST:

0 commit comments

Comments
 (0)