mirror of
https://github.com/python-kasa/python-kasa.git
synced 2025-08-06 10:44:04 +00:00
Add LightEffect module for smart light strips (#918)
Implements the `light_strip_lighting_effect` components for `smart` devices. Uses a new list of effects captured from a L900 which are similar to the `iot` effects but include some additional properties and a few extra effects. Assumes that a device only implements `light_strip_lighting_effect` or `light_effect` but not both.
This commit is contained in:
@@ -176,7 +176,7 @@ class FakeSmartTransport(BaseTransport):
|
||||
"Method %s not implemented for children" % child_method
|
||||
)
|
||||
|
||||
def _set_light_effect(self, info, params):
|
||||
def _set_dynamic_light_effect(self, info, params):
|
||||
"""Set or remove values as per the device behaviour."""
|
||||
info["get_device_info"]["dynamic_light_effect_enable"] = params["enable"]
|
||||
info["get_dynamic_light_effect_rules"]["enable"] = params["enable"]
|
||||
@@ -189,6 +189,13 @@ class FakeSmartTransport(BaseTransport):
|
||||
if "current_rule_id" in info["get_dynamic_light_effect_rules"]:
|
||||
del info["get_dynamic_light_effect_rules"]["current_rule_id"]
|
||||
|
||||
def _set_light_strip_effect(self, info, params):
|
||||
"""Set or remove values as per the device behaviour."""
|
||||
info["get_device_info"]["lighting_effect"]["enable"] = params["enable"]
|
||||
info["get_device_info"]["lighting_effect"]["name"] = params["name"]
|
||||
info["get_device_info"]["lighting_effect"]["id"] = params["id"]
|
||||
info["get_lighting_effect"] = copy.deepcopy(params)
|
||||
|
||||
def _set_led_info(self, info, params):
|
||||
"""Set or remove values as per the device behaviour."""
|
||||
info["get_led_info"]["led_status"] = params["led_rule"] != "never"
|
||||
@@ -244,7 +251,10 @@ class FakeSmartTransport(BaseTransport):
|
||||
elif method in ["set_qs_info", "fw_download"]:
|
||||
return {"error_code": 0}
|
||||
elif method == "set_dynamic_light_effect_rule_enable":
|
||||
self._set_light_effect(info, params)
|
||||
self._set_dynamic_light_effect(info, params)
|
||||
return {"error_code": 0}
|
||||
elif method == "set_lighting_effect":
|
||||
self._set_light_strip_effect(info, params)
|
||||
return {"error_code": 0}
|
||||
elif method == "set_led_info":
|
||||
self._set_led_info(info, params)
|
||||
|
@@ -390,12 +390,8 @@ async def test_light_effect(dev: Device, runner: CliRunner):
|
||||
assert light_effect.effect == light_effect.LIGHT_EFFECTS_OFF
|
||||
|
||||
res = await runner.invoke(effect, obj=dev)
|
||||
msg = (
|
||||
"Setting an effect requires a named built-in effect: "
|
||||
+ f"{light_effect.effect_list}"
|
||||
)
|
||||
assert msg in res.output
|
||||
assert res.exit_code == 2
|
||||
assert f"Light effect: {light_effect.effect}" in res.output
|
||||
assert res.exit_code == 0
|
||||
|
||||
res = await runner.invoke(effect, [light_effect.effect_list[1]], obj=dev)
|
||||
assert f"Setting Effect: {light_effect.effect_list[1]}" in res.output
|
||||
|
@@ -19,7 +19,14 @@ led = parametrize_combine([led_smart, plug_iot])
|
||||
light_effect_smart = parametrize(
|
||||
"has light effect smart", component_filter="light_effect", protocol_filter={"SMART"}
|
||||
)
|
||||
light_effect = parametrize_combine([light_effect_smart, lightstrip_iot])
|
||||
light_strip_effect_smart = parametrize(
|
||||
"has light strip effect smart",
|
||||
component_filter="light_strip_lighting_effect",
|
||||
protocol_filter={"SMART"},
|
||||
)
|
||||
light_effect = parametrize_combine(
|
||||
[light_effect_smart, light_strip_effect_smart, lightstrip_iot]
|
||||
)
|
||||
|
||||
dimmable_smart = parametrize(
|
||||
"dimmable smart", component_filter="brightness", protocol_filter={"SMART"}
|
||||
|
Reference in New Issue
Block a user