Skip to content

Commit 32d3505

Browse files
committed
second attempt to fix, according to @bouwew recommendation
1 parent 655627d commit 32d3505

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

plugwise_usb/nodes/scan.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,11 @@
5959
DEFAULT_FIRMWARE: Final = datetime(2010, 11, 4, 16, 58, 46, tzinfo=UTC)
6060

6161
# Sensitivity values for motion sensor configuration
62-
SENSITIVITY_HIGH_VALUE = 20 # 0x14
63-
SENSITIVITY_MEDIUM_VALUE = 30 # 0x1E
64-
SENSITIVITY_OFF_VALUE = 255 # 0xFF
62+
SENSITIVITY_MAP: Final = {
63+
MotionSensitivity.HIGH: 20, # 0x14
64+
MotionSensitivity.MEDIUM: 30, # 0x1E
65+
MotionSensitivity.OFF: 255, # 0xFF
66+
}
6567

6668
# Scan Features
6769
SCAN_FEATURES: Final = (
@@ -207,7 +209,7 @@ def _sensitivity_level_from_cache(self) -> MotionSensitivity | None:
207209
if (
208210
sensitivity_level := self._get_cache(CACHE_SCAN_CONFIG_SENSITIVITY)
209211
) is not None:
210-
return MotionSensitivity(int(sensitivity_level))
212+
return MotionSensitivity([sensitivity_level])
211213
return None
212214

213215
def _motion_config_dirty_from_cache(self) -> bool:
@@ -423,11 +425,13 @@ async def _motion_state_update(
423425
]
424426
)
425427

426-
async def _run_awake_tasks(self) -> None:
428+
async def _run_awake_tasks(self) -> bool:
427429
"""Execute all awake tasks."""
428-
await super()._run_awake_tasks()
430+
if not await super()._run_awake_tasks():
431+
return False
429432
if self._motion_config.dirty:
430433
await self._configure_scan_task()
434+
return True
431435

432436
async def _configure_scan_task(self) -> bool:
433437
"""Configure Scan device settings. Returns True if successful."""
@@ -440,13 +444,8 @@ async def _configure_scan_task(self) -> bool:
440444

441445
async def scan_configure(self) -> bool:
442446
"""Configure Scan device settings. Returns True if successful."""
443-
sensitivity_map = {
444-
MotionSensitivity.HIGH: SENSITIVITY_HIGH_VALUE,
445-
MotionSensitivity.MEDIUM: SENSITIVITY_MEDIUM_VALUE,
446-
MotionSensitivity.OFF: SENSITIVITY_OFF_VALUE,
447-
}
448447
# Default to medium
449-
sensitivity_value = sensitivity_map.get(
448+
sensitivity_value = SENSITIVITY_MAP.get(
450449
self._motion_config.sensitivity_level, SENSITIVITY_MEDIUM_VALUE
451450
)
452451
request = ScanConfigureRequest(
@@ -483,7 +482,7 @@ async def _scan_configure_update(self) -> None:
483482
CACHE_SCAN_CONFIG_RESET_TIMER, str(self._motion_config.reset_timer)
484483
)
485484
self._set_cache(
486-
CACHE_SCAN_CONFIG_SENSITIVITY, self._motion_config.sensitivity_level.value
485+
CACHE_SCAN_CONFIG_SENSITIVITY, self._motion_config.sensitivity_level.name
487486
)
488487
self._set_cache(
489488
CACHE_SCAN_CONFIG_DAYLIGHT_MODE, str(self._motion_config.daylight_mode)

0 commit comments

Comments
 (0)