From 310b9639327a95693a6635e179d8a68583580deb Mon Sep 17 00:00:00 2001 From: Werner Pieterson Date: Wed, 9 Nov 2022 15:52:25 +0200 Subject: [PATCH] Fix area sensor bug --- custom_components/load_shedding/sensor.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/custom_components/load_shedding/sensor.py b/custom_components/load_shedding/sensor.py index e0e64b4..c0cf658 100644 --- a/custom_components/load_shedding/sensor.py +++ b/custom_components/load_shedding/sensor.py @@ -246,11 +246,17 @@ def native_value(self) -> StateType: if ATTR_END_TIME in event and event.get(ATTR_END_TIME) < now: continue - self._attr_native_value = cast(StateType, STATE_OFF) - if event.get(ATTR_STAGE) == Stage.NO_LOAD_SHEDDING: - return self._attr_native_value if event.get(ATTR_START_TIME) <= now <= event.get(ATTR_END_TIME): self._attr_native_value = cast(StateType, STATE_ON) + break + + if event.get(ATTR_START_TIME) > now: + self._attr_native_value = cast(StateType, STATE_OFF) + break + + if event.get(ATTR_STAGE) == Stage.NO_LOAD_SHEDDING: + self._attr_native_value = cast(StateType, STATE_OFF) + break return self._attr_native_value