1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-24 12:59:34 +00:00

Migrate hue v1 light to color_mode (#69275)

* Migrate hue v1 light to color_mode

* Fix test

* Correct filter_supported_color_modes + add test

* Use ColorMode enum
This commit is contained in:
Erik Montnemery
2022-04-28 09:49:51 +02:00
committed by GitHub
parent 59c6282c6c
commit 573e966d74
4 changed files with 147 additions and 15 deletions

View File

@@ -16,7 +16,7 @@ from homeassistant.const import (
STATE_OFF,
STATE_ON,
)
from homeassistant.exceptions import Unauthorized
from homeassistant.exceptions import HomeAssistantError, Unauthorized
from homeassistant.setup import async_setup_component
import homeassistant.util.color as color_util
@@ -2417,3 +2417,44 @@ def test_valid_supported_color_modes():
supported = {light.ColorMode.BRIGHTNESS, light.ColorMode.COLOR_TEMP}
with pytest.raises(vol.Error):
light.valid_supported_color_modes(supported)
def test_filter_supported_color_modes():
"""Test filter_supported_color_modes."""
supported = {light.ColorMode.HS}
assert light.filter_supported_color_modes(supported) == supported
# Supported color modes must not be empty
supported = set()
with pytest.raises(HomeAssistantError):
light.filter_supported_color_modes(supported)
# ColorMode.WHITE must be combined with a color mode supporting color
supported = {light.ColorMode.WHITE}
with pytest.raises(HomeAssistantError):
light.filter_supported_color_modes(supported)
supported = {light.ColorMode.WHITE, light.ColorMode.COLOR_TEMP}
with pytest.raises(HomeAssistantError):
light.filter_supported_color_modes(supported)
supported = {light.ColorMode.WHITE, light.ColorMode.HS}
assert light.filter_supported_color_modes(supported) == supported
# ColorMode.ONOFF will be removed if combined with other modes
supported = {light.ColorMode.ONOFF}
assert light.filter_supported_color_modes(supported) == supported
supported = {light.ColorMode.ONOFF, light.ColorMode.COLOR_TEMP}
assert light.filter_supported_color_modes(supported) == {light.ColorMode.COLOR_TEMP}
# ColorMode.BRIGHTNESS will be removed if combined with other modes
supported = {light.ColorMode.BRIGHTNESS}
assert light.filter_supported_color_modes(supported) == supported
supported = {light.ColorMode.BRIGHTNESS, light.ColorMode.COLOR_TEMP}
assert light.filter_supported_color_modes(supported) == {light.ColorMode.COLOR_TEMP}
# ColorMode.BRIGHTNESS has priority over ColorMode.ONOFF
supported = {light.ColorMode.ONOFF, light.ColorMode.BRIGHTNESS}
assert light.filter_supported_color_modes(supported) == {light.ColorMode.BRIGHTNESS}