-
-
Notifications
You must be signed in to change notification settings - Fork 37.5k
Add Z-Wave battery low event entity #170111
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
Draft
TheJulianJES
wants to merge
6
commits into
home-assistant:dev
Choose a base branch
from
TheJulianJES:tjj/zwave_battery_low_entity_2
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
8998563
Forward Z-Wave Battery CC notifications to the notification bus event
TheJulianJES b461653
Add Z-Wave battery low event entity
TheJulianJES 4ac562a
Drop unreachable BatteryReplacementStatus.NO check
TheJulianJES c0c697c
Type the client fixture in new battery low event tests
TheJulianJES b98b239
Remove battery low event entity on Z-Wave node reinterview
TheJulianJES 7189590
Test Battery CC notification bus event forwarding
TheJulianJES File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,6 +17,7 @@ | |
| from zwave_js_server.model.driver import Driver | ||
| from zwave_js_server.model.node import Node as ZwaveNode | ||
| from zwave_js_server.model.notification import ( | ||
| BatteryNotification, | ||
| EntryControlNotification, | ||
| MultilevelSwitchNotification, | ||
| NotificationNotification, | ||
|
|
@@ -79,6 +80,7 @@ | |
| ATTR_STATUS, | ||
| ATTR_TEST_NODE_ID, | ||
| ATTR_TYPE, | ||
| ATTR_URGENCY, | ||
| ATTR_VALUE, | ||
| ATTR_VALUE_RAW, | ||
| CONF_ADDON_DEVICE, | ||
|
|
@@ -826,6 +828,17 @@ async def async_on_node_ready(self, node: ZwaveNode) -> None: | |
| node, | ||
| ) | ||
|
|
||
| # Create a battery low event entity for each non-controller node that | ||
| # supports the Battery CC. | ||
| if not node.is_controller_node and any( | ||
| cc.id == CommandClass.BATTERY.value for cc in node.command_classes | ||
| ): | ||
| async_dispatcher_send( | ||
| self.hass, | ||
| f"{DOMAIN}_{self.config_entry.entry_id}_add_battery_low_event_entity", | ||
| node, | ||
| ) | ||
|
|
||
| # After ensuring the node is set up in HA, we should check if the node's | ||
| # device config has changed, and if so, issue a repair registry entry for a | ||
| # possible reinterview | ||
|
|
@@ -965,7 +978,8 @@ def async_on_notification(self, event: dict[str, Any]) -> None: | |
|
|
||
| driver = self.controller_events.driver_events.driver | ||
| notification: ( | ||
| EntryControlNotification | ||
| BatteryNotification | ||
| | EntryControlNotification | ||
| | NotificationNotification | ||
| | PowerLevelNotification | ||
| | MultilevelSwitchNotification | ||
|
|
@@ -985,7 +999,15 @@ def async_on_notification(self, event: dict[str, Any]) -> None: | |
| ATTR_COMMAND_CLASS: notification.command_class, | ||
| } | ||
|
|
||
| if isinstance(notification, EntryControlNotification): | ||
| if isinstance(notification, BatteryNotification): | ||
| event_data.update( | ||
| { | ||
| ATTR_COMMAND_CLASS_NAME: "Battery", | ||
| ATTR_EVENT_TYPE: notification.event_type, | ||
| ATTR_URGENCY: notification.urgency, | ||
| } | ||
| ) | ||
|
TheJulianJES marked this conversation as resolved.
Comment on lines
+1002
to
+1009
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This can be a separate PR, I think. |
||
| elif isinstance(notification, EntryControlNotification): | ||
| event_data.update( | ||
| { | ||
| ATTR_COMMAND_CLASS_NAME: "Entry Control", | ||
|
|
||
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest we do a refactor first, in a separate PR, and introduce a node discovery feature with node discovery schemas, a node discovery handler that forwards the discovery info to the correct platform, and a node base entity class that has the common features that node based entities share.
Most of the current node based entities (ping button, controller status sensor, node status sensor, statistics sensor, firmware update) seem to have almost the same base features.