4747# Light override
4848SCAN_DEFAULT_DAYLIGHT_MODE : Final = False
4949
50+ # Sensitivity values for motion sensor configuration
51+ SENSITIVITY_HIGH_VALUE = 20 # 0x14
52+ SENSITIVITY_MEDIUM_VALUE = 30 # 0x1E
53+ SENSITIVITY_OFF_VALUE = 255 # 0xFF
54+
5055# endregion
5156
5257
@@ -169,7 +174,7 @@ def _motion_from_cache(self) -> bool:
169174 if (
170175 cached_motion_state == "True"
171176 and (motion_timestamp := self ._motion_timestamp_from_cache ()) is not None
172- and ( datetime .now (tz = UTC ) - motion_timestamp ).seconds < self ._reset_timer_from_cache () * 60
177+ and int (( datetime .now (tz = UTC ) - motion_timestamp ).total_seconds ()) < self ._reset_timer_from_cache () * 60
173178 ):
174179 return True
175180 return False
@@ -378,7 +383,7 @@ async def _motion_state_update(
378383 self ._set_cache (CACHE_MOTION_STATE , "False" )
379384 if self ._motion_state .state is None or self ._motion_state .state :
380385 if self ._reset_timer_motion_on is not None :
381- reset_timer = ( timestamp - self ._reset_timer_motion_on ).seconds
386+ reset_timer = int (( timestamp - self ._reset_timer_motion_on ).total_seconds ())
382387 if self ._motion_config .reset_timer is None :
383388 self ._motion_config = replace (
384389 self ._motion_config ,
@@ -464,12 +469,13 @@ async def scan_configure(
464469 daylight_mode : bool ,
465470 ) -> bool :
466471 """Configure Scan device settings. Returns True if successful."""
467- # Default to medium:
468- sensitivity_value = 30 # b'1E'
469- if sensitivity_level == MotionSensitivity .HIGH :
470- sensitivity_value = 20 # b'14'
471- if sensitivity_level == MotionSensitivity .OFF :
472- sensitivity_value = 255 # b'FF'
472+ sensitivity_map = {
473+ MotionSensitivity .HIGH : SENSITIVITY_HIGH_VALUE ,
474+ MotionSensitivity .MEDIUM : SENSITIVITY_MEDIUM_VALUE ,
475+ MotionSensitivity .OFF : SENSITIVITY_OFF_VALUE ,
476+ }
477+ # Default to medium
478+ sensitivity_value = sensitivity_map .get (sensitivity_level , SENSITIVITY_MEDIUM_VALUE )
473479 request = ScanConfigureRequest (
474480 self ._send ,
475481 self ._mac_in_bytes ,
@@ -484,17 +490,20 @@ async def scan_configure(
484490 self ._new_daylight_mode = None
485491 _LOGGER .warning ("Failed to configure scan settings for %s" , self .name )
486492 return False
493+
487494 if response .node_ack_type == NodeAckResponseType .SCAN_CONFIG_ACCEPTED :
488495 await self ._scan_configure_update (
489496 motion_reset_timer , sensitivity_level , daylight_mode
490497 )
491498 return True
499+
492500 _LOGGER .warning (
493501 "Unexpected response ack type %s for %s" ,
494502 response .node_ack_type ,
495503 self .name ,
496504 )
497505 return False
506+
498507 self ._new_reset_timer = None
499508 self ._new_sensitivity_level = None
500509 self ._new_daylight_mode = None
0 commit comments