Skip to content

Commit e220116

Browse files
committed
simply bool retrieval from cache
1 parent 6c2e33f commit e220116

File tree

3 files changed

+12
-14
lines changed

3 files changed

+12
-14
lines changed

plugwise_usb/nodes/node.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -655,6 +655,14 @@ def _get_cache(self, setting: str) -> str | None:
655655
return None
656656
return self._node_cache.get_state(setting)
657657

658+
def _get_cache_as_bool(self, setting: str) -> bool | None:
659+
"""Retrieve bool of specified setting from cache memory."""
660+
if not self._cache_enabled:
661+
return None
662+
if self._node_cache.get_state(setting) == "True":
663+
return True
664+
return False
665+
658666
def _get_cache_as_datetime(self, setting: str) -> datetime | None:
659667
"""Retrieve value of specified setting from cache memory and return it as datetime object."""
660668
if (timestamp_str := self._get_cache(setting)) is not None:

plugwise_usb/nodes/scan.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -178,13 +178,7 @@ async def _load_from_cache(self) -> bool:
178178

179179
def _daylight_mode_from_cache(self) -> bool | None:
180180
"""Load awake duration from cache."""
181-
if (
182-
daylight_mode := self._get_cache(CACHE_SCAN_CONFIG_DAYLIGHT_MODE)
183-
) is not None:
184-
if daylight_mode == "True":
185-
return True
186-
return False
187-
return None
181+
return self._get_cache_as_bool(CACHE_SCAN_CONFIG_DAYLIGHT_MODE)
188182

189183
def _motion_from_cache(self) -> bool:
190184
"""Load motion state from cache."""
@@ -218,7 +212,7 @@ def _sensitivity_level_from_cache(self) -> MotionSensitivity | None:
218212

219213
def _motion_config_dirty_from_cache(self) -> bool:
220214
"""Load dirty from cache."""
221-
if (dirty := self._get_cache(CACHE_SCAN_CONFIG_DIRTY)) is not None:
215+
if (dirty := self._get_cache_as_bool(CACHE_SCAN_CONFIG_DIRTY)) is not None:
222216
return dirty
223217
return True
224218

plugwise_usb/nodes/sed.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -191,11 +191,7 @@ def _clock_interval_from_cache(self) -> int | None:
191191

192192
def _clock_sync_from_cache(self) -> bool | None:
193193
"""Load clock sync state from cache."""
194-
if (clock_sync := self._get_cache(CACHE_SED_CLOCK_SYNC)) is not None:
195-
if clock_sync == "True":
196-
return True
197-
return False
198-
return None
194+
return self._get_cache_as_bool(CACHE_SED_CLOCK_SYNC)
199195

200196
def _maintenance_interval_from_cache(self) -> int | None:
201197
"""Load maintenance interval from cache."""
@@ -222,7 +218,7 @@ def _awake_reason_from_cache(self) -> str | None:
222218

223219
def _sed_config_dirty_from_cache(self) -> bool:
224220
"""Load battery config dirty from cache."""
225-
if (dirty := self._get_cache(CACHE_SED_DIRTY)) is not None:
221+
if (dirty := self._get_cache_as_bool(CACHE_SED_DIRTY)) is not None:
226222
return dirty
227223
return True
228224

0 commit comments

Comments
 (0)