Skip to content

Commit

Permalink
History to update only zones
Browse files Browse the repository at this point in the history
  • Loading branch information
rgc99 committed Oct 9, 2024
1 parent 456277a commit 3baf2fa
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions custom_components/irrigation_unlimited/irrigation_unlimited.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@ def render_positive_float(data: dict, key: str) -> None:
if isinstance(template, Template):
data[key] = cv.positive_float(template.async_render())


def check_item(index: int, items: list[int] | None) -> bool:
"""If items is None or contains only a 0 (match all) then
return True. Otherwise check if index + 1 is in the list"""
Expand Down Expand Up @@ -2386,10 +2387,16 @@ def request_update(self) -> None:
"""Flag the sensor needs an update"""
self._sensor_update_required = True

def schedule_update(self, stime: datetime) -> None:
"""Schedule a HA update of the sensor"""
self._zone_sensor.schedule_update_ha_state()
self._sensor_update_required = False
self._sensor_last_update = stime

def update_sensor(self, stime: datetime, do_on: bool) -> bool:
"""Lazy sensor updater"""
updated: bool = False
do_update: bool = False
updated = False
do_update = False

if self._zone_sensor is not None:
if do_on is False:
Expand All @@ -2413,14 +2420,10 @@ def update_sensor(self, stime: datetime, do_on: bool) -> bool:
>= self._coordinator.refresh_interval
)
do_update |= self._sensor_update_required
else:
do_update = False

if do_update:
self._zone_sensor.schedule_update_ha_state()
self._sensor_update_required = False
self._sensor_last_update = stime
updated = True
self.schedule_update(stime)
return True

return updated

Expand Down Expand Up @@ -6692,13 +6695,11 @@ def service_call(
def service_history(self, entity_ids: set[str]) -> None:
"""History service call entry point. The history has changed
and the sensors require an update"""
stime = self.service_time()
for controller in self._controllers:
if controller.entity_id in entity_ids:
controller.request_update(False)
for zone in controller.zones:
if zone.entity_id in entity_ids:
zone.request_update()
self.update_sensor(self.service_time())
zone.schedule_update(stime)

def start_test(self, test_no: int) -> datetime:
"""Main entry to start a test"""
Expand Down

0 comments on commit 3baf2fa

Please sign in to comment.