8000 Fix light preset module when list contains lighting effects (#1048) · python-kasa/python-kasa@7888f49 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7888f49

Browse files
authored
Fix light preset module when list contains lighting effects (#1048)
Fixes the residual issues with the light preset module not handling unexpected `lighting_effect` items in the presets list. Completes the fixes started with PR #1043 to fix #1040, [HA #121115](home-assistant/core#121115) and [HA #121119](home-assistant/core#121119) With this PR affected devices will no longer have the light preset functionality disabled. As this is a new feature this does not warrant a hotfix so will go into the next release. Updated fixture for testing thanks to @szssamuel, many thanks!
1 parent 983aacb commit 7888f49

File tree

2 files changed

+767
-107
lines changed

2 files changed

+767
-107
lines changed

kasa/smart/modules/lightpreset.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from __future__ import annotations
44

5+
import logging
56
from collections.abc import Sequence
67
from dataclasses import asdict
78
from typing import TYPE_CHECKING
@@ -13,6 +14,8 @@
1314
if TYPE_CHECKING:
1415
from ..smartdevice import SmartDevice
1516

17+
_LOGGER = logging.getLogger(__name__)
18+
1619

1720
class LightPreset(SmartModule, LightPresetInterface):
1821
"""Implementation of light presets."""
@@ -38,6 +41,14 @@ def _post_update_hook(self):
3841
state_key = "states" if not self._state_in_sysinfo else self.SYS_INFO_STATE_KEY
3942
if preset_states := self.data.get(state_key):
4043
for preset_state in preset_states:
44+
if "brightness" not in preset_state:
45+
# Some devices can store effects as a preset. These will be ignored
46+
# and handled in the effects module
47+
if "lighting_effect" not in preset_state:
48+
_LOGGER.info(
49+
"Unexpected keys %s in preset", list(preset_state.keys())
50+
)
51+
continue
4152
color_temp = preset_state.get("color_temp")
4253
hue = preset_state.get("hue")
4354
saturation = preset_state.get("saturation")

0 commit comments

Comments
 (0)
0