From 4f3a2c0443c880e4547ea31c5d8345f9202788fa Mon Sep 17 00:00:00 2001 From: "David F. Mulcahey" Date: Tue, 10 Sep 2019 16:14:22 -0400 Subject: [PATCH] fix events for smartthings acceleration cluster (#26557) --- .../zha/core/channels/manufacturerspecific.py | 30 ++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/zha/core/channels/manufacturerspecific.py b/homeassistant/components/zha/core/channels/manufacturerspecific.py index 6ed9de9b30..6b4d2e2c08 100644 --- a/homeassistant/components/zha/core/channels/manufacturerspecific.py +++ b/homeassistant/components/zha/core/channels/manufacturerspecific.py @@ -6,9 +6,17 @@ https://home-assistant.io/components/zha/ """ import logging +from homeassistant.core import callback +from homeassistant.helpers.dispatcher import async_dispatcher_send + from . import AttributeListeningChannel from .. import registries -from ..const import REPORT_CONFIG_ASAP, REPORT_CONFIG_MAX_INT, REPORT_CONFIG_MIN_INT +from ..const import ( + REPORT_CONFIG_ASAP, + REPORT_CONFIG_MAX_INT, + REPORT_CONFIG_MIN_INT, + SIGNAL_ATTR_UPDATED, +) _LOGGER = logging.getLogger(__name__) @@ -38,3 +46,23 @@ class SmartThingsAcceleration(AttributeListeningChannel): {"attr": "y_axis", "config": REPORT_CONFIG_ASAP}, {"attr": "z_axis", "config": REPORT_CONFIG_ASAP}, ] + + @callback + def attribute_updated(self, attrid, value): + """Handle attribute updates on this cluster.""" + if attrid == self.value_attribute: + async_dispatcher_send( + self._zha_device.hass, f"{self.unique_id}_{SIGNAL_ATTR_UPDATED}", value + ) + else: + self.zha_send_event( + self._cluster, + SIGNAL_ATTR_UPDATED, + { + "attribute_id": attrid, + "attribute_name": self._cluster.attributes.get(attrid, ["Unknown"])[ + 0 + ], + "value": value, + }, + )