Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -669,11 +669,11 @@ omit =
homeassistant/components/zha/__init__.py
homeassistant/components/zha/api.py
homeassistant/components/zha/const.py
homeassistant/components/zha/core/channels/*
homeassistant/components/zha/core/const.py
homeassistant/components/zha/core/device.py
homeassistant/components/zha/core/gateway.py
homeassistant/components/zha/core/helpers.py
homeassistant/components/zha/core/listeners.py
homeassistant/components/zha/device_entity.py
homeassistant/components/zha/entity.py
homeassistant/components/zha/light.py
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/zha/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
DATA_ZHA_RADIO, DEFAULT_BAUDRATE, DEFAULT_DATABASE_NAME,
DEFAULT_RADIO_TYPE, DOMAIN, RadioType, DATA_ZHA_CORE_EVENTS, ENABLE_QUIRKS)
from .core.gateway import establish_device_mappings
from .core.listeners import populate_listener_registry
from .core.channels.registry import populate_channel_registry

REQUIREMENTS = [
'bellows==0.7.0',
Expand Down Expand Up @@ -90,7 +90,7 @@ async def async_setup_entry(hass, config_entry):
Will automatically load components to support devices found on the network.
"""
establish_device_mappings()
populate_listener_registry()
populate_channel_registry()

for component in COMPONENTS:
hass.data[DATA_ZHA][component] = (
Expand Down
46 changes: 23 additions & 23 deletions homeassistant/components/zha/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
from homeassistant.components.binary_sensor import DOMAIN, BinarySensorDevice
from homeassistant.helpers.dispatcher import async_dispatcher_connect
from .core.const import (
DATA_ZHA, DATA_ZHA_DISPATCHERS, ZHA_DISCOVERY_NEW, LISTENER_ON_OFF,
LISTENER_LEVEL, LISTENER_ZONE, SIGNAL_ATTR_UPDATED, SIGNAL_MOVE_LEVEL,
SIGNAL_SET_LEVEL, LISTENER_ATTRIBUTE, UNKNOWN, OPENING, ZONE, OCCUPANCY,
DATA_ZHA, DATA_ZHA_DISPATCHERS, ZHA_DISCOVERY_NEW, ON_OFF_CHANNEL,
LEVEL_CHANNEL, ZONE_CHANNEL, SIGNAL_ATTR_UPDATED, SIGNAL_MOVE_LEVEL,
SIGNAL_SET_LEVEL, ATTRIBUTE_CHANNEL, UNKNOWN, OPENING, ZONE, OCCUPANCY,
ATTR_LEVEL, SENSOR_TYPE)
from .entity import ZhaEntity

Expand All @@ -30,9 +30,9 @@
}


async def get_ias_device_class(listener):
"""Get the HA device class from the listener."""
zone_type = await listener.get_attribute_value('zone_type')
async def get_ias_device_class(channel):
"""Get the HA device class from the channel."""
zone_type = await channel.get_attribute_value('zone_type')
return CLASS_MAPPING.get(zone_type)


Expand Down Expand Up @@ -87,10 +87,10 @@ def __init__(self, **kwargs):
"""Initialize the ZHA binary sensor."""
super().__init__(**kwargs)
self._device_state_attributes = {}
self._zone_listener = self.cluster_listeners.get(LISTENER_ZONE)
self._on_off_listener = self.cluster_listeners.get(LISTENER_ON_OFF)
self._level_listener = self.cluster_listeners.get(LISTENER_LEVEL)
self._attr_listener = self.cluster_listeners.get(LISTENER_ATTRIBUTE)
self._zone_channel = self.cluster_channels.get(ZONE_CHANNEL)
self._on_off_channel = self.cluster_channels.get(ON_OFF_CHANNEL)
self._level_channel = self.cluster_channels.get(LEVEL_CHANNEL)
self._attr_channel = self.cluster_channels.get(ATTRIBUTE_CHANNEL)
self._zha_sensor_type = kwargs[SENSOR_TYPE]
self._level = None

Expand All @@ -99,31 +99,31 @@ async def _determine_device_class(self):
device_class_supplier = DEVICE_CLASS_REGISTRY.get(
self._zha_sensor_type)
if callable(device_class_supplier):
listener = self.cluster_listeners.get(self._zha_sensor_type)
if listener is None:
channel = self.cluster_channels.get(self._zha_sensor_type)
if channel is None:
return None
return await device_class_supplier(listener)
return await device_class_supplier(channel)
return device_class_supplier

async def async_added_to_hass(self):
"""Run when about to be added to hass."""
self._device_class = await self._determine_device_class()
await super().async_added_to_hass()
if self._level_listener:
if self._level_channel:
await self.async_accept_signal(
self._level_listener, SIGNAL_SET_LEVEL, self.set_level)
self._level_channel, SIGNAL_SET_LEVEL, self.set_level)
await self.async_accept_signal(
self._level_listener, SIGNAL_MOVE_LEVEL, self.move_level)
if self._on_off_listener:
self._level_channel, SIGNAL_MOVE_LEVEL, self.move_level)
if self._on_off_channel:
await self.async_accept_signal(
self._on_off_listener, SIGNAL_ATTR_UPDATED,
self._on_off_channel, SIGNAL_ATTR_UPDATED,
self.async_set_state)
if self._zone_listener:
if self._zone_channel:
await self.async_accept_signal(
self._zone_listener, SIGNAL_ATTR_UPDATED, self.async_set_state)
if self._attr_listener:
self._zone_channel, SIGNAL_ATTR_UPDATED, self.async_set_state)
if self._attr_channel:
await self.async_accept_signal(
self._attr_listener, SIGNAL_ATTR_UPDATED, self.async_set_state)
self._attr_channel, SIGNAL_ATTR_UPDATED, self.async_set_state)

@property
def is_on(self) -> bool:
Expand Down Expand Up @@ -160,7 +160,7 @@ def set_level(self, level):
@property
def device_state_attributes(self):
"""Return the device state attributes."""
if self._level_listener is not None:
if self._level_channel is not None:
self._device_state_attributes.update({
ATTR_LEVEL: self._state and self._level or 0
})
Expand Down
3 changes: 0 additions & 3 deletions homeassistant/components/zha/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,3 @@
# flake8: noqa
from .device import ZHADevice
from .gateway import ZHAGateway
from .listeners import (
ClusterListener, AttributeListener, OnOffListener, LevelListener,
IASZoneListener, ActivePowerListener, BatteryListener, EventRelayListener)
Loading