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 homeassistant/components/zha/core/channels/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,4 +199,4 @@ async def async_read_state(self, from_cache):
await self.get_attribute_value(
'battery_percentage_remaining', from_cache=from_cache)
await self.get_attribute_value(
'active_power', from_cache=from_cache)
'battery_voltage', from_cache=from_cache)
10 changes: 10 additions & 0 deletions homeassistant/components/zha/core/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
https://home-assistant.io/components/zha/
"""
import asyncio
from enum import Enum
import logging

from homeassistant.helpers.dispatcher import (
Expand All @@ -23,6 +24,13 @@
_LOGGER = logging.getLogger(__name__)


class DeviceStatus(Enum):
"""Status of a device."""

CREATED = 1
INITIALIZED = 2


class ZHADevice:
"""ZHA Zigbee device object."""

Expand Down Expand Up @@ -61,6 +69,7 @@ def __init__(self, hass, zigpy_device, zha_gateway):
self._zigpy_device.__class__.__name__
)
self.power_source = None
self.status = DeviceStatus.CREATED

@property
def name(self):
Expand Down Expand Up @@ -186,6 +195,7 @@ async def async_initialize(self, from_cache=False):
self.name,
BasicChannel.POWER_SOURCES.get(self.power_source)
)
self.status = DeviceStatus.INITIALIZED
_LOGGER.debug('%s: completed initialization', self.name)

async def _execute_channel_tasks(self, task_name, *args):
Expand Down
21 changes: 12 additions & 9 deletions homeassistant/components/zha/core/gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
REPORT_CONFIG_ASAP, REPORT_CONFIG_DEFAULT, REPORT_CONFIG_MIN_INT,
REPORT_CONFIG_MAX_INT, REPORT_CONFIG_OP, SIGNAL_REMOVE, NO_SENSOR_CLUSTERS,
POWER_CONFIGURATION_CHANNEL)
from .device import ZHADevice
from .device import ZHADevice, DeviceStatus
from ..device_entity import ZhaDeviceEntity
from .channels import (
AttributeListeningChannel, EventRelayChannel, ZDOChannel
Expand Down Expand Up @@ -139,7 +139,9 @@ def async_update_device(self, sender):
"""Update device that has just become available."""
if sender.ieee in self.devices:
device = self.devices[sender.ieee]
device.update_available(True)
# avoid a race condition during new joins
if device.status is DeviceStatus.INITIALIZED:
device.update_available(True)

async def async_device_initialized(self, device, is_new_join):
"""Handle device joined and basic information discovered (async)."""
Expand Down Expand Up @@ -319,20 +321,21 @@ async def _handle_single_cluster_matches(hass, endpoint, zha_device,
cluster_match_tasks = []
event_channel_tasks = []
for cluster in endpoint.in_clusters.values():
if cluster.cluster_id not in profile_clusters[0]:
cluster_match_tasks.append(_handle_single_cluster_match(
hass,
# don't let profiles prevent these channels from being created
if cluster.cluster_id in NO_SENSOR_CLUSTERS:
cluster_match_tasks.append(_handle_channel_only_cluster_match(
zha_device,
cluster,
device_key,
zha_const.SINGLE_INPUT_CLUSTER_DEVICE_CLASS,
is_new_join,
))

if cluster.cluster_id in NO_SENSOR_CLUSTERS:
cluster_match_tasks.append(_handle_channel_only_cluster_match(
if cluster.cluster_id not in profile_clusters[0]:
cluster_match_tasks.append(_handle_single_cluster_match(
hass,
zha_device,
cluster,
device_key,
zha_const.SINGLE_INPUT_CLUSTER_DEVICE_CLASS,
is_new_join,
))

Expand Down