Skip to content

Commit

Permalink
Add LightEffect module for smart light strips (#918)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
sdb9696 committed May 15, 2024
1 parent 67b5d7d commit 133a839
Show file tree
Hide file tree
Showing 8 changed files with 572 additions and 19 deletions.
9 changes: 5 additions & 4 deletions kasa/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -911,11 +911,12 @@ async def effect(dev: Device, ctx, effect):
echo("Device does not support effects")
return
if effect is None:
raise click.BadArgumentUsage(
"Setting an effect requires a named built-in effect: "
+ f"{light_effect.effect_list}",
ctx,
echo(
f"Light effect: {light_effect.effect}\n"
+ f"Available Effects: {light_effect.effect_list}"
)
return light_effect.effect

if effect not in light_effect.effect_list:
raise click.BadArgumentUsage(
f"Effect must be one of: {light_effect.effect_list}", ctx
Expand Down
11 changes: 5 additions & 6 deletions kasa/iot/modules/lighteffect.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,11 @@ def effect(self) -> str:
'id': '',
'name': ''}
"""
if (
(state := self.data.get("lighting_effect_state"))
and state.get("enable")
and (name := state.get("name"))
and name in EFFECT_NAMES_V1
):
eff = self.data["lighting_effect_state"]
name = eff["name"]
if eff["enable"]:
return name

return self.LIGHT_EFFECTS_OFF

@property
Expand Down Expand Up @@ -67,6 +65,7 @@ async def set_effect(
raise ValueError(f"The effect {effect} is not a built in effect.")
else:
effect_dict = EFFECT_MAPPING_V1[effect]

if brightness is not None:
effect_dict["brightness"] = brightness
if transition is not None:
Expand Down

0 comments on commit 133a839

Please sign in to comment.