Skip to content

Commit ec88723

Browse files
committed
Adapt scan.py
1 parent 69d90fc commit ec88723

File tree

1 file changed

+14
-15
lines changed

1 file changed

+14
-15
lines changed

plugwise_usb/nodes/scan.py

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,14 @@
99
import logging
1010
from typing import Any, Final
1111

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+
)
1320
from ..connection import StickController
1421
from ..constants import MAX_UINT_2
1522
from ..exceptions import MessageError, NodeError, NodeTimeout
@@ -36,24 +43,14 @@
3643

3744
# region Defaults for Scan Devices
3845

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-
4946
DEFAULT_MOTION_STATE: Final = False
5047

5148
# Time in minutes the motion sensor should not sense motion to
5249
# report "no motion" state [Source: 1min - 4uur]
5350
DEFAULT_RESET_TIMER: Final = 10
5451

5552
# Default sensitivity of the motion sensors
56-
DEFAULT_SENSITIVITY = MOTION_SENSITIVITY[MEDIUM]
53+
DEFAULT_SENSITIVITY = MotionSensitivity.MEDIUM
5754

5855
# Light override
5956
DEFAULT_DAYLIGHT_MODE: Final = False
@@ -204,9 +201,9 @@ def _reset_timer_from_cache(self) -> int | None:
204201
def _sensitivity_level_from_cache(self) -> int | None:
205202
"""Load sensitivity level from cache."""
206203
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
208205
) is not None:
209-
return int(sensitivity_level)
206+
return MotionSensitivity[sensitivity_level]
210207
return None
211208

212209
def _motion_config_dirty_from_cache(self) -> bool:
@@ -474,7 +471,9 @@ async def _scan_configure_update(self) -> None:
474471
CACHE_SCAN_CONFIG_RESET_TIMER, str(self._motion_config.reset_timer)
475472
)
476473
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+
)
478477
)
479478
self._set_cache(
480479
CACHE_SCAN_CONFIG_DAYLIGHT_MODE, str(self._motion_config.daylight_mode)

0 commit comments

Comments
 (0)