Skip to content

Commit

Permalink
Fix DIY modes for TX Ultimate #1424
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexxIT committed Sep 8, 2024
1 parent cea6f75 commit 1c8862f
Showing 1 changed file with 19 additions and 17 deletions.
36 changes: 19 additions & 17 deletions custom_components/sonoff/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -1145,40 +1145,42 @@ async def async_turn_off(self, **kwargs) -> None:
await self.ewelink.send(self.device, {"lightswitch": 0})


T5_EFFECTS = {
"Night Light": 0,
"Party": 1,
"Leisure": 2,
"Color": 3,
"Childhood": 4,
"Wiper": 5,
"Fairy": 6,
"Starburst": 7,
"DIY 1": 101,
"DIY 2": 102,
}


class XT5Light(XOnOffLight):
params = {"lightSwitch", "lightMode"}

_attr_effect_list = [
"Night Light",
"Party",
"Leisure",
"Color",
"Childhood",
"Wiper",
"Fairy",
"Starburst",
"DIY 1",
"DIY 2",
]
_attr_effect_list = list(T5_EFFECTS.keys())
_attr_supported_features = LightEntityFeature.EFFECT

def set_state(self, params: dict):
if "lightSwitch" in params:
self._attr_is_on = params["lightSwitch"] == "on"

if "lightMode" in params:
i = int(params["lightMode"])
self._attr_effect = (
self._attr_effect_list[i] if i < len(self._attr_effect_list) else None
self._attr_effect = next(
(k for k, v in T5_EFFECTS.items() if v == params["lightMode"]), None
)

async def async_turn_on(
self, brightness: int = None, effect: str = None, **kwargs
) -> None:
params = {}

if effect:
params["lightMode"] = self._attr_effect_list.index(effect)
if effect and effect in T5_EFFECTS:
params["lightMode"] = T5_EFFECTS[effect]

if not params:
params["lightSwitch"] = "on"
Expand Down

0 comments on commit 1c8862f

Please sign in to comment.