Skip to content

Commit 4022af8

Browse files
committed
improve readability circle.py
expose dirty flag properly
1 parent e220116 commit 4022af8

File tree

3 files changed

+24
-7
lines changed

3 files changed

+24
-7
lines changed

plugwise_usb/nodes/circle.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -910,8 +910,10 @@ async def load(self) -> None:
910910

911911
# Check if node is online
912912
if (
913-
not self._available and not await self.is_online()
914-
) or await self.node_info_update() is None:
913+
not self._available
914+
and not await self.is_online()
915+
or await self.node_info_update() is None
916+
):
915917
_LOGGER.debug(
916918
"Failed to retrieve NodeInfo for %s, loading defaults",
917919
self._mac_in_str,

plugwise_usb/nodes/scan.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,10 @@ def _motion_timestamp_from_cache(self) -> datetime | None:
227227
# endregion
228228

229229
# region Properties
230+
@property
231+
def dirty(self) -> bool:
232+
"""Motion configuration dirty flag."""
233+
return self._motion_config.dirty
230234

231235
@property
232236
def daylight_mode(self) -> bool:
@@ -261,6 +265,7 @@ def motion_config(self) -> MotionConfig:
261265
reset_timer=self.reset_timer,
262266
daylight_mode=self.daylight_mode,
263267
sensitivity_level=self.sensitivity_level,
268+
dirty=self.dirty,
264269
)
265270

266271
@property

plugwise_usb/nodes/sed.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,6 @@ async def _load_from_cache(self) -> bool:
162162
dirty = True
163163
sleep_duration = SED_DEFAULT_SLEEP_DURATION
164164
dirty &= self._sed_config_dirty_from_cache()
165-
166165
self._battery_config = BatteryConfig(
167166
awake_duration=awake_duration,
168167
clock_interval=clock_interval,
@@ -191,6 +190,9 @@ def _clock_interval_from_cache(self) -> int | None:
191190

192191
def _clock_sync_from_cache(self) -> bool | None:
193192
"""Load clock sync state from cache."""
193+
_LOGGER.debug(
194+
"MDI: Bool: %s", str(self._get_cache_as_bool(CACHE_SED_CLOCK_SYNC))
195+
)
194196
return self._get_cache_as_bool(CACHE_SED_CLOCK_SYNC)
195197

196198
def _maintenance_interval_from_cache(self) -> int | None:
@@ -237,7 +239,9 @@ async def set_awake_duration(self, seconds: int) -> bool:
237239
)
238240

239241
self._battery_config = replace(
240-
self._battery_config, awake_duration=seconds, dirty=True
242+
self._battery_config,
243+
awake_duration=seconds,
244+
dirty=True,
241245
)
242246
return True
243247

@@ -325,6 +329,11 @@ async def set_sleep_duration(self, minutes: int) -> bool:
325329

326330
# endregion
327331
# region Properties
332+
@property
333+
def dirty(self) -> int:
334+
"""Battry configuration dirty flag."""
335+
return self._battery_config.dirty
336+
328337
@property
329338
def awake_duration(self) -> int:
330339
"""Duration in seconds a battery powered devices is awake."""
@@ -341,6 +350,7 @@ def battery_config(self) -> BatteryConfig:
341350
clock_sync=self.clock_sync,
342351
maintenance_interval=self.maintenance_interval,
343352
sleep_duration=self.sleep_duration,
353+
dirty=self.dirty,
344354
)
345355

346356
@property
@@ -413,17 +423,17 @@ async def _awake_response(self, response: PlugwiseResponse) -> bool:
413423
):
414424
return True
415425

426+
await self._run_awake_tasks()
416427
self._last_awake[response.awake_type] = response.timestamp
417428

418429
tasks: list[Coroutine[Any, Any, None]] = [
419-
await self._reset_awake(response.timestamp),
430+
self._reset_awake(response.timestamp),
420431
self.publish_feature_update_to_subscribers(
421432
NodeFeature.BATTERY,
422433
self._battery_config,
423434
),
424-
await self.save_cache(),
435+
self.save_cache(),
425436
]
426-
await self._run_awake_tasks()
427437
if response.awake_type == NodeAwakeResponseType.MAINTENANCE:
428438
self._last_awake_reason = "Maintenance"
429439
self._set_cache(CACHE_SED_AWAKE_REASON, "Maintenance")

0 commit comments

Comments
 (0)