Implement color mode for ZHA light polling (#44829)

This commit is contained in:
TheJulianJES 2021-01-05 03:57:05 +01:00 committed by GitHub
parent 65e56d03bf
commit 86154744e4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,6 +1,7 @@
"""Lights on Zigbee Home Automation networks.""" """Lights on Zigbee Home Automation networks."""
from collections import Counter from collections import Counter
from datetime import timedelta from datetime import timedelta
import enum
import functools import functools
import itertools import itertools
import logging import logging
@ -88,6 +89,14 @@ SUPPORT_GROUP_LIGHT = (
) )
class LightColorMode(enum.IntEnum):
"""ZCL light color mode enum."""
HS_COLOR = 0x00
XY_COLOR = 0x01
COLOR_TEMP = 0x02
async def async_setup_entry(hass, config_entry, async_add_entities): async def async_setup_entry(hass, config_entry, async_add_entities):
"""Set up the Zigbee Home Automation light from config entry.""" """Set up the Zigbee Home Automation light from config entry."""
entities_to_create = hass.data[DATA_ZHA][light.DOMAIN] entities_to_create = hass.data[DATA_ZHA][light.DOMAIN]
@ -442,6 +451,7 @@ class Light(BaseLight, ZhaEntity):
self._brightness = level self._brightness = level
if self._color_channel: if self._color_channel:
attributes = [ attributes = [
"color_mode",
"color_temperature", "color_temperature",
"current_x", "current_x",
"current_y", "current_y",
@ -452,16 +462,21 @@ class Light(BaseLight, ZhaEntity):
attributes, from_cache=False attributes, from_cache=False
) )
color_mode = results.get("color_mode")
if color_mode is not None:
if color_mode == LightColorMode.COLOR_TEMP:
color_temp = results.get("color_temperature") color_temp = results.get("color_temperature")
if color_temp is not None: if color_temp is not None and color_mode:
self._color_temp = color_temp self._color_temp = color_temp
self._hs_color = None
else:
color_x = results.get("current_x") color_x = results.get("current_x")
color_y = results.get("current_y") color_y = results.get("current_y")
if color_x is not None and color_y is not None: if color_x is not None and color_y is not None:
self._hs_color = color_util.color_xy_to_hs( self._hs_color = color_util.color_xy_to_hs(
float(color_x / 65535), float(color_y / 65535) float(color_x / 65535), float(color_y / 65535)
) )
self._color_temp = None
color_loop_active = results.get("color_loop_active") color_loop_active = results.get("color_loop_active")
if color_loop_active is not None: if color_loop_active is not None: