|
9 | 9 | import logging |
10 | 10 | from typing import Any, Final |
11 | 11 |
|
12 | | -from ..api import MotionConfig, MotionState, NodeEvent, NodeFeature, NodeType |
| 12 | +from ..api import ( |
| 13 | + MotionConfig, |
| 14 | + MotionSensitivity, |
| 15 | + MotionState, |
| 16 | + NodeEvent, |
| 17 | + NodeFeature, |
| 18 | + NodeType, |
| 19 | +) |
13 | 20 | from ..connection import StickController |
14 | 21 | from ..constants import MAX_UINT_2 |
15 | 22 | from ..exceptions import MessageError, NodeError, NodeTimeout |
|
36 | 43 |
|
37 | 44 | # region Defaults for Scan Devices |
38 | 45 |
|
39 | | -# Sensitivity values for motion sensor configuration |
40 | | -HIGH: Final[str] = "HIGH" |
41 | | -MEDIUM: Final[str] = "MEDIUM" |
42 | | -OFF: Final[str] = "OFF" |
43 | | -MOTION_SENSITIVITY: Final[dict] = { |
44 | | - HIGH: 20, # 0x14 |
45 | | - MEDIUM: 30, # 0x1E |
46 | | - OFF: 255, # 0xFF |
47 | | -} |
48 | | - |
49 | 46 | DEFAULT_MOTION_STATE: Final = False |
50 | 47 |
|
51 | 48 | # Time in minutes the motion sensor should not sense motion to |
52 | 49 | # report "no motion" state [Source: 1min - 4uur] |
53 | 50 | DEFAULT_RESET_TIMER: Final = 10 |
54 | 51 |
|
55 | 52 | # Default sensitivity of the motion sensors |
56 | | -DEFAULT_SENSITIVITY = MOTION_SENSITIVITY[MEDIUM] |
| 53 | +DEFAULT_SENSITIVITY = MotionSensitivity.MEDIUM |
57 | 54 |
|
58 | 55 | # Light override |
59 | 56 | DEFAULT_DAYLIGHT_MODE: Final = False |
@@ -204,9 +201,9 @@ def _reset_timer_from_cache(self) -> int | None: |
204 | 201 | def _sensitivity_level_from_cache(self) -> int | None: |
205 | 202 | """Load sensitivity level from cache.""" |
206 | 203 | if ( |
207 | | - sensitivity_level := self._get_cache(CACHE_SCAN_CONFIG_SENSITIVITY) |
| 204 | + sensitivity_level := self._get_cache(CACHE_SCAN_CONFIG_SENSITIVITY) # returns level in string CAPITALS |
208 | 205 | ) is not None: |
209 | | - return int(sensitivity_level) |
| 206 | + return MotionSensitivity[sensitivity_level] |
210 | 207 | return None |
211 | 208 |
|
212 | 209 | def _motion_config_dirty_from_cache(self) -> bool: |
@@ -474,7 +471,9 @@ async def _scan_configure_update(self) -> None: |
474 | 471 | CACHE_SCAN_CONFIG_RESET_TIMER, str(self._motion_config.reset_timer) |
475 | 472 | ) |
476 | 473 | self._set_cache( |
477 | | - CACHE_SCAN_CONFIG_SENSITIVITY, self._motion_config.sensitivity_level |
| 474 | + CACHE_SCAN_CONFIG_SENSITIVITY, str( |
| 475 | + MotionSensitivity(self._motion_config.sensitivity_level).name |
| 476 | + ) |
478 | 477 | ) |
479 | 478 | self._set_cache( |
480 | 479 | CACHE_SCAN_CONFIG_DAYLIGHT_MODE, str(self._motion_config.daylight_mode) |
|
0 commit comments