diff --git a/homeassistant/components/zha/core/channels/__init__.py b/homeassistant/components/zha/core/channels/__init__.py index ef3ef71477f..d8a3918889d 100644 --- a/homeassistant/components/zha/core/channels/__init__.py +++ b/homeassistant/components/zha/core/channels/__init__.py @@ -83,9 +83,14 @@ class ChannelStatus(Enum): class ZigbeeChannel: """Base channel for a Zigbee cluster.""" + CHANNEL_NAME = None + def __init__(self, cluster, device): """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._zha_device = device self._unique_id = construct_unique_id(cluster) @@ -96,6 +101,11 @@ class ZigbeeChannel: self._status = ChannelStatus.CREATED self._cluster.add_listener(self) + @property + def generic_id(self): + """Return the generic id for this channel.""" + return self._generic_id + @property def unique_id(self): """Return the unique id for this channel.""" @@ -111,6 +121,11 @@ class ZigbeeChannel: """Return the device this channel is linked to.""" return self._zha_device + @property + def name(self) -> str: + """Return friendly name.""" + return self._channel_name + @property def status(self): """Return the status of the channel.""" @@ -215,10 +230,11 @@ class ZigbeeChannel: class AttributeListeningChannel(ZigbeeChannel): """Channel for attribute reports from the cluster.""" + CHANNEL_NAME = ATTRIBUTE_CHANNEL + def __init__(self, cluster, device): """Initialize AttributeListeningChannel.""" super().__init__(cluster, device) - self.name = ATTRIBUTE_CHANNEL attr = self._report_config[0].get('attr') if isinstance(attr, str): self.value_attribute = get_attr_id_by_name(self.cluster, attr) @@ -340,10 +356,7 @@ class ZDOChannel: class EventRelayChannel(ZigbeeChannel): """Event relay that can be attached to zigbee clusters.""" - def __init__(self, cluster, device): - """Initialize EventRelayChannel.""" - super().__init__(cluster, device) - self.name = EVENT_RELAY_CHANNEL + CHANNEL_NAME = EVENT_RELAY_CHANNEL @callback def attribute_updated(self, attrid, value): diff --git a/homeassistant/components/zha/core/channels/general.py b/homeassistant/components/zha/core/channels/general.py index c0b0367be99..bf0f1044efb 100644 --- a/homeassistant/components/zha/core/channels/general.py +++ b/homeassistant/components/zha/core/channels/general.py @@ -11,8 +11,7 @@ from . import ZigbeeChannel, parse_and_log_command from ..helpers import get_attr_id_by_name from ..const import ( SIGNAL_ATTR_UPDATED, SIGNAL_MOVE_LEVEL, SIGNAL_SET_LEVEL, - SIGNAL_STATE_ATTR, BASIC_CHANNEL, ON_OFF_CHANNEL, LEVEL_CHANNEL, - POWER_CONFIGURATION_CHANNEL + SIGNAL_STATE_ATTR ) _LOGGER = logging.getLogger(__name__) @@ -26,7 +25,6 @@ class OnOffChannel(ZigbeeChannel): def __init__(self, cluster, device): """Initialize OnOffChannel.""" super().__init__(cluster, device) - self.name = ON_OFF_CHANNEL self._state = None @callback @@ -77,11 +75,6 @@ class LevelControlChannel(ZigbeeChannel): CURRENT_LEVEL = 0 - def __init__(self, cluster, device): - """Initialize LevelControlChannel.""" - super().__init__(cluster, device) - self.name = LEVEL_CHANNEL - @callback def cluster_command(self, tsn, command_id, args): """Handle commands received to this cluster.""" @@ -149,7 +142,6 @@ class BasicChannel(ZigbeeChannel): def __init__(self, cluster, device): """Initialize BasicChannel.""" super().__init__(cluster, device) - self.name = BASIC_CHANNEL self._power_source = None async def async_configure(self): @@ -171,11 +163,6 @@ class BasicChannel(ZigbeeChannel): class PowerConfigurationChannel(ZigbeeChannel): """Channel for the zigbee power configuration cluster.""" - def __init__(self, cluster, device): - """Initialize PowerConfigurationChannel.""" - super().__init__(cluster, device) - self.name = POWER_CONFIGURATION_CHANNEL - @callback def attribute_updated(self, attrid, value): """Handle attribute updates on this cluster.""" diff --git a/homeassistant/components/zha/core/channels/homeautomation.py b/homeassistant/components/zha/core/channels/homeautomation.py index 2518889fcb1..e4b67dd0db7 100644 --- a/homeassistant/components/zha/core/channels/homeautomation.py +++ b/homeassistant/components/zha/core/channels/homeautomation.py @@ -15,18 +15,15 @@ _LOGGER = logging.getLogger(__name__) class ElectricalMeasurementChannel(AttributeListeningChannel): """Channel that polls active power level.""" - def __init__(self, cluster, device): - """Initialize ElectricalMeasurementChannel.""" - super().__init__(cluster, device) - self.name = ELECTRICAL_MEASUREMENT_CHANNEL + CHANNEL_NAME = ELECTRICAL_MEASUREMENT_CHANNEL async def async_update(self): """Retrieve latest state.""" _LOGGER.debug("%s async_update", self.unique_id) # This is a polling channel. Don't allow cache. - result = await self.get_attribute_value( - ELECTRICAL_MEASUREMENT_CHANNEL, from_cache=False) + result = await self.get_attribute_value('active_power', + from_cache=False) async_dispatcher_send( self._zha_device.hass, "{}_{}".format(self.unique_id, SIGNAL_ATTR_UPDATED), @@ -35,6 +32,5 @@ class ElectricalMeasurementChannel(AttributeListeningChannel): async def async_initialize(self, from_cache): """Initialize channel.""" - await self.get_attribute_value( - ELECTRICAL_MEASUREMENT_CHANNEL, from_cache=from_cache) + await self.get_attribute_value('active_power', from_cache=from_cache) await super().async_initialize(from_cache) diff --git a/homeassistant/components/zha/core/channels/hvac.py b/homeassistant/components/zha/core/channels/hvac.py index c62ec66588e..3da881e75d8 100644 --- a/homeassistant/components/zha/core/channels/hvac.py +++ b/homeassistant/components/zha/core/channels/hvac.py @@ -8,7 +8,7 @@ import logging from homeassistant.core import callback from homeassistant.helpers.dispatcher import async_dispatcher_send from . import ZigbeeChannel -from ..const import FAN_CHANNEL, SIGNAL_ATTR_UPDATED +from ..const import SIGNAL_ATTR_UPDATED _LOGGER = logging.getLogger(__name__) @@ -18,11 +18,6 @@ class FanChannel(ZigbeeChannel): _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: """Set the speed of the fan.""" from zigpy.exceptions import DeliveryError diff --git a/homeassistant/components/zha/core/channels/lighting.py b/homeassistant/components/zha/core/channels/lighting.py index 9c904a7a001..696a15b483b 100644 --- a/homeassistant/components/zha/core/channels/lighting.py +++ b/homeassistant/components/zha/core/channels/lighting.py @@ -6,7 +6,6 @@ https://home-assistant.io/components/zha/ """ import logging from . import ZigbeeChannel -from ..const import COLOR_CHANNEL _LOGGER = logging.getLogger(__name__) @@ -21,7 +20,6 @@ class ColorChannel(ZigbeeChannel): def __init__(self, cluster, device): """Initialize ColorChannel.""" super().__init__(cluster, device) - self.name = COLOR_CHANNEL self._color_capabilities = None def get_color_capabilities(self): diff --git a/homeassistant/components/zha/core/channels/security.py b/homeassistant/components/zha/core/channels/security.py index e8c0e71a263..03b50b7c7ba 100644 --- a/homeassistant/components/zha/core/channels/security.py +++ b/homeassistant/components/zha/core/channels/security.py @@ -9,7 +9,7 @@ from homeassistant.core import callback from homeassistant.helpers.dispatcher import async_dispatcher_send from . import ZigbeeChannel from ..helpers import bind_cluster -from ..const import SIGNAL_ATTR_UPDATED, ZONE_CHANNEL +from ..const import SIGNAL_ATTR_UPDATED _LOGGER = logging.getLogger(__name__) @@ -17,11 +17,6 @@ _LOGGER = logging.getLogger(__name__) class IASZoneChannel(ZigbeeChannel): """Channel for the IASZone Zigbee cluster.""" - def __init__(self, cluster, device): - """Initialize IASZoneChannel.""" - super().__init__(cluster, device) - self.name = ZONE_CHANNEL - @callback def cluster_command(self, tsn, command_id, args): """Handle commands received to this cluster.""" diff --git a/homeassistant/components/zha/core/const.py b/homeassistant/components/zha/core/const.py index 58cecb3600f..b7f418253d8 100644 --- a/homeassistant/components/zha/core/const.py +++ b/homeassistant/components/zha/core/const.py @@ -87,12 +87,12 @@ ZDO_CHANNEL = 'zdo' ON_OFF_CHANNEL = 'on_off' ATTRIBUTE_CHANNEL = 'attribute' BASIC_CHANNEL = 'basic' -COLOR_CHANNEL = 'color' +COLOR_CHANNEL = 'light_color' FAN_CHANNEL = 'fan' LEVEL_CHANNEL = ATTR_LEVEL -ZONE_CHANNEL = 'zone' -ELECTRICAL_MEASUREMENT_CHANNEL = 'active_power' -POWER_CONFIGURATION_CHANNEL = 'battery' +ZONE_CHANNEL = 'ias_zone' +ELECTRICAL_MEASUREMENT_CHANNEL = 'electrical_measurement' +POWER_CONFIGURATION_CHANNEL = 'power' EVENT_RELAY_CHANNEL = 'event_relay' SIGNAL_ATTR_UPDATED = 'attribute_updated'