fix events for smartthings acceleration cluster (#26557)

This commit is contained in:
David F. Mulcahey authored and Paulus Schoutsen committed 2019-09-10 13:14:22 -07:00
1 parent 6f27c5ae46
commit 4f3a2c0443
1 file changed
+29 -1
@@ -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,
},
)