From 3901b5c8e868f7e07b12859980b60f47dbc82201 Mon Sep 17 00:00:00 2001 From: Reuben Bijl Date: Wed, 27 Apr 2022 19:12:23 +1200 Subject: [PATCH] Add zwave_js MultilevelSwitch Notification (#70470) Co-authored-by: Raman Gupta <7243222+raman325@users.noreply.github.com> --- homeassistant/components/zwave_js/__init__.py | 12 +++++++++- homeassistant/components/zwave_js/const.py | 1 + tests/components/zwave_js/test_events.py | 23 +++++++++++++++++++ 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/zwave_js/__init__.py b/homeassistant/components/zwave_js/__init__.py index fa87ad954ad..d12c7df6a79 100644 --- a/homeassistant/components/zwave_js/__init__.py +++ b/homeassistant/components/zwave_js/__init__.py @@ -12,6 +12,7 @@ from zwave_js_server.exceptions import BaseZwaveJSServerError, InvalidServerVers from zwave_js_server.model.node import Node as ZwaveNode from zwave_js_server.model.notification import ( EntryControlNotification, + MultilevelSwitchNotification, NotificationNotification, PowerLevelNotification, ) @@ -47,6 +48,7 @@ from .const import ( ATTR_COMMAND_CLASS, ATTR_COMMAND_CLASS_NAME, ATTR_DATA_TYPE, + ATTR_DIRECTION, ATTR_ENDPOINT, ATTR_EVENT, ATTR_EVENT_DATA, @@ -403,7 +405,7 @@ async def async_setup_entry( # noqa: C901 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)}) @@ -446,6 +448,14 @@ async def async_setup_entry( # noqa: C901 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}") diff --git a/homeassistant/components/zwave_js/const.py b/homeassistant/components/zwave_js/const.py index e2b339e6d79..1fd8e3e9d14 100644 --- a/homeassistant/components/zwave_js/const.py +++ b/homeassistant/components/zwave_js/const.py @@ -45,6 +45,7 @@ ATTR_PROPERTY_KEY_NAME = "property_key_name" 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" diff --git a/tests/components/zwave_js/test_events.py b/tests/components/zwave_js/test_events.py index 5085175de83..72da1fcb915 100644 --- a/tests/components/zwave_js/test_events.py +++ b/tests/components/zwave_js/test_events.py @@ -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."""