Skip to content

Commit 5d105cb

Browse files
committed
Perform a full update once per day
1 parent e7d0fdc commit 5d105cb

File tree

1 file changed

+38
-28
lines changed

1 file changed

+38
-28
lines changed

plugwise/__init__.py

Lines changed: 38 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from __future__ import annotations
66

77
import aiohttp
8+
import datetime as dt
89
from defusedxml import ElementTree as etree
910

1011
# Dict as class
@@ -318,6 +319,7 @@ def __init__(
318319
SmileData.__init__(self)
319320

320321
self.smile_hostname: str | None = None
322+
self._previous: str = "0"
321323
self._target_smile: str | None = None
322324

323325
async def connect(self) -> bool:
@@ -506,36 +508,44 @@ async def _update_domain_objects(self) -> None:
506508

507509
async def async_update(self) -> PlugwiseData:
508510
"""Perform an incremental update for updating the various device states."""
509-
await self._update_domain_objects()
510-
match self._target_smile:
511-
case "smile_v2":
512-
self._modules = await self._request(MODULES)
513-
case "smile_v3" | "smile_v4":
514-
self._locations = await self._request(LOCATIONS)
515-
case "smile_open_therm_v2" | "smile_open_therm_v3":
516-
self._appliances = await self._request(APPLIANCES)
517-
self._modules = await self._request(MODULES)
518-
case self._target_smile if self._target_smile in REQUIRE_APPLIANCES:
519-
self._appliances = await self._request(APPLIANCES)
520-
521-
self.gw_data["notifications"] = self._notifications
522-
523-
for device_id, device in self.gw_devices.items():
524-
data = self._get_device_data(device_id)
525-
if (
526-
"binary_sensors" in device
527-
and "plugwise_notification" in device["binary_sensors"]
528-
):
529-
data["binary_sensors"]["plugwise_notification"] = bool(
530-
self._notifications
531-
)
532-
device.update(data)
511+
new = dt.datetime.now().strftime("%w")
512+
# Perform a full update at day-change
513+
if new != self._previous:
514+
self._previous = new
515+
await self._full_update_device()
516+
self.get_all_devices()
517+
# Otherwise perform an incremental update
518+
else:
519+
await self._update_domain_objects()
520+
match self._target_smile:
521+
case "smile_v2":
522+
self._modules = await self._request(MODULES)
523+
case "smile_v3" | "smile_v4":
524+
self._locations = await self._request(LOCATIONS)
525+
case "smile_open_therm_v2" | "smile_open_therm_v3":
526+
self._appliances = await self._request(APPLIANCES)
527+
self._modules = await self._request(MODULES)
528+
case self._target_smile if self._target_smile in REQUIRE_APPLIANCES:
529+
self._appliances = await self._request(APPLIANCES)
530+
531+
self.gw_data["notifications"] = self._notifications
532+
533+
for device_id, device in self.gw_devices.items():
534+
data = self._get_device_data(device_id)
535+
if (
536+
"binary_sensors" in device
537+
and "plugwise_notification" in device["binary_sensors"]
538+
):
539+
data["binary_sensors"]["plugwise_notification"] = bool(
540+
self._notifications
541+
)
542+
device.update(data)
533543

534-
# Update for cooling
535-
if device["dev_class"] in ZONE_THERMOSTATS:
536-
self.update_for_cooling(device)
544+
# Update for cooling
545+
if device["dev_class"] in ZONE_THERMOSTATS:
546+
self.update_for_cooling(device)
537547

538-
remove_empty_platform_dicts(device)
548+
remove_empty_platform_dicts(device)
539549

540550
return PlugwiseData(self.gw_data, self.gw_devices)
541551

0 commit comments

Comments
 (0)