mirror of
https://github.com/elisspace/core.git
synced 2026-10-05 16:56:19 +00:00
Improve zwave_js notification event handling (#66790)
This commit is contained in:
@@ -12,6 +12,7 @@ from zwave_js_server.model.node import Node as ZwaveNode
|
||||
from zwave_js_server.model.notification import (
|
||||
EntryControlNotification,
|
||||
NotificationNotification,
|
||||
PowerLevelNotification,
|
||||
)
|
||||
from zwave_js_server.model.value import Value, ValueNotification
|
||||
|
||||
@@ -41,6 +42,7 @@ from homeassistant.helpers.typing import ConfigType
|
||||
from .addon import AddonError, AddonManager, AddonState, get_addon_manager
|
||||
from .api import async_register_api
|
||||
from .const import (
|
||||
ATTR_ACKNOWLEDGED_FRAMES,
|
||||
ATTR_COMMAND_CLASS,
|
||||
ATTR_COMMAND_CLASS_NAME,
|
||||
ATTR_DATA_TYPE,
|
||||
@@ -57,6 +59,8 @@ from .const import (
|
||||
ATTR_PROPERTY_KEY,
|
||||
ATTR_PROPERTY_KEY_NAME,
|
||||
ATTR_PROPERTY_NAME,
|
||||
ATTR_STATUS,
|
||||
ATTR_TEST_NODE_ID,
|
||||
ATTR_TYPE,
|
||||
ATTR_VALUE,
|
||||
ATTR_VALUE_RAW,
|
||||
@@ -392,7 +396,9 @@ async def async_setup_entry( # noqa: C901
|
||||
|
||||
@callback
|
||||
def async_on_notification(
|
||||
notification: EntryControlNotification | NotificationNotification,
|
||||
notification: EntryControlNotification
|
||||
| NotificationNotification
|
||||
| PowerLevelNotification,
|
||||
) -> None:
|
||||
"""Relay stateless notification events from Z-Wave nodes to hass."""
|
||||
device = dev_reg.async_get_device({get_device_id(client, notification.node)})
|
||||
@@ -415,7 +421,7 @@ async def async_setup_entry( # noqa: C901
|
||||
ATTR_EVENT_DATA: notification.event_data,
|
||||
}
|
||||
)
|
||||
else:
|
||||
elif isinstance(notification, NotificationNotification):
|
||||
event_data.update(
|
||||
{
|
||||
ATTR_COMMAND_CLASS_NAME: "Notification",
|
||||
@@ -426,6 +432,17 @@ async def async_setup_entry( # noqa: C901
|
||||
ATTR_PARAMETERS: notification.parameters,
|
||||
}
|
||||
)
|
||||
elif isinstance(notification, PowerLevelNotification):
|
||||
event_data.update(
|
||||
{
|
||||
ATTR_COMMAND_CLASS_NAME: "Power Level",
|
||||
ATTR_TEST_NODE_ID: notification.test_node_id,
|
||||
ATTR_STATUS: notification.status,
|
||||
ATTR_ACKNOWLEDGED_FRAMES: notification.acknowledged_frames,
|
||||
}
|
||||
)
|
||||
else:
|
||||
raise TypeError(f"Unhandled notification type: {notification}")
|
||||
|
||||
hass.bus.async_fire(ZWAVE_JS_NOTIFICATION_EVENT, event_data)
|
||||
|
||||
|
||||
@@ -56,6 +56,9 @@ ATTR_EVENT_DATA = "event_data"
|
||||
ATTR_DATA_TYPE = "data_type"
|
||||
ATTR_WAIT_FOR_RESULT = "wait_for_result"
|
||||
ATTR_OPTIONS = "options"
|
||||
ATTR_TEST_NODE_ID = "test_node_id"
|
||||
ATTR_STATUS = "status"
|
||||
ATTR_ACKNOWLEDGED_FRAMES = "acknowledged_frames"
|
||||
|
||||
ATTR_NODE = "node"
|
||||
ATTR_ZWAVE_VALUE = "zwave_value"
|
||||
|
||||
Reference in New Issue
Block a user