44
55import logging
66import re
7+ from dataclasses import dataclass
78from enum import Enum
8- from typing import cast
9+ from typing import Annotated , cast
910
10- from pydantic .v1 import BaseModel , Field , root_validator
11+ from mashumaro import DataClassDictMixin
12+ from mashumaro .config import BaseConfig
13+ from mashumaro .types import Alias
1114
1215from ..device_type import DeviceType
1316from ..deviceconfig import DeviceConfig
@@ -35,9 +38,12 @@ class BehaviorMode(str, Enum):
3538 Last = "last_status"
3639 #: Use chosen preset.
3740 Preset = "customize_preset"
41+ #: Circadian
42+ Circadian = "circadian"
3843
3944
40- class TurnOnBehavior (BaseModel ):
45+ @dataclass
46+ class TurnOnBehavior (DataClassDictMixin ):
4147 """Model to present a single turn on behavior.
4248
4349 :param int preset: the index number of wanted preset.
@@ -48,34 +54,30 @@ class TurnOnBehavior(BaseModel):
4854 to contain either the preset index, or ``None`` for the last known state.
4955 """
5056
51- #: Index of preset to use, or ``None`` for the last known state.
52- preset : int | None = Field (alias = "index" , default = None )
53- #: Wanted behavior
54- mode : BehaviorMode
55-
56- @root_validator
57- def _mode_based_on_preset (cls , values : dict ) -> dict :
58- """Set the mode based on the preset value."""
59- if values ["preset" ] is not None :
60- values ["mode" ] = BehaviorMode .Preset
61- else :
62- values ["mode" ] = BehaviorMode .Last
57+ class Config (BaseConfig ):
58+ """Serialization config."""
6359
64- return values
60+ omit_none = True
61+ serialize_by_alias = True
6562
66- class Config :
67- """Configuration to make the validator run when changing the values."""
68-
69- validate_assignment = True
63+ #: Wanted behavior
64+ mode : BehaviorMode
65+ #: Index of preset to use, or ``None`` for the last known state.
66+ preset : Annotated [int | None , Alias ("index" )] = None
67+ brightness : int | None = None
68+ color_temp : int | None = None
69+ hue : int | None = None
70+ saturation : int | None = None
7071
7172
72- class TurnOnBehaviors (BaseModel ):
73+ @dataclass
74+ class TurnOnBehaviors (DataClassDictMixin ):
7375 """Model to contain turn on behaviors."""
7476
7577 #: The behavior when the bulb is turned on programmatically.
76- soft : TurnOnBehavior = Field ( alias = "soft_on" )
78+ soft : Annotated [ TurnOnBehavior , Alias ( "soft_on" )]
7779 #: The behavior when the bulb has been off from mains power.
78- hard : TurnOnBehavior = Field ( alias = "hard_on" )
80+ hard : Annotated [ TurnOnBehavior , Alias ( "hard_on" )]
7981
8082
8183TPLINK_KELVIN = {
@@ -303,7 +305,7 @@ async def get_light_details(self) -> dict[str, int]:
303305
304306 async def get_turn_on_behavior (self ) -> TurnOnBehaviors :
305307 """Return the behavior for turning the bulb on."""
306- return TurnOnBehaviors .parse_obj (
308+ return TurnOnBehaviors .from_dict (
307309 await self ._query_helper (self .LIGHT_SERVICE , "get_default_behavior" )
308310 )
309311
@@ -314,7 +316,7 @@ async def set_turn_on_behavior(self, behavior: TurnOnBehaviors) -> dict:
314316 you should use :func:`get_turn_on_behavior` to get the current settings.
315317 """
316318 return await self ._query_helper (
317- self .LIGHT_SERVICE , "set_default_behavior" , behavior .dict ( by_alias = True )
319+ self .LIGHT_SERVICE , "set_default_behavior" , behavior .to_dict ( )
318320 )
319321
320322 async def get_light_state (self ) -> dict [str , dict ]:
0 commit comments