mirror of
https://github.com/python-kasa/python-kasa.git
synced 2025-04-26 16:46:23 +00:00
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:
parent
983aacbc24
commit
7888f4904a
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import logging
|
||||||
from collections.abc import Sequence
|
from collections.abc import Sequence
|
||||||
from dataclasses import asdict
|
from dataclasses import asdict
|
||||||
from typing import TYPE_CHECKING
|
from typing import TYPE_CHECKING
|
||||||
@ -13,6 +14,8 @@ from ..smartmodule import SmartModule
|
|||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from ..smartdevice import SmartDevice
|
from ..smartdevice import SmartDevice
|
||||||
|
|
||||||
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class LightPreset(SmartModule, LightPresetInterface):
|
class LightPreset(SmartModule, LightPresetInterface):
|
||||||
"""Implementation of light presets."""
|
"""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
|
state_key = "states" if not self._state_in_sysinfo else self.SYS_INFO_STATE_KEY
|
||||||
if preset_states := self.data.get(state_key):
|
if preset_states := self.data.get(state_key):
|
||||||
for preset_state in preset_states:
|
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")
|
color_temp = preset_state.get("color_temp")
|
||||||
hue = preset_state.get("hue")
|
hue = preset_state.get("hue")
|
||||||
saturation = preset_state.get("saturation")
|
saturation = preset_state.get("saturation")
|
||||||
|
883
kasa/tests/fixtures/smart/L920-5(EU)_1.0_1.1.3.json
vendored
883
kasa/tests/fixtures/smart/L920-5(EU)_1.0_1.1.3.json
vendored
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user