Relay events for onoff and levelcontrol output clusters in ZHA (#19863)
* auto relay events for onoff and levelcontrol output clusters * fix docstring * correct copy/paste failure - review comment * add space - review commentpull/19875/head
parent
0cea54cea1
commit
acdf9c7ce2
|
@ -21,7 +21,7 @@ from homeassistant.helpers.entity_component import EntityComponent
|
|||
# Loading the config flow file will register the flow
|
||||
from . import config_flow # noqa # pylint: disable=unused-import
|
||||
from . import const as zha_const
|
||||
from .event import ZhaEvent
|
||||
from .event import ZhaEvent, ZhaRelayEvent
|
||||
from .const import (
|
||||
COMPONENTS, CONF_BAUDRATE, CONF_DATABASE, CONF_DEVICE_CONFIG,
|
||||
CONF_RADIO_TYPE, CONF_USB_PATH, DATA_ZHA, DATA_ZHA_BRIDGE_ID,
|
||||
|
@ -393,10 +393,18 @@ class ApplicationListener:
|
|||
if cluster.cluster_id in EVENTABLE_CLUSTERS:
|
||||
if cluster.endpoint.device.ieee not in self._events:
|
||||
self._events.update({cluster.endpoint.device.ieee: []})
|
||||
self._events[cluster.endpoint.device.ieee].append(ZhaEvent(
|
||||
self._hass,
|
||||
cluster
|
||||
))
|
||||
from zigpy.zcl.clusters.general import OnOff, LevelControl
|
||||
if discovery_attr == 'out_clusters' and \
|
||||
(cluster.cluster_id == OnOff.cluster_id or
|
||||
cluster.cluster_id == LevelControl.cluster_id):
|
||||
self._events[cluster.endpoint.device.ieee].append(
|
||||
ZhaRelayEvent(self._hass, cluster)
|
||||
)
|
||||
else:
|
||||
self._events[cluster.endpoint.device.ieee].append(ZhaEvent(
|
||||
self._hass,
|
||||
cluster
|
||||
))
|
||||
|
||||
if cluster.cluster_id in profile_clusters:
|
||||
return
|
||||
|
|
|
@ -67,3 +67,33 @@ class ZhaEvent():
|
|||
},
|
||||
EventOrigin.remote
|
||||
)
|
||||
|
||||
|
||||
class ZhaRelayEvent(ZhaEvent):
|
||||
"""Event relay that can be attached to zigbee clusters."""
|
||||
|
||||
@callback
|
||||
def attribute_updated(self, attribute, value):
|
||||
"""Handle an attribute updated on this cluster."""
|
||||
self.zha_send_event(
|
||||
self._cluster,
|
||||
'attribute_updated',
|
||||
{
|
||||
'attribute_id': attribute,
|
||||
'attribute_name': self._cluster.attributes.get(
|
||||
attribute,
|
||||
['Unknown'])[0],
|
||||
'value': value
|
||||
}
|
||||
)
|
||||
|
||||
@callback
|
||||
def cluster_command(self, tsn, command_id, args):
|
||||
"""Handle a cluster command received on this cluster."""
|
||||
if self._cluster.server_commands is not None and\
|
||||
self._cluster.server_commands.get(command_id) is not None:
|
||||
self.zha_send_event(
|
||||
self._cluster,
|
||||
self._cluster.server_commands.get(command_id)[0],
|
||||
args
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue