From a66bb3411fc80dcff8ea3513bebd97dc33f95c58 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Sat, 23 Apr 2022 20:00:13 +0000 Subject: [PATCH 1/2] Use ColorMode enum in vesync --- homeassistant/components/vesync/light.py | 31 ++++++------------------ 1 file changed, 8 insertions(+), 23 deletions(-) diff --git a/homeassistant/components/vesync/light.py b/homeassistant/components/vesync/light.py index 7fd682e1943eec..9fa7eefa64f924 100644 --- a/homeassistant/components/vesync/light.py +++ b/homeassistant/components/vesync/light.py @@ -4,8 +4,7 @@ from homeassistant.components.light import ( ATTR_BRIGHTNESS, ATTR_COLOR_TEMP, - COLOR_MODE_BRIGHTNESS, - COLOR_MODE_COLOR_TEMP, + ColorMode, LightEntity, ) from homeassistant.config_entries import ConfigEntry @@ -88,7 +87,7 @@ def turn_on(self, **kwargs): """Turn the device on.""" attribute_adjustment_only = False # set white temperature - if self.color_mode in (COLOR_MODE_COLOR_TEMP,) and ATTR_COLOR_TEMP in kwargs: + if self.color_mode in (ColorMode.COLOR_TEMP,) and ATTR_COLOR_TEMP in kwargs: # get white temperature from HA data color_temp = int(kwargs[ATTR_COLOR_TEMP]) # ensure value between min-max supported Mireds @@ -108,7 +107,7 @@ def turn_on(self, **kwargs): attribute_adjustment_only = True # set brightness level if ( - self.color_mode in (COLOR_MODE_BRIGHTNESS, COLOR_MODE_COLOR_TEMP) + self.color_mode in (ColorMode.BRIGHTNESS, ColorMode.COLOR_TEMP) and ATTR_BRIGHTNESS in kwargs ): # get brightness from HA data @@ -133,20 +132,16 @@ def turn_on(self, **kwargs): class VeSyncDimmableLightHA(VeSyncBaseLight, LightEntity): """Representation of a VeSync dimmable light device.""" - @property - def color_mode(self): - """Set color mode for this entity.""" - return COLOR_MODE_BRIGHTNESS - - @property - def supported_color_modes(self): - """Flag supported color_modes (in an array format).""" - return [COLOR_MODE_BRIGHTNESS] + _attr_color_mode = ColorMode.BRIGHTNESS + _attr_supported_color_modes = {ColorMode.BRIGHTNESS} class VeSyncTunableWhiteLightHA(VeSyncBaseLight, LightEntity): """Representation of a VeSync Tunable White Light device.""" + _attr_color_mode = ColorMode.COLOR_TEMP + _attr_supported_color_modes = {ColorMode.COLOR_TEMP} + @property def color_temp(self): """Get device white temperature.""" @@ -183,13 +178,3 @@ def min_mireds(self): def max_mireds(self): """Set device warmest white temperature.""" return 370 # 370 Mireds ( 1,000,000 divided by 2700 Kelvin = 370 Mireds) - - @property - def color_mode(self): - """Set color mode for this entity.""" - return COLOR_MODE_COLOR_TEMP - - @property - def supported_color_modes(self): - """Flag supported color_modes (in an array format).""" - return [COLOR_MODE_COLOR_TEMP] From 4f6f7bce7feaf0c8dcfd04bd935d981165d05086 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Sat, 23 Apr 2022 20:32:09 +0000 Subject: [PATCH 2/2] Use == --- homeassistant/components/vesync/light.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/components/vesync/light.py b/homeassistant/components/vesync/light.py index 9fa7eefa64f924..d01319ff0e765f 100644 --- a/homeassistant/components/vesync/light.py +++ b/homeassistant/components/vesync/light.py @@ -87,7 +87,7 @@ def turn_on(self, **kwargs): """Turn the device on.""" attribute_adjustment_only = False # set white temperature - if self.color_mode in (ColorMode.COLOR_TEMP,) and ATTR_COLOR_TEMP in kwargs: + if self.color_mode == ColorMode.COLOR_TEMP and ATTR_COLOR_TEMP in kwargs: # get white temperature from HA data color_temp = int(kwargs[ATTR_COLOR_TEMP]) # ensure value between min-max supported Mireds