|
5 | 5 | from __future__ import annotations |
6 | 6 |
|
7 | 7 | import aiohttp |
| 8 | +import datetime as dt |
8 | 9 | from defusedxml import ElementTree as etree |
9 | 10 |
|
10 | 11 | # Dict as class |
@@ -318,6 +319,7 @@ def __init__( |
318 | 319 | SmileData.__init__(self) |
319 | 320 |
|
320 | 321 | self.smile_hostname: str | None = None |
| 322 | + self._previous: str = "0" |
321 | 323 | self._target_smile: str | None = None |
322 | 324 |
|
323 | 325 | async def connect(self) -> bool: |
@@ -506,36 +508,44 @@ async def _update_domain_objects(self) -> None: |
506 | 508 |
|
507 | 509 | async def async_update(self) -> PlugwiseData: |
508 | 510 | """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) |
533 | 543 |
|
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) |
537 | 547 |
|
538 | | - remove_empty_platform_dicts(device) |
| 548 | + remove_empty_platform_dicts(device) |
539 | 549 |
|
540 | 550 | return PlugwiseData(self.gw_data, self.gw_devices) |
541 | 551 |
|
|
0 commit comments