mirror of
https://github.com/home-assistant/core.git
synced 2025-08-03 04:35:11 +02:00
add ZHA channel name property (#22218)
* Make channel name a property. * Cleanup Zigbee channels. Use zcl.Cluster.ep_attribute as default channel name.
This commit is contained in:
committed by
Paulus Schoutsen
parent
2b02c0d0fc
commit
03855c18fc
@@ -83,9 +83,14 @@ class ChannelStatus(Enum):
|
|||||||
class ZigbeeChannel:
|
class ZigbeeChannel:
|
||||||
"""Base channel for a Zigbee cluster."""
|
"""Base channel for a Zigbee cluster."""
|
||||||
|
|
||||||
|
CHANNEL_NAME = None
|
||||||
|
|
||||||
def __init__(self, cluster, device):
|
def __init__(self, cluster, device):
|
||||||
"""Initialize ZigbeeChannel."""
|
"""Initialize ZigbeeChannel."""
|
||||||
self.name = 'channel_{}'.format(cluster.cluster_id)
|
self._channel_name = cluster.ep_attribute
|
||||||
|
if self.CHANNEL_NAME:
|
||||||
|
self._channel_name = self.CHANNEL_NAME
|
||||||
|
self._generic_id = 'channel_0x{:04x}'.format(cluster.cluster_id)
|
||||||
self._cluster = cluster
|
self._cluster = cluster
|
||||||
self._zha_device = device
|
self._zha_device = device
|
||||||
self._unique_id = construct_unique_id(cluster)
|
self._unique_id = construct_unique_id(cluster)
|
||||||
@@ -96,6 +101,11 @@ class ZigbeeChannel:
|
|||||||
self._status = ChannelStatus.CREATED
|
self._status = ChannelStatus.CREATED
|
||||||
self._cluster.add_listener(self)
|
self._cluster.add_listener(self)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def generic_id(self):
|
||||||
|
"""Return the generic id for this channel."""
|
||||||
|
return self._generic_id
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def unique_id(self):
|
def unique_id(self):
|
||||||
"""Return the unique id for this channel."""
|
"""Return the unique id for this channel."""
|
||||||
@@ -111,6 +121,11 @@ class ZigbeeChannel:
|
|||||||
"""Return the device this channel is linked to."""
|
"""Return the device this channel is linked to."""
|
||||||
return self._zha_device
|
return self._zha_device
|
||||||
|
|
||||||
|
@property
|
||||||
|
def name(self) -> str:
|
||||||
|
"""Return friendly name."""
|
||||||
|
return self._channel_name
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def status(self):
|
def status(self):
|
||||||
"""Return the status of the channel."""
|
"""Return the status of the channel."""
|
||||||
@@ -215,10 +230,11 @@ class ZigbeeChannel:
|
|||||||
class AttributeListeningChannel(ZigbeeChannel):
|
class AttributeListeningChannel(ZigbeeChannel):
|
||||||
"""Channel for attribute reports from the cluster."""
|
"""Channel for attribute reports from the cluster."""
|
||||||
|
|
||||||
|
CHANNEL_NAME = ATTRIBUTE_CHANNEL
|
||||||
|
|
||||||
def __init__(self, cluster, device):
|
def __init__(self, cluster, device):
|
||||||
"""Initialize AttributeListeningChannel."""
|
"""Initialize AttributeListeningChannel."""
|
||||||
super().__init__(cluster, device)
|
super().__init__(cluster, device)
|
||||||
self.name = ATTRIBUTE_CHANNEL
|
|
||||||
attr = self._report_config[0].get('attr')
|
attr = self._report_config[0].get('attr')
|
||||||
if isinstance(attr, str):
|
if isinstance(attr, str):
|
||||||
self.value_attribute = get_attr_id_by_name(self.cluster, attr)
|
self.value_attribute = get_attr_id_by_name(self.cluster, attr)
|
||||||
@@ -340,10 +356,7 @@ class ZDOChannel:
|
|||||||
class EventRelayChannel(ZigbeeChannel):
|
class EventRelayChannel(ZigbeeChannel):
|
||||||
"""Event relay that can be attached to zigbee clusters."""
|
"""Event relay that can be attached to zigbee clusters."""
|
||||||
|
|
||||||
def __init__(self, cluster, device):
|
CHANNEL_NAME = EVENT_RELAY_CHANNEL
|
||||||
"""Initialize EventRelayChannel."""
|
|
||||||
super().__init__(cluster, device)
|
|
||||||
self.name = EVENT_RELAY_CHANNEL
|
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def attribute_updated(self, attrid, value):
|
def attribute_updated(self, attrid, value):
|
||||||
|
@@ -11,8 +11,7 @@ from . import ZigbeeChannel, parse_and_log_command
|
|||||||
from ..helpers import get_attr_id_by_name
|
from ..helpers import get_attr_id_by_name
|
||||||
from ..const import (
|
from ..const import (
|
||||||
SIGNAL_ATTR_UPDATED, SIGNAL_MOVE_LEVEL, SIGNAL_SET_LEVEL,
|
SIGNAL_ATTR_UPDATED, SIGNAL_MOVE_LEVEL, SIGNAL_SET_LEVEL,
|
||||||
SIGNAL_STATE_ATTR, BASIC_CHANNEL, ON_OFF_CHANNEL, LEVEL_CHANNEL,
|
SIGNAL_STATE_ATTR
|
||||||
POWER_CONFIGURATION_CHANNEL
|
|
||||||
)
|
)
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
@@ -26,7 +25,6 @@ class OnOffChannel(ZigbeeChannel):
|
|||||||
def __init__(self, cluster, device):
|
def __init__(self, cluster, device):
|
||||||
"""Initialize OnOffChannel."""
|
"""Initialize OnOffChannel."""
|
||||||
super().__init__(cluster, device)
|
super().__init__(cluster, device)
|
||||||
self.name = ON_OFF_CHANNEL
|
|
||||||
self._state = None
|
self._state = None
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
@@ -77,11 +75,6 @@ class LevelControlChannel(ZigbeeChannel):
|
|||||||
|
|
||||||
CURRENT_LEVEL = 0
|
CURRENT_LEVEL = 0
|
||||||
|
|
||||||
def __init__(self, cluster, device):
|
|
||||||
"""Initialize LevelControlChannel."""
|
|
||||||
super().__init__(cluster, device)
|
|
||||||
self.name = LEVEL_CHANNEL
|
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def cluster_command(self, tsn, command_id, args):
|
def cluster_command(self, tsn, command_id, args):
|
||||||
"""Handle commands received to this cluster."""
|
"""Handle commands received to this cluster."""
|
||||||
@@ -149,7 +142,6 @@ class BasicChannel(ZigbeeChannel):
|
|||||||
def __init__(self, cluster, device):
|
def __init__(self, cluster, device):
|
||||||
"""Initialize BasicChannel."""
|
"""Initialize BasicChannel."""
|
||||||
super().__init__(cluster, device)
|
super().__init__(cluster, device)
|
||||||
self.name = BASIC_CHANNEL
|
|
||||||
self._power_source = None
|
self._power_source = None
|
||||||
|
|
||||||
async def async_configure(self):
|
async def async_configure(self):
|
||||||
@@ -171,11 +163,6 @@ class BasicChannel(ZigbeeChannel):
|
|||||||
class PowerConfigurationChannel(ZigbeeChannel):
|
class PowerConfigurationChannel(ZigbeeChannel):
|
||||||
"""Channel for the zigbee power configuration cluster."""
|
"""Channel for the zigbee power configuration cluster."""
|
||||||
|
|
||||||
def __init__(self, cluster, device):
|
|
||||||
"""Initialize PowerConfigurationChannel."""
|
|
||||||
super().__init__(cluster, device)
|
|
||||||
self.name = POWER_CONFIGURATION_CHANNEL
|
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def attribute_updated(self, attrid, value):
|
def attribute_updated(self, attrid, value):
|
||||||
"""Handle attribute updates on this cluster."""
|
"""Handle attribute updates on this cluster."""
|
||||||
|
@@ -15,18 +15,15 @@ _LOGGER = logging.getLogger(__name__)
|
|||||||
class ElectricalMeasurementChannel(AttributeListeningChannel):
|
class ElectricalMeasurementChannel(AttributeListeningChannel):
|
||||||
"""Channel that polls active power level."""
|
"""Channel that polls active power level."""
|
||||||
|
|
||||||
def __init__(self, cluster, device):
|
CHANNEL_NAME = ELECTRICAL_MEASUREMENT_CHANNEL
|
||||||
"""Initialize ElectricalMeasurementChannel."""
|
|
||||||
super().__init__(cluster, device)
|
|
||||||
self.name = ELECTRICAL_MEASUREMENT_CHANNEL
|
|
||||||
|
|
||||||
async def async_update(self):
|
async def async_update(self):
|
||||||
"""Retrieve latest state."""
|
"""Retrieve latest state."""
|
||||||
_LOGGER.debug("%s async_update", self.unique_id)
|
_LOGGER.debug("%s async_update", self.unique_id)
|
||||||
|
|
||||||
# This is a polling channel. Don't allow cache.
|
# This is a polling channel. Don't allow cache.
|
||||||
result = await self.get_attribute_value(
|
result = await self.get_attribute_value('active_power',
|
||||||
ELECTRICAL_MEASUREMENT_CHANNEL, from_cache=False)
|
from_cache=False)
|
||||||
async_dispatcher_send(
|
async_dispatcher_send(
|
||||||
self._zha_device.hass,
|
self._zha_device.hass,
|
||||||
"{}_{}".format(self.unique_id, SIGNAL_ATTR_UPDATED),
|
"{}_{}".format(self.unique_id, SIGNAL_ATTR_UPDATED),
|
||||||
@@ -35,6 +32,5 @@ class ElectricalMeasurementChannel(AttributeListeningChannel):
|
|||||||
|
|
||||||
async def async_initialize(self, from_cache):
|
async def async_initialize(self, from_cache):
|
||||||
"""Initialize channel."""
|
"""Initialize channel."""
|
||||||
await self.get_attribute_value(
|
await self.get_attribute_value('active_power', from_cache=from_cache)
|
||||||
ELECTRICAL_MEASUREMENT_CHANNEL, from_cache=from_cache)
|
|
||||||
await super().async_initialize(from_cache)
|
await super().async_initialize(from_cache)
|
||||||
|
@@ -8,7 +8,7 @@ import logging
|
|||||||
from homeassistant.core import callback
|
from homeassistant.core import callback
|
||||||
from homeassistant.helpers.dispatcher import async_dispatcher_send
|
from homeassistant.helpers.dispatcher import async_dispatcher_send
|
||||||
from . import ZigbeeChannel
|
from . import ZigbeeChannel
|
||||||
from ..const import FAN_CHANNEL, SIGNAL_ATTR_UPDATED
|
from ..const import SIGNAL_ATTR_UPDATED
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
@@ -18,11 +18,6 @@ class FanChannel(ZigbeeChannel):
|
|||||||
|
|
||||||
_value_attribute = 0
|
_value_attribute = 0
|
||||||
|
|
||||||
def __init__(self, cluster, device):
|
|
||||||
"""Initialize FanChannel."""
|
|
||||||
super().__init__(cluster, device)
|
|
||||||
self.name = FAN_CHANNEL
|
|
||||||
|
|
||||||
async def async_set_speed(self, value) -> None:
|
async def async_set_speed(self, value) -> None:
|
||||||
"""Set the speed of the fan."""
|
"""Set the speed of the fan."""
|
||||||
from zigpy.exceptions import DeliveryError
|
from zigpy.exceptions import DeliveryError
|
||||||
|
@@ -6,7 +6,6 @@ https://home-assistant.io/components/zha/
|
|||||||
"""
|
"""
|
||||||
import logging
|
import logging
|
||||||
from . import ZigbeeChannel
|
from . import ZigbeeChannel
|
||||||
from ..const import COLOR_CHANNEL
|
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
@@ -21,7 +20,6 @@ class ColorChannel(ZigbeeChannel):
|
|||||||
def __init__(self, cluster, device):
|
def __init__(self, cluster, device):
|
||||||
"""Initialize ColorChannel."""
|
"""Initialize ColorChannel."""
|
||||||
super().__init__(cluster, device)
|
super().__init__(cluster, device)
|
||||||
self.name = COLOR_CHANNEL
|
|
||||||
self._color_capabilities = None
|
self._color_capabilities = None
|
||||||
|
|
||||||
def get_color_capabilities(self):
|
def get_color_capabilities(self):
|
||||||
|
@@ -9,7 +9,7 @@ from homeassistant.core import callback
|
|||||||
from homeassistant.helpers.dispatcher import async_dispatcher_send
|
from homeassistant.helpers.dispatcher import async_dispatcher_send
|
||||||
from . import ZigbeeChannel
|
from . import ZigbeeChannel
|
||||||
from ..helpers import bind_cluster
|
from ..helpers import bind_cluster
|
||||||
from ..const import SIGNAL_ATTR_UPDATED, ZONE_CHANNEL
|
from ..const import SIGNAL_ATTR_UPDATED
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
@@ -17,11 +17,6 @@ _LOGGER = logging.getLogger(__name__)
|
|||||||
class IASZoneChannel(ZigbeeChannel):
|
class IASZoneChannel(ZigbeeChannel):
|
||||||
"""Channel for the IASZone Zigbee cluster."""
|
"""Channel for the IASZone Zigbee cluster."""
|
||||||
|
|
||||||
def __init__(self, cluster, device):
|
|
||||||
"""Initialize IASZoneChannel."""
|
|
||||||
super().__init__(cluster, device)
|
|
||||||
self.name = ZONE_CHANNEL
|
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def cluster_command(self, tsn, command_id, args):
|
def cluster_command(self, tsn, command_id, args):
|
||||||
"""Handle commands received to this cluster."""
|
"""Handle commands received to this cluster."""
|
||||||
|
@@ -87,12 +87,12 @@ ZDO_CHANNEL = 'zdo'
|
|||||||
ON_OFF_CHANNEL = 'on_off'
|
ON_OFF_CHANNEL = 'on_off'
|
||||||
ATTRIBUTE_CHANNEL = 'attribute'
|
ATTRIBUTE_CHANNEL = 'attribute'
|
||||||
BASIC_CHANNEL = 'basic'
|
BASIC_CHANNEL = 'basic'
|
||||||
COLOR_CHANNEL = 'color'
|
COLOR_CHANNEL = 'light_color'
|
||||||
FAN_CHANNEL = 'fan'
|
FAN_CHANNEL = 'fan'
|
||||||
LEVEL_CHANNEL = ATTR_LEVEL
|
LEVEL_CHANNEL = ATTR_LEVEL
|
||||||
ZONE_CHANNEL = 'zone'
|
ZONE_CHANNEL = 'ias_zone'
|
||||||
ELECTRICAL_MEASUREMENT_CHANNEL = 'active_power'
|
ELECTRICAL_MEASUREMENT_CHANNEL = 'electrical_measurement'
|
||||||
POWER_CONFIGURATION_CHANNEL = 'battery'
|
POWER_CONFIGURATION_CHANNEL = 'power'
|
||||||
EVENT_RELAY_CHANNEL = 'event_relay'
|
EVENT_RELAY_CHANNEL = 'event_relay'
|
||||||
|
|
||||||
SIGNAL_ATTR_UPDATED = 'attribute_updated'
|
SIGNAL_ATTR_UPDATED = 'attribute_updated'
|
||||||
|
Reference in New Issue
Block a user