Skip to content
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

Add zwave_js MultilevelSwitch Notification #70470

12 changes: 11 additions & 1 deletion homeassistant/components/zwave_js/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from zwave_js_server.model.node import Node as ZwaveNode
from zwave_js_server.model.notification import (
EntryControlNotification,
MultilevelSwitchNotification,
NotificationNotification,
PowerLevelNotification,
)
Expand Down Expand Up @@ -47,6 +48,7 @@
ATTR_COMMAND_CLASS,
ATTR_COMMAND_CLASS_NAME,
ATTR_DATA_TYPE,
ATTR_DIRECTION,
ATTR_ENDPOINT,
ATTR_EVENT,
ATTR_EVENT_DATA,
Expand Down Expand Up @@ -403,7 +405,7 @@ def async_on_notification(event: dict[str, Any]) -> None:
if "notification" not in event:
LOGGER.info("Unknown notification: %s", event)
return
notification: EntryControlNotification | NotificationNotification | PowerLevelNotification = event[
notification: EntryControlNotification | NotificationNotification | PowerLevelNotification | MultilevelSwitchNotification = event[
"notification"
]
device = dev_reg.async_get_device({get_device_id(client, notification.node)})
Expand Down Expand Up @@ -446,6 +448,14 @@ def async_on_notification(event: dict[str, Any]) -> None:
ATTR_ACKNOWLEDGED_FRAMES: notification.acknowledged_frames,
}
)
elif isinstance(notification, MultilevelSwitchNotification):
event_data.update(
{
ATTR_COMMAND_CLASS_NAME: "Multilevel Switch",
ATTR_EVENT_TYPE: notification.event_type,
ATTR_DIRECTION: notification.direction,
}
)
else:
raise TypeError(f"Unhandled notification type: {notification}")

Expand Down
1 change: 1 addition & 0 deletions homeassistant/components/zwave_js/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
ATTR_PROPERTY = "property"
ATTR_PROPERTY_KEY = "property_key"
ATTR_PARAMETERS = "parameters"
ATTR_DIRECTION = "direction"
ATTR_EVENT = "event"
ATTR_EVENT_LABEL = "event_label"
ATTR_EVENT_TYPE = "event_type"
Expand Down
23 changes: 23 additions & 0 deletions tests/components/zwave_js/test_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,29 @@ async def test_notifications(hass, hank_binary_switch, integration, client):
assert events[1].data["command_class"] == CommandClass.ENTRY_CONTROL
assert events[1].data["command_class_name"] == "Entry Control"

# Publish fake Multilevel Switch CC notification
event = Event(
type="notification",
data={
"source": "node",
"event": "notification",
"nodeId": 32,
"ccId": 38,
"args": {"eventType": 4, "direction": "up"},
},
)

node.receive_event(event)
# wait for the event
await hass.async_block_till_done()
assert len(events) == 3
assert events[2].data["home_id"] == client.driver.controller.home_id
assert events[2].data["node_id"] == 32
assert events[2].data["event_type"] == 4
assert events[2].data["direction"] == "up"
assert events[2].data["command_class"] == CommandClass.SWITCH_MULTILEVEL
assert events[2].data["command_class_name"] == "Multilevel Switch"


async def test_value_updated(hass, vision_security_zl7432, integration, client):
"""Test value updated events."""
Expand Down