Add support for exposing light effects via Google Assistant (#38575)
* Don't set SUPPORT_EFFECT on DemoLight if there are no effects This requires an update to the group test - previously the other lights instantiated by the DemoLight component had nothing in ATTR_EFFECT_LIST, but still had SUPPORT_EFFECT set. This appears to have resulted in the light group test code setting an effect on the group and expecting it to apply to all lights, but given that two of the bulbs didn't actually support any effects (due to the empty ATTR_EFFECT_LIST) this seems like a broken assumption and updating the test to verify only the bulb that supports effects has had one applied seems reasonable. * Add support for exposing light effects via Google Assistant The LightEffects trait only supports a fixed (and small) list of lighting effects, but we can expose them via the Modes trait - this requires saying "Set (foo) effect to (bar)" which is a little clumsy, but at least makes it possible.
This commit is contained in:
1 parent
e304792f3a
commit
34e2a1825b
6 files changed
+208
-13
No files matched your search
@@ -515,6 +515,73 @@ async def test_color_light_temperature_light_bad_temp(hass):
|
||||
assert trt.query_attributes() == {}
|
||||
|
||||
|
||||
async def test_light_modes(hass):
|
||||
"""Test Light Mode trait."""
|
||||
assert helpers.get_google_type(light.DOMAIN, None) is not None
|
||||
assert trait.ModesTrait.supported(light.DOMAIN, light.SUPPORT_EFFECT, None)
|
||||
|
||||
trt = trait.ModesTrait(
|
||||
hass,
|
||||
State(
|
||||
"light.living_room",
|
||||
light.STATE_ON,
|
||||
attributes={
|
||||
light.ATTR_EFFECT_LIST: ["random", "colorloop"],
|
||||
light.ATTR_EFFECT: "random",
|
||||
},
|
||||
),
|
||||
BASIC_CONFIG,
|
||||
)
|
||||
|
||||
attribs = trt.sync_attributes()
|
||||
assert attribs == {
|
||||
"availableModes": [
|
||||
{
|
||||
"name": "effect",
|
||||
"name_values": [{"name_synonym": ["effect"], "lang": "en"}],
|
||||
"settings": [
|
||||
{
|
||||
"setting_name": "random",
|
||||
"setting_values": [
|
||||
{"setting_synonym": ["random"], "lang": "en"}
|
||||
],
|
||||
},
|
||||
{
|
||||
"setting_name": "colorloop",
|
||||
"setting_values": [
|
||||
{"setting_synonym": ["colorloop"], "lang": "en"}
|
||||
],
|
||||
},
|
||||
],
|
||||
"ordered": False,
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
assert trt.query_attributes() == {
|
||||
"currentModeSettings": {"effect": "random"},
|
||||
"on": True,
|
||||
}
|
||||
|
||||
assert trt.can_execute(
|
||||
trait.COMMAND_MODES, params={"updateModeSettings": {"effect": "colorloop"}},
|
||||
)
|
||||
|
||||
calls = async_mock_service(hass, light.DOMAIN, SERVICE_TURN_ON)
|
||||
await trt.execute(
|
||||
trait.COMMAND_MODES,
|
||||
BASIC_DATA,
|
||||
{"updateModeSettings": {"effect": "colorloop"}},
|
||||
{},
|
||||
)
|
||||
|
||||
assert len(calls) == 1
|
||||
assert calls[0].data == {
|
||||
"entity_id": "light.living_room",
|
||||
"effect": "colorloop",
|
||||
}
|
||||
|
||||
|
||||
async def test_scene_scene(hass):
|
||||
"""Test Scene trait support for scene domain."""
|
||||
assert helpers.get_google_type(scene.DOMAIN, None) is not None
|
||||
|
||||
Reference in new issue
Block a user