Use ColorMode enum in homekit (#70581)

This commit is contained in:
epenet 2022-04-24 12:30:08 +02:00 committed by GitHub
parent f902aed6b3
commit 4830b427ac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -18,10 +18,8 @@ from homeassistant.components.light import (
ATTR_RGBWW_COLOR, ATTR_RGBWW_COLOR,
ATTR_SUPPORTED_COLOR_MODES, ATTR_SUPPORTED_COLOR_MODES,
ATTR_WHITE, ATTR_WHITE,
COLOR_MODE_RGBW,
COLOR_MODE_RGBWW,
COLOR_MODE_WHITE,
DOMAIN, DOMAIN,
ColorMode,
brightness_supported, brightness_supported,
color_supported, color_supported,
color_temp_supported, color_temp_supported,
@ -60,7 +58,7 @@ CHANGE_COALESCE_TIME_WINDOW = 0.01
DEFAULT_MIN_MIREDS = 153 DEFAULT_MIN_MIREDS = 153
DEFAULT_MAX_MIREDS = 500 DEFAULT_MAX_MIREDS = 500
COLOR_MODES_WITH_WHITES = {COLOR_MODE_RGBW, COLOR_MODE_RGBWW, COLOR_MODE_WHITE} COLOR_MODES_WITH_WHITES = {ColorMode.RGBW, ColorMode.RGBWW, ColorMode.WHITE}
@TYPES.register("Light") @TYPES.register("Light")
@ -86,9 +84,9 @@ class Light(HomeAccessory):
self._previous_color_mode = attributes.get(ATTR_COLOR_MODE) self._previous_color_mode = attributes.get(ATTR_COLOR_MODE)
self.color_supported = color_supported(color_modes) self.color_supported = color_supported(color_modes)
self.color_temp_supported = color_temp_supported(color_modes) self.color_temp_supported = color_temp_supported(color_modes)
self.rgbw_supported = COLOR_MODE_RGBW in color_modes self.rgbw_supported = ColorMode.RGBW in color_modes
self.rgbww_supported = COLOR_MODE_RGBWW in color_modes self.rgbww_supported = ColorMode.RGBWW in color_modes
self.white_supported = COLOR_MODE_WHITE in color_modes self.white_supported = ColorMode.WHITE in color_modes
self.brightness_supported = brightness_supported(color_modes) self.brightness_supported = brightness_supported(color_modes)
if self.brightness_supported: if self.brightness_supported:
@ -264,7 +262,7 @@ class Light(HomeAccessory):
hue, saturation = color_temperature_to_hs( hue, saturation = color_temperature_to_hs(
color_temperature_mired_to_kelvin(color_temp) color_temperature_mired_to_kelvin(color_temp)
) )
elif color_mode == COLOR_MODE_WHITE: elif color_mode == ColorMode.WHITE:
hue, saturation = 0, 0 hue, saturation = 0, 0
else: else:
hue, saturation = attributes.get(ATTR_HS_COLOR, (None, None)) hue, saturation = attributes.get(ATTR_HS_COLOR, (None, None))
@ -281,7 +279,7 @@ class Light(HomeAccessory):
color_temp = None color_temp = None
if self.color_temp_supported: if self.color_temp_supported:
color_temp = attributes.get(ATTR_COLOR_TEMP) color_temp = attributes.get(ATTR_COLOR_TEMP)
elif color_mode == COLOR_MODE_WHITE: elif color_mode == ColorMode.WHITE:
color_temp = self.min_mireds color_temp = self.min_mireds
if isinstance(color_temp, (int, float)): if isinstance(color_temp, (int, float)):
self.char_color_temp.set_value(round(color_temp, 0)) self.char_color_temp.set_value(round(color_temp, 0))