Use supported_color_modes in alexa (#49174)
parent
e0ac12bd56
commit
1230c46e1e
|
@ -504,12 +504,12 @@ class LightCapabilities(AlexaEntity):
|
|||
"""Yield the supported interfaces."""
|
||||
yield AlexaPowerController(self.entity)
|
||||
|
||||
supported = self.entity.attributes.get(ATTR_SUPPORTED_FEATURES, 0)
|
||||
if supported & light.SUPPORT_BRIGHTNESS:
|
||||
color_modes = self.entity.attributes.get(light.ATTR_SUPPORTED_COLOR_MODES, [])
|
||||
if any(mode in color_modes for mode in light.COLOR_MODES_BRIGHTNESS):
|
||||
yield AlexaBrightnessController(self.entity)
|
||||
if supported & light.SUPPORT_COLOR:
|
||||
if any(mode in color_modes for mode in light.COLOR_MODES_COLOR):
|
||||
yield AlexaColorController(self.entity)
|
||||
if supported & light.SUPPORT_COLOR_TEMP:
|
||||
if light.COLOR_MODE_COLOR_TEMP in color_modes:
|
||||
yield AlexaColorTemperatureController(self.entity)
|
||||
|
||||
yield AlexaEndpointHealth(self.hass, self.entity)
|
||||
|
|
|
@ -239,17 +239,27 @@ async def test_report_lock_state(hass):
|
|||
properties.assert_equal("Alexa.LockController", "lockState", "JAMMED")
|
||||
|
||||
|
||||
async def test_report_dimmable_light_state(hass):
|
||||
@pytest.mark.parametrize(
|
||||
"supported_color_modes", [["brightness"], ["hs"], ["color_temp"]]
|
||||
)
|
||||
async def test_report_dimmable_light_state(hass, supported_color_modes):
|
||||
"""Test BrightnessController reports brightness correctly."""
|
||||
hass.states.async_set(
|
||||
"light.test_on",
|
||||
"on",
|
||||
{"friendly_name": "Test light On", "brightness": 128, "supported_features": 1},
|
||||
{
|
||||
"friendly_name": "Test light On",
|
||||
"brightness": 128,
|
||||
"supported_color_modes": supported_color_modes,
|
||||
},
|
||||
)
|
||||
hass.states.async_set(
|
||||
"light.test_off",
|
||||
"off",
|
||||
{"friendly_name": "Test light Off", "supported_features": 1},
|
||||
{
|
||||
"friendly_name": "Test light Off",
|
||||
"supported_color_modes": supported_color_modes,
|
||||
},
|
||||
)
|
||||
|
||||
properties = await reported_properties(hass, "light.test_on")
|
||||
|
@ -259,7 +269,8 @@ async def test_report_dimmable_light_state(hass):
|
|||
properties.assert_equal("Alexa.BrightnessController", "brightness", 0)
|
||||
|
||||
|
||||
async def test_report_colored_light_state(hass):
|
||||
@pytest.mark.parametrize("supported_color_modes", [["hs"], ["rgb"], ["xy"]])
|
||||
async def test_report_colored_light_state(hass, supported_color_modes):
|
||||
"""Test ColorController reports color correctly."""
|
||||
hass.states.async_set(
|
||||
"light.test_on",
|
||||
|
@ -268,13 +279,16 @@ async def test_report_colored_light_state(hass):
|
|||
"friendly_name": "Test light On",
|
||||
"hs_color": (180, 75),
|
||||
"brightness": 128,
|
||||
"supported_features": 17,
|
||||
"supported_color_modes": supported_color_modes,
|
||||
},
|
||||
)
|
||||
hass.states.async_set(
|
||||
"light.test_off",
|
||||
"off",
|
||||
{"friendly_name": "Test light Off", "supported_features": 17},
|
||||
{
|
||||
"friendly_name": "Test light Off",
|
||||
"supported_color_modes": supported_color_modes,
|
||||
},
|
||||
)
|
||||
|
||||
properties = await reported_properties(hass, "light.test_on")
|
||||
|
@ -295,12 +309,16 @@ async def test_report_colored_temp_light_state(hass):
|
|||
hass.states.async_set(
|
||||
"light.test_on",
|
||||
"on",
|
||||
{"friendly_name": "Test light On", "color_temp": 240, "supported_features": 2},
|
||||
{
|
||||
"friendly_name": "Test light On",
|
||||
"color_temp": 240,
|
||||
"supported_color_modes": ["color_temp"],
|
||||
},
|
||||
)
|
||||
hass.states.async_set(
|
||||
"light.test_off",
|
||||
"off",
|
||||
{"friendly_name": "Test light Off", "supported_features": 2},
|
||||
{"friendly_name": "Test light Off", "supported_color_modes": ["color_temp"]},
|
||||
)
|
||||
|
||||
properties = await reported_properties(hass, "light.test_on")
|
||||
|
|
|
@ -231,7 +231,11 @@ async def test_dimmable_light(hass):
|
|||
device = (
|
||||
"light.test_2",
|
||||
"on",
|
||||
{"brightness": 128, "friendly_name": "Test light 2", "supported_features": 1},
|
||||
{
|
||||
"brightness": 128,
|
||||
"friendly_name": "Test light 2",
|
||||
"supported_color_modes": ["brightness"],
|
||||
},
|
||||
)
|
||||
appliance = await discovery_test(device, hass)
|
||||
|
||||
|
@ -262,14 +266,18 @@ async def test_dimmable_light(hass):
|
|||
assert call.data["brightness_pct"] == 50
|
||||
|
||||
|
||||
async def test_color_light(hass):
|
||||
@pytest.mark.parametrize(
|
||||
"supported_color_modes",
|
||||
[["color_temp", "hs"], ["color_temp", "rgb"], ["color_temp", "xy"]],
|
||||
)
|
||||
async def test_color_light(hass, supported_color_modes):
|
||||
"""Test color light discovery."""
|
||||
device = (
|
||||
"light.test_3",
|
||||
"on",
|
||||
{
|
||||
"friendly_name": "Test light 3",
|
||||
"supported_features": 19,
|
||||
"supported_color_modes": supported_color_modes,
|
||||
"min_mireds": 142,
|
||||
"color_temp": "333",
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue