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
https://github.com/python-kasa/python-kasa/pull/1043 to fix
https://github.com/python-kasa/python-kasa/issues/1040, [HA
#121115](https://github.com/home-assistant/core/issues/121115) and [HA
#121119](https://github.com/home-assistant/core/issues/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!
This commit is contained in:
Steven B 2024-07-04 16:22:47 +01:00 committed by GitHub
parent 983aacbc24
commit 7888f4904a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 777 additions and 117 deletions

View File

@ -2,6 +2,7 @@
from __future__ import annotations
import logging
from collections.abc import Sequence
from dataclasses import asdict
from typing import TYPE_CHECKING
@ -13,6 +14,8 @@ from ..smartmodule import SmartModule
if TYPE_CHECKING:
from ..smartdevice import SmartDevice
_LOGGER = logging.getLogger(__name__)
class LightPreset(SmartModule, LightPresetInterface):
"""Implementation of light presets."""
@ -38,6 +41,14 @@ class LightPreset(SmartModule, LightPresetInterface):
state_key = "states" if not self._state_in_sysinfo else self.SYS_INFO_STATE_KEY
if preset_states := self.data.get(state_key):
for preset_state in preset_states:
if "brightness" not in preset_state:
# Some devices can store effects as a preset. These will be ignored
# and handled in the effects module
if "lighting_effect" not in preset_state:
_LOGGER.info(
"Unexpected keys %s in preset", list(preset_state.keys())
)
continue
color_temp = preset_state.get("color_temp")
hue = preset_state.get("hue")
saturation = preset_state.get("saturation")

File diff suppressed because it is too large Load Diff