Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 2
store MotionSensitivity enum which makes communication to HA easier#323
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
cc6bcf6
store MotionSensitivity enum which makes communication to HA easier
dirixmjm 6bd7013
fixup: mdi_scan Python code reformatted using Ruff
9a147d5
CR: Catched missing update
dirixmjm 247d762
reference to self-functions which return default values of config-obj…
dirixmjm 722734a
fixup: mdi_scan Python code reformatted using Ruff
96307d0
print wrong value of level in de log
dirixmjm 9b13066
fixup: mdi_scan Python code reformatted using Ruff
22b21d3
CR: update node.py as well
dirixmjm b5a44c2
release 0.44.12a2
dirixmjm 96e4df5
CR: Nitpick on formatting
dirixmjm f536631
expose scheduling of light calibration
dirixmjm 32f66ff
Revert api/set_motion_sensitivity_level() typing
bouwew b797755
Revert node/set_motion_sensitivity_level() typing
bouwew 3516508
Assure proper input-output
bouwew 68ab733
Fix set_motion_sensitivity_level tests
bouwew 7e010a5
Fix sensitivity_level property
bouwew 1b64119
convert to value just before call to ScanConfigureRequest
dirixmjm 1d56d5f
cherry-pick updates to test_usb.py
dirixmjm 1696031
return type change to indicate already or newly activated
dirixmjm 01d1db4
CR: remove unwanted exception
dirixmjm 46dfac2
CR: Nitpick, cachewrite already stringifies internally
dirixmjm b37383a
update CHANGELOG
dirixmjm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -19,7 +19,7 @@ | ||
| ) | ||
| from ..connection import StickController | ||
| from ..constants import MAX_UINT_2 | ||
| from ..exceptions import MessageError, NodeError, NodeTimeout | ||
| from ..exceptions import MessageError, NodeError | ||
| from ..messages.requests import ScanConfigureRequest, ScanLightCalibrateRequest | ||
| from ..messages.responses import ( | ||
| NODE_SWITCH_GROUP_ID, | ||
| @@ -86,7 +86,7 @@ def __init__( | ||
| self._motion_state = MotionState() | ||
| self._motion_config = MotionConfig() | ||
| self._scan_calibrate_light_scheduled = False | ||
| self._configure_daylight_mode_task: Task[Coroutine[Any, Any, None]] | None = ( | ||
| None | ||
| ) | ||
| @@ -198,7 +198,7 @@ def _reset_timer_from_cache(self) -> int | None: | ||
| return int(reset_timer) | ||
| return None | ||
| def _sensitivity_level_from_cache(self) -> int | None: | ||
| def _sensitivity_level_from_cache(self) -> MotionSensitivity | None: | ||
| """Load sensitivity level from cache.""" | ||
| if ( | ||
| sensitivity_level := self._get_cache( | ||
| @@ -274,7 +274,7 @@ def reset_timer(self) -> int: | ||
| return DEFAULT_RESET_TIMER | ||
| @property | ||
| def sensitivity_level(self) -> int: | ||
| def sensitivity_level(self) -> MotionSensitivity: | ||
| """Sensitivity level of motion sensor.""" | ||
| if self._motion_config.sensitivity_level is not None: | ||
| return self._motion_config.sensitivity_level | ||
| @@ -326,13 +326,13 @@ async def set_motion_reset_timer(self, minutes: int) -> bool: | ||
| await self._scan_configure_update() | ||
| return True | ||
| async def set_motion_sensitivity_level(self, level: int) -> bool: | ||
| async def set_motion_sensitivity_level(self, level: MotionSensitivity) -> bool: | ||
| """Configure the motion sensitivity level.""" | ||
| _LOGGER.debug( | ||
| "set_motion_sensitivity_level | Device %s | %s -> %s", | ||
| self.name, | ||
| self._motion_config.sensitivity_level, | ||
| level, | ||
| self.sensitivity_level.name, | ||
| level.name, | ||
| ) | ||
| if self._motion_config.sensitivity_level == level: | ||
| return False | ||
| @@ -426,6 +426,8 @@ async def _run_awake_tasks(self) -> None: | ||
| await super()._run_awake_tasks() | ||
| if self._motion_config.dirty: | ||
| await self._configure_scan_task() | ||
| if self._scan_calibrate_light_scheduled: | ||
| await self._scan_calibrate_light() | ||
| await self.publish_feature_update_to_subscribers( | ||
| NodeFeature.MOTION_CONFIG, | ||
| self._motion_config, | ||
| @@ -446,9 +448,9 @@ async def scan_configure(self) -> bool: | ||
| request = ScanConfigureRequest( | ||
| self._send, | ||
| self._mac_in_bytes, | ||
| self._motion_config.reset_timer, | ||
| self._motion_config.sensitivity_level, | ||
| self._motion_config.daylight_mode, | ||
| self.reset_timer, | ||
| self.sensitivity_level.value, | ||
| self.daylight_mode, | ||
| ) | ||
bouwew marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| if (response := await request.send()) is None: | ||
| _LOGGER.warning( | ||
| @@ -473,17 +475,13 @@ async def scan_configure(self) -> bool: | ||
| async def _scan_configure_update(self) -> None: | ||
| """Push scan configuration update to cache.""" | ||
| self._set_cache( | ||
| CACHE_SCAN_CONFIG_RESET_TIMER, str(self._motion_config.reset_timer) | ||
| ) | ||
| self._set_cache(CACHE_SCAN_CONFIG_RESET_TIMER, self.reset_timer) | ||
| self._set_cache( | ||
| CACHE_SCAN_CONFIG_SENSITIVITY, | ||
| str(MotionSensitivity(self._motion_config.sensitivity_level).name), | ||
| self._motion_config.sensitivity_level.name, | ||
| ) | ||
| self._set_cache( | ||
| CACHE_SCAN_CONFIG_DAYLIGHT_MODE, str(self._motion_config.daylight_mode) | ||
| ) | ||
| self._set_cache(CACHE_SCAN_CONFIG_DIRTY, str(self._motion_config.dirty)) | ||
| self._set_cache(CACHE_SCAN_CONFIG_DAYLIGHT_MODE, self.daylight_mode) | ||
| self._set_cache(CACHE_SCAN_CONFIG_DIRTY, self.dirty) | ||
| await gather( | ||
| self.publish_feature_update_to_subscribers( | ||
| NodeFeature.MOTION_CONFIG, | ||
| @@ -493,18 +491,36 @@ async def _scan_configure_update(self) -> None: | ||
| ) | ||
| async def scan_calibrate_light(self) -> bool: | ||
| """Schedule light sensitivity calibration of Scan device. | ||
| Returns True when scheduling was newly activated; | ||
| False if it was already scheduled. | ||
| """ | ||
| if self._scan_calibrate_light_scheduled: | ||
| return False | ||
| self._scan_calibrate_light_scheduled = True | ||
| return True | ||
| async def _scan_calibrate_light(self) -> bool: | ||
| """Request to calibration light sensitivity of Scan device.""" | ||
| request = ScanLightCalibrateRequest(self._send, self._mac_in_bytes) | ||
| if (response := await request.send()) is not None: | ||
| if ( | ||
| response.node_ack_type | ||
| == NodeAckResponseType.SCAN_LIGHT_CALIBRATION_ACCEPTED | ||
| ): | ||
| return True | ||
| response = await request.send() | ||
| if response is None: | ||
| _LOGGER.warning( | ||
| "No response from %s to light calibration request", | ||
| self.name, | ||
| ) | ||
| return False | ||
| raise NodeTimeout( | ||
| f"No response from Scan device {self.mac} " | ||
| + "to light calibration request." | ||
| if ( | ||
| response.node_ack_type | ||
| == NodeAckResponseType.SCAN_LIGHT_CALIBRATION_ACCEPTED | ||
| ): | ||
| self._scan_calibrate_light_scheduled = False | ||
| return True | ||
| _LOGGER.warning( | ||
| "Unexpected ack type %s for light calibration on %s", | ||
| response.node_ack_type, | ||
| self.name, | ||
| ) | ||
| async def get_state(self, features: tuple[NodeFeature]) -> dict[NodeFeature, Any]: | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.