Allow multiple attribute reads in ZHA (#32498)
* multi attribute reads for lights * catch specific exceptions * get attributes * fix mains powered update * add guards and use get_attributes * use debug for read failures * cleanup * update return value for read_attributes * fix on with timed off
This commit is contained in:
parent
dd91b51435
commit
e52542c4d7
14 changed files with 136 additions and 78 deletions
|
@ -329,44 +329,59 @@ class Light(ZhaEntity, light.Light):
|
|||
"""Attempt to retrieve on off state from the light."""
|
||||
self.debug("polling current state")
|
||||
if self._on_off_channel:
|
||||
self._state = await self._on_off_channel.get_attribute_value(
|
||||
state = await self._on_off_channel.get_attribute_value(
|
||||
"on_off", from_cache=from_cache
|
||||
)
|
||||
if state is not None:
|
||||
self._state = state
|
||||
if self._level_channel:
|
||||
self._brightness = await self._level_channel.get_attribute_value(
|
||||
level = await self._level_channel.get_attribute_value(
|
||||
"current_level", from_cache=from_cache
|
||||
)
|
||||
if level is not None:
|
||||
self._brightness = level
|
||||
if self._color_channel:
|
||||
attributes = []
|
||||
color_capabilities = self._color_channel.get_color_capabilities()
|
||||
if (
|
||||
color_capabilities is not None
|
||||
and color_capabilities & CAPABILITIES_COLOR_TEMP
|
||||
):
|
||||
self._color_temp = await self._color_channel.get_attribute_value(
|
||||
"color_temperature", from_cache=from_cache
|
||||
)
|
||||
attributes.append("color_temperature")
|
||||
if (
|
||||
color_capabilities is not None
|
||||
and color_capabilities & CAPABILITIES_COLOR_XY
|
||||
):
|
||||
color_x = await self._color_channel.get_attribute_value(
|
||||
"current_x", from_cache=from_cache
|
||||
)
|
||||
color_y = await self._color_channel.get_attribute_value(
|
||||
"current_y", from_cache=from_cache
|
||||
)
|
||||
if color_x is not None and color_y is not None:
|
||||
self._hs_color = color_util.color_xy_to_hs(
|
||||
float(color_x / 65535), float(color_y / 65535)
|
||||
)
|
||||
attributes.append("current_x")
|
||||
attributes.append("current_y")
|
||||
if (
|
||||
color_capabilities is not None
|
||||
and color_capabilities & CAPABILITIES_COLOR_LOOP
|
||||
):
|
||||
color_loop_active = await self._color_channel.get_attribute_value(
|
||||
"color_loop_active", from_cache=from_cache
|
||||
attributes.append("color_loop_active")
|
||||
|
||||
results = await self._color_channel.get_attributes(
|
||||
attributes, from_cache=from_cache
|
||||
)
|
||||
|
||||
if (
|
||||
"color_temperature" in results
|
||||
and results["color_temperature"] is not None
|
||||
):
|
||||
self._color_temp = results["color_temperature"]
|
||||
|
||||
color_x = results.get("color_x", None)
|
||||
color_y = results.get("color_y", None)
|
||||
if color_x is not None and color_y is not None:
|
||||
self._hs_color = color_util.color_xy_to_hs(
|
||||
float(color_x / 65535), float(color_y / 65535)
|
||||
)
|
||||
if color_loop_active is not None and color_loop_active == 1:
|
||||
if (
|
||||
"color_loop_active" in results
|
||||
and results["color_loop_active"] is not None
|
||||
):
|
||||
color_loop_active = results["color_loop_active"]
|
||||
if color_loop_active == 1:
|
||||
self._effect = light.EFFECT_COLORLOOP
|
||||
|
||||
async def refresh(self, time):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue