FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Make mypy happy · python-kasa/python-kasa@842528e · GitHub

Repository navigation

Commit 842528e

Browse files
committed
Make mypy happy
1 parent 1281147 commit 842528e

1 file changed

Lines changed: 80 additions & 24 deletions

File tree

‎kasa/tapo/tapobulb.py‎

Lines changed: 80 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
1+
"""Module for tapo-branded smart bulbs (L5**)."""
12
from typing import Dict, List, Optional
23

4+
from ..exceptions import SmartDeviceException
35
from ..smartbulb import HSV, ColorTempRange, SmartBulb, SmartBulbPreset
46
from .tapodevice import TapoDevice
57

68
AVAILABLE_EFFECTS = {
7-
'L1': "Party",
9+
"L1": "Party",
810
"L2": "Relax",
911
}
1012

11-
class TapoBulb(TapoDevice, SmartBulb):
1213

14+
class TapoBulb(TapoDevice, SmartBulb):
1315
@property
1416
def is_color(self) -> bool:
1517
# TODO: this makes an assumption that only color bulbs report this
@@ -27,11 +29,16 @@ def is_variable_color_temp(self) -> bool:
2729

2830
@property
2931
def valid_temperature_range(self) -> ColorTempRange:
30-
ct_range = self._info.get("color_temp_range")
32+
"""Return the device-specific white temperature range (in Kelvin).
33+
34+
:return: White temperature range in Kelvin (minimum, maximum)
35+
"""
36+
ct_range = self._info.get("color_temp_range", [0, 0])
3137
return ColorTempRange(min=ct_range[0], max=ct_range[1])
3238

3339
@property
3440
def has_effects(self) -> bool:
41+
"""Return True if the device supports effects."""
3542
return "dynamic_light_effect_enable" in self._info
3643

3744
@property
@@ -65,40 +72,83 @@ def effect_list(self) -> Optional[List[str]]:
6572
Example:
6673
['Party', 'Relax', ...]
6774
"""
68-
return AVAILABLE_EFFECTS.keys() if self.has_effects else None
69-
75+
return list(AVAILABLE_EFFECTS.keys()) if self.has_effects else None
7076

7177
@property
7278
def hsv(self) -> HSV:
73-
h, s, v = self._info.get("hue"), self._info.get("saturation"), self._info.get("brightness")
79+
"""Return the current HSV state of the bulb.
80+
81+
:return: hue, saturation and value (degrees, %, %)
82+
"""
83+
if not self.is_color:
84+
raise SmartDeviceException("Bulb does not support color.")
85+
86+
h, s, v = (
87+
self._info.get("hue", 0),
88+
self._info.get("saturation", 0),
89+
self._info.get("brightness", 0),
90+
)
7491

7592
return HSV(hue=h, saturation=s, value=v)
7693

7794
@property
7895
def color_temp(self) -> int:
79-
return self._info.get("color_temp")
96+
"""Whether the bulb supports color temperature changes."""
97+
if not self.is_variable_color_temp:
98+
raise SmartDeviceException("Bulb does not support colortemp.")
99+
100+
return self._info.get("color_temp", -1)
80101

81102
@property
82103
def brightness(self) -> int:
83-
return self._info.get("brightness")
104+
"""Return the current brightness in percentage."""
105+
if not self.is_dimmable: # pragma: no cover
106+
raise SmartDeviceException("Bulb is not dimmable.")
84107

85-
async def set_hsv(self, hue: int, saturation: int, value: Optional[int] = None, *,
86-
transition: Optional[int] = None) -> Dict:
87-
return await self.protocol.query({"set_device_info": {
88-
"hue": hue,
89-
"saturation": saturation,
90-
"brightness": value,
91-
}})
108+
return self._info.get("brightness", -1)
92109

93-
async def set_color_temp(self, temp: int, *, brightness=None, transition: Optional[int] = None) -> Dict:
110+
async def set_hsv(
111+
self,
112+
hue: int,
113+
saturation: int,
114+
value: Optional[int] = None,
115+
*,
116+
transition: Optional[int] = None,
117+
) -> Dict:
118+
if not self.is_color:
119+
raise SmartDeviceException("Bulb does not support color.")
120+
121+
return await self.protocol.query(
122+
{
123+
"set_device_info": {
124+
"hue": hue,
125+
"saturation": saturation,
126+
"brightness": value,
127+
}
128+
}
129+
)
130+
131+
async def set_color_temp(
132+
self, temp: int, *, brightness=None, transition: Optional[int] = None
133+
) -> Dict:
94134
# TODO: Decide how to handle brightness and transition
95-
# TODO: Note, trying to set brightness at the same time with color_temp causes error -1008
96-
return await self.protocol.query({"set_device_info": {"color_temp": temp}})
135+
# TODO: Note, trying to set brightness at the same time
136+
# with color_temp causes error -1008
137+
if not self.is_variable_color_temp:
138+
raise SmartDeviceException("Bulb does not support colortemp.")
97139

140+
return await self.protocol.query({"set_device_info": {"color_temp": temp}})
98141

99-
async def set_brightness(self, brightness: int, *, transition: Optional[int] = None) -> Dict:
142+
async def set_brightness(
143+
self, brightness: int, *, transition: Optional[int] = None
144+
) -> Dict:
100145
# TODO: Decide how to handle transitions
101-
return await self.protocol.query({"set_device_info": {"brightness": brightness}})
146+
if not self.is_dimmable: # pragma: no cover
147+
raise SmartDeviceException("Bulb is not dimmable.")
148+
149+
return await self.protocol.query(
150+
{"set_device_info": {"brightness": brightness}}
151+
)
102152

103153
# Default state information, should be made to settings
104154
"""
@@ -123,10 +173,16 @@ async def set_effect(
123173
transition: Optional[int] = None,
124174
) -> None:
125175
"""Set an effect on the device."""
126-
raise NotImplementedError() # TODO: the code above does not seem to activate the effect
127-
return await self.protocol.query({"set_device_info": {"dynamic_light_effect_enable": 1,
128-
"dynamic_light_effect_id": effect}})
129-
176+
raise NotImplementedError()
177+
# TODO: the code below does to activate the effect but gives no error
178+
return await self.protocol.query(
179+
{
180+
"set_device_info": {
181+
"dynamic_light_effect_enable": 1,
182+
"dynamic_light_effect_id": effect,
183+
}
184+
}
185+
)
130186

131187
@property
132188
def presets(self) -> List[SmartBulbPreset]:

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL