From 74cef6966d6a9469566694fd1120d1123f8d183a Mon Sep 17 00:00:00 2001 From: Dan Klaffenbach Date: Tue, 15 Sep 2020 21:13:17 +0200 Subject: [PATCH] Expose angle and xy attributes in deCONZ event if present (#39822) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit These attribute are used by the color wheel on the Müller Licht tint remote control. --- homeassistant/components/deconz/const.py | 2 ++ .../components/deconz/deconz_event.py | 8 ++++++- tests/components/deconz/test_deconz_event.py | 24 ++++++++++++++++++- 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/deconz/const.py b/homeassistant/components/deconz/const.py index c2190321fdf..0937339ab94 100644 --- a/homeassistant/components/deconz/const.py +++ b/homeassistant/components/deconz/const.py @@ -44,4 +44,6 @@ POWER_PLUGS = ["On/Off light", "On/Off plug-in unit", "Smart plug"] SIRENS = ["Warning device"] SWITCH_TYPES = POWER_PLUGS + SIRENS +CONF_ANGLE = "angle" CONF_GESTURE = "gesture" +CONF_XY = "xy" diff --git a/homeassistant/components/deconz/deconz_event.py b/homeassistant/components/deconz/deconz_event.py index 9ad4a7f3162..d1325bcddd6 100644 --- a/homeassistant/components/deconz/deconz_event.py +++ b/homeassistant/components/deconz/deconz_event.py @@ -3,7 +3,7 @@ from homeassistant.const import CONF_EVENT, CONF_ID, CONF_UNIQUE_ID from homeassistant.core import callback from homeassistant.util import slugify -from .const import CONF_GESTURE, LOGGER +from .const import CONF_ANGLE, CONF_GESTURE, CONF_XY, LOGGER from .deconz_device import DeconzBase CONF_DECONZ_EVENT = "deconz_event" @@ -52,6 +52,12 @@ class DeconzEvent(DeconzBase): if self._device.gesture is not None: data[CONF_GESTURE] = self._device.gesture + if self._device.angle is not None: + data[CONF_ANGLE] = self._device.angle + + if self._device.xy is not None: + data[CONF_XY] = self._device.xy + self.gateway.hass.bus.async_fire(CONF_DECONZ_EVENT, data) async def async_update_device_registry(self): diff --git a/tests/components/deconz/test_deconz_event.py b/tests/components/deconz/test_deconz_event.py index fc8d4f9d1ba..525821e389f 100644 --- a/tests/components/deconz/test_deconz_event.py +++ b/tests/components/deconz/test_deconz_event.py @@ -40,6 +40,14 @@ SENSORS = { "config": {"battery": 100}, "uniqueid": "00:00:00:00:00:00:00:04-00", }, + "5": { + "id": "ZHA remote 1 id", + "name": "ZHA remote 1", + "type": "ZHASwitch", + "state": {"angle": 0, "buttonevent": 1000, "xy": [0.0, 0.0]}, + "config": {"group": "4,5,6", "reachable": True, "on": True}, + "uniqueid": "00:00:00:00:00:00:00:05-00", + }, } @@ -53,7 +61,7 @@ async def test_deconz_events(hass): assert "sensor.switch_2" not in gateway.deconz_ids assert "sensor.switch_2_battery_level" in gateway.deconz_ids assert len(hass.states.async_all()) == 3 - assert len(gateway.events) == 4 + assert len(gateway.events) == 5 switch_1 = hass.states.get("sensor.switch_1") assert switch_1 is None @@ -101,6 +109,20 @@ async def test_deconz_events(hass): "gesture": 0, } + gateway.api.sensors["5"].update( + {"state": {"buttonevent": 6002, "angle": 110, "xy": [0.5982, 0.3897]}} + ) + await hass.async_block_till_done() + + assert len(events) == 4 + assert events[3].data == { + "id": "zha_remote_1", + "unique_id": "00:00:00:00:00:00:00:05", + "event": 6002, + "angle": 110, + "xy": [0.5982, 0.3897], + } + await gateway.async_reset() assert len(hass.states.async_all()) == 0