mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 04:07:08 +00:00
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 comment
This commit is contained in:
parent
0cea54cea1
commit
acdf9c7ce2
@ -21,7 +21,7 @@ from homeassistant.helpers.entity_component import EntityComponent
|
|||||||
# Loading the config flow file will register the flow
|
# Loading the config flow file will register the flow
|
||||||
from . import config_flow # noqa # pylint: disable=unused-import
|
from . import config_flow # noqa # pylint: disable=unused-import
|
||||||
from . import const as zha_const
|
from . import const as zha_const
|
||||||
from .event import ZhaEvent
|
from .event import ZhaEvent, ZhaRelayEvent
|
||||||
from .const import (
|
from .const import (
|
||||||
COMPONENTS, CONF_BAUDRATE, CONF_DATABASE, CONF_DEVICE_CONFIG,
|
COMPONENTS, CONF_BAUDRATE, CONF_DATABASE, CONF_DEVICE_CONFIG,
|
||||||
CONF_RADIO_TYPE, CONF_USB_PATH, DATA_ZHA, DATA_ZHA_BRIDGE_ID,
|
CONF_RADIO_TYPE, CONF_USB_PATH, DATA_ZHA, DATA_ZHA_BRIDGE_ID,
|
||||||
@ -393,6 +393,14 @@ class ApplicationListener:
|
|||||||
if cluster.cluster_id in EVENTABLE_CLUSTERS:
|
if cluster.cluster_id in EVENTABLE_CLUSTERS:
|
||||||
if cluster.endpoint.device.ieee not in self._events:
|
if cluster.endpoint.device.ieee not in self._events:
|
||||||
self._events.update({cluster.endpoint.device.ieee: []})
|
self._events.update({cluster.endpoint.device.ieee: []})
|
||||||
|
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._events[cluster.endpoint.device.ieee].append(ZhaEvent(
|
||||||
self._hass,
|
self._hass,
|
||||||
cluster
|
cluster
|
||||||
|
@ -67,3 +67,33 @@ class ZhaEvent():
|
|||||||
},
|
},
|
||||||
EventOrigin.remote
|
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…
x
Reference in New Issue
Block a user