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
8 changes: 3 additions & 5 deletions homeassistant/components/zha/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,9 @@ def handle_message(sender, is_reply, profile, cluster,
"""Handle message from a device."""
if not sender.initializing and sender.ieee in zha_gateway.devices and \
not zha_gateway.devices[sender.ieee].available:
hass.async_create_task(
zha_gateway.async_device_became_available(
sender, is_reply, profile, cluster, src_ep, dst_ep, tsn,
command_id, args
)
zha_gateway.async_device_became_available(
sender, is_reply, profile, cluster, src_ep, dst_ep, tsn,
command_id, args
)
return sender.handle_message(
is_reply, profile, cluster, src_ep, dst_ep, tsn, command_id, args)
Expand Down
8 changes: 4 additions & 4 deletions homeassistant/components/zha/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ async def websocket_device_clusters(hass, connection, msg):
zha_device = zha_gateway.get_device(ieee)
response_clusters = []
if zha_device is not None:
clusters_by_endpoint = await zha_device.get_clusters()
clusters_by_endpoint = zha_device.async_get_clusters()
for ep_id, clusters in clusters_by_endpoint.items():
for c_id, cluster in clusters[IN].items():
response_clusters.append({
Expand Down Expand Up @@ -289,7 +289,7 @@ async def websocket_device_cluster_attributes(hass, connection, msg):
zha_device = zha_gateway.get_device(ieee)
attributes = None
if zha_device is not None:
attributes = await zha_device.get_cluster_attributes(
attributes = zha_device.async_get_cluster_attributes(
endpoint_id,
cluster_id,
cluster_type)
Expand Down Expand Up @@ -329,7 +329,7 @@ async def websocket_device_cluster_commands(hass, connection, msg):
cluster_commands = []
commands = None
if zha_device is not None:
commands = await zha_device.get_cluster_commands(
commands = zha_device.async_get_cluster_commands(
endpoint_id,
cluster_id,
cluster_type)
Expand Down Expand Up @@ -380,7 +380,7 @@ async def websocket_read_zigbee_cluster_attributes(hass, connection, msg):
zha_device = zha_gateway.get_device(ieee)
success = failure = None
if zha_device is not None:
cluster = await zha_device.get_cluster(
cluster = zha_device.async_get_cluster(
endpoint_id, cluster_id, cluster_type=cluster_type)
success, failure = await cluster.read_attributes(
[attribute],
Expand Down
11 changes: 8 additions & 3 deletions homeassistant/components/zha/core/channels/__init__.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 concurrent.futures import TimeoutError as Timeout
from enum import Enum
from functools import wraps
import logging
Expand Down Expand Up @@ -55,9 +56,13 @@ async def wrapper(*args, **kwds):
if isinstance(result, bool):
return result
return result[1] is Status.SUCCESS
except DeliveryError:
_LOGGER.debug("%s: command failed: %s", channel.unique_id,
command.__name__)
except (DeliveryError, Timeout) as ex:
_LOGGER.debug(
"%s: command failed: %s exception: %s",
channel.unique_id,
command.__name__,
str(ex)
)
return False
return wrapper

Expand Down
8 changes: 8 additions & 0 deletions homeassistant/components/zha/core/channels/lighting.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,16 @@ def get_color_capabilities(self):
"""Return the color capabilities."""
return self._color_capabilities

async def async_configure(self):
"""Configure channel."""
await self.fetch_color_capabilities(False)

async def async_initialize(self, from_cache):
"""Initialize channel."""
await self.fetch_color_capabilities(True)

async def fetch_color_capabilities(self, from_cache):
"""Get the color configuration."""
capabilities = await self.get_attribute_value(
'color_capabilities', from_cache=from_cache)

Expand Down
41 changes: 22 additions & 19 deletions homeassistant/components/zha/core/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from enum import Enum
import logging

from homeassistant.core import callback
from homeassistant.helpers.dispatcher import (
async_dispatcher_connect, async_dispatcher_send
)
Expand Down Expand Up @@ -188,13 +189,14 @@ async def async_initialize(self, from_cache=False):
"""Initialize channels."""
_LOGGER.debug('%s: started initialization', self.name)
await self._execute_channel_tasks('async_initialize', from_cache)
self.power_source = self.cluster_channels.get(
BASIC_CHANNEL).get_power_source()
_LOGGER.debug(
'%s: power source: %s',
self.name,
BasicChannel.POWER_SOURCES.get(self.power_source)
)
if BASIC_CHANNEL in self.cluster_channels:
self.power_source = self.cluster_channels.get(
BASIC_CHANNEL).get_power_source()
_LOGGER.debug(
'%s: power source: %s',
self.name,
BasicChannel.POWER_SOURCES.get(self.power_source)
)
self.status = DeviceStatus.INITIALIZED
_LOGGER.debug('%s: completed initialization', self.name)

Expand Down Expand Up @@ -229,7 +231,8 @@ async def async_unsub_dispatcher(self):
if self._unsub:
self._unsub()

async def get_clusters(self):
@callback
def async_get_clusters(self):
"""Get all clusters for this device."""
return {
ep_id: {
Expand All @@ -239,25 +242,27 @@ async def get_clusters(self):
if ep_id != 0
}

async def get_cluster(self, endpoint_id, cluster_id, cluster_type=IN):
@callback
def async_get_cluster(self, endpoint_id, cluster_id, cluster_type=IN):
"""Get zigbee cluster from this entity."""
clusters = await self.get_clusters()
clusters = self.async_get_clusters()
return clusters[endpoint_id][cluster_type][cluster_id]

async def get_cluster_attributes(self, endpoint_id, cluster_id,
@callback
def async_get_cluster_attributes(self, endpoint_id, cluster_id,
cluster_type=IN):
"""Get zigbee attributes for specified cluster."""
cluster = await self.get_cluster(endpoint_id, cluster_id,
cluster = self.async_get_cluster(endpoint_id, cluster_id,
cluster_type)
if cluster is None:
return None
return cluster.attributes

async def get_cluster_commands(self, endpoint_id, cluster_id,
@callback
def async_get_cluster_commands(self, endpoint_id, cluster_id,
cluster_type=IN):
"""Get zigbee commands for specified cluster."""
cluster = await self.get_cluster(endpoint_id, cluster_id,
cluster_type)
cluster = self.async_get_cluster(endpoint_id, cluster_id, cluster_type)
if cluster is None:
return None
return {
Expand All @@ -269,8 +274,7 @@ async def write_zigbee_attribute(self, endpoint_id, cluster_id,
attribute, value, cluster_type=IN,
manufacturer=None):
"""Write a value to a zigbee attribute for a cluster in this entity."""
cluster = await self.get_cluster(
endpoint_id, cluster_id, cluster_type)
cluster = self.async_get_cluster(endpoint_id, cluster_id, cluster_type)
if cluster is None:
return None

Expand Down Expand Up @@ -304,8 +308,7 @@ async def issue_cluster_command(self, endpoint_id, cluster_id, command,
command_type, args, cluster_type=IN,
manufacturer=None):
"""Issue a command against specified zigbee cluster on this entity."""
cluster = await self.get_cluster(
endpoint_id, cluster_id, cluster_type)
cluster = self.async_get_cluster(endpoint_id, cluster_id, cluster_type)
if cluster is None:
return None
response = None
Expand Down
Loading