python-kasa 0.6.2.1__py3-none-any.whl → 0.7.0.dev0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (164) hide show
  1. kasa/__init__.py +88 -27
  2. kasa/aestransport.py +51 -34
  3. kasa/cli.py +326 -130
  4. kasa/device.py +406 -0
  5. kasa/device_factory.py +83 -44
  6. kasa/device_type.py +7 -3
  7. kasa/deviceconfig.py +16 -9
  8. kasa/discover.py +100 -81
  9. kasa/emeterstatus.py +7 -5
  10. kasa/exceptions.py +41 -26
  11. kasa/feature.py +201 -0
  12. kasa/httpclient.py +21 -14
  13. kasa/interfaces/__init__.py +16 -0
  14. kasa/interfaces/fan.py +20 -0
  15. kasa/interfaces/led.py +38 -0
  16. kasa/interfaces/light.py +133 -0
  17. kasa/interfaces/lighteffect.py +80 -0
  18. kasa/interfaces/lightpreset.py +76 -0
  19. kasa/iot/__init__.py +18 -0
  20. kasa/{effects.py → iot/effects.py} +4 -2
  21. kasa/{smartbulb.py → iot/iotbulb.py} +100 -147
  22. kasa/{smartdevice.py → iot/iotdevice.py} +157 -286
  23. kasa/{smartdimmer.py → iot/iotdimmer.py} +42 -33
  24. kasa/iot/iotlightstrip.py +71 -0
  25. kasa/{modules/module.py → iot/iotmodule.py} +22 -42
  26. kasa/iot/iotplug.py +94 -0
  27. kasa/{smartstrip.py → iot/iotstrip.py} +57 -75
  28. kasa/{modules → iot/modules}/__init__.py +10 -2
  29. kasa/{modules → iot/modules}/ambientlight.py +31 -3
  30. kasa/{modules → iot/modules}/antitheft.py +1 -0
  31. kasa/{modules → iot/modules}/cloud.py +25 -6
  32. kasa/{modules → iot/modules}/countdown.py +1 -0
  33. kasa/iot/modules/emeter.py +210 -0
  34. kasa/iot/modules/led.py +32 -0
  35. kasa/iot/modules/light.py +221 -0
  36. kasa/iot/modules/lighteffect.py +122 -0
  37. kasa/iot/modules/lightpreset.py +151 -0
  38. kasa/{modules → iot/modules}/motion.py +8 -8
  39. kasa/{modules → iot/modules}/rulemodule.py +11 -12
  40. kasa/{modules → iot/modules}/schedule.py +1 -0
  41. kasa/{modules → iot/modules}/time.py +5 -4
  42. kasa/{modules → iot/modules}/usage.py +10 -8
  43. kasa/iotprotocol.py +22 -20
  44. kasa/klaptransport.py +25 -15
  45. kasa/module.py +136 -0
  46. kasa/modulemapping.py +25 -0
  47. kasa/modulemapping.pyi +96 -0
  48. kasa/protocol.py +6 -4
  49. kasa/smart/__init__.py +6 -0
  50. kasa/smart/effects.py +429 -0
  51. kasa/smart/modules/__init__.py +57 -0
  52. kasa/smart/modules/alarm.py +142 -0
  53. kasa/smart/modules/autooff.py +96 -0
  54. kasa/smart/modules/batterysensor.py +54 -0
  55. kasa/smart/modules/brightness.py +66 -0
  56. kasa/smart/modules/childdevice.py +10 -0
  57. kasa/smart/modules/cloud.py +42 -0
  58. kasa/smart/modules/color.py +96 -0
  59. kasa/smart/modules/colortemperature.py +78 -0
  60. kasa/smart/modules/contactsensor.py +42 -0
  61. kasa/smart/modules/devicemodule.py +22 -0
  62. kasa/smart/modules/energy.py +101 -0
  63. kasa/smart/modules/fan.py +80 -0
  64. kasa/smart/modules/firmware.py +216 -0
  65. kasa/smart/modules/frostprotection.py +59 -0
  66. kasa/smart/modules/humiditysensor.py +55 -0
  67. kasa/smart/modules/led.py +49 -0
  68. kasa/smart/modules/light.py +139 -0
  69. kasa/smart/modules/lighteffect.py +115 -0
  70. kasa/smart/modules/lightpreset.py +142 -0
  71. kasa/smart/modules/lightstripeffect.py +135 -0
  72. kasa/smart/modules/lighttransition.py +183 -0
  73. kasa/smart/modules/reportmode.py +36 -0
  74. kasa/smart/modules/temperaturecontrol.py +177 -0
  75. kasa/smart/modules/temperaturesensor.py +77 -0
  76. kasa/smart/modules/time.py +57 -0
  77. kasa/smart/modules/waterleaksensor.py +66 -0
  78. kasa/smart/smartchilddevice.py +65 -0
  79. kasa/smart/smartdevice.py +653 -0
  80. kasa/smart/smartmodule.py +112 -0
  81. kasa/smartprotocol.py +107 -41
  82. kasa/tests/conftest.py +27 -562
  83. kasa/tests/device_fixtures.py +427 -0
  84. kasa/tests/discovery_fixtures.py +197 -0
  85. kasa/tests/fakeprotocol_iot.py +64 -6
  86. kasa/tests/fakeprotocol_smart.py +215 -22
  87. kasa/tests/fixtureinfo.py +154 -0
  88. kasa/tests/fixtures/smart/H100(EU)_1.0_1.2.3.json +221 -0
  89. kasa/tests/fixtures/smart/H100(EU)_1.0_1.5.10.json +547 -0
  90. kasa/tests/fixtures/smart/H100(EU)_1.0_1.5.5.json +391 -0
  91. kasa/tests/fixtures/smart/KH100(UK)_1.0_1.5.6.json +1557 -0
  92. kasa/tests/fixtures/smart/KS240(US)_1.0_1.0.4.json +899 -0
  93. kasa/tests/fixtures/smart/KS240(US)_1.0_1.0.5.json +479 -0
  94. kasa/tests/fixtures/smart/L530E(EU)_3.0_1.1.6.json +449 -0
  95. kasa/tests/fixtures/smart/P100_1.0.0_1.1.3.json +173 -0
  96. kasa/tests/fixtures/smart/P100_1.0.0_1.4.0.json +204 -0
  97. kasa/tests/fixtures/smart/P110(EU)_1.0_1.0.7.json +566 -0
  98. kasa/tests/fixtures/smart/child/KE100(EU)_1.0_2.4.0.json +170 -0
  99. kasa/tests/fixtures/smart/child/KE100(EU)_1.0_2.8.0.json +171 -0
  100. kasa/tests/fixtures/smart/child/KE100(UK)_1.0_2.8.0.json +171 -0
  101. kasa/tests/fixtures/smart/child/T110(EU)_1.0_1.8.0.json +526 -0
  102. kasa/tests/fixtures/smart/child/T300(EU)_1.0_1.7.0.json +533 -0
  103. kasa/tests/fixtures/smart/child/T310(EU)_1.0_1.5.0.json +530 -0
  104. kasa/tests/fixtures/smart/child/T315(EU)_1.0_1.7.0.json +537 -0
  105. kasa/tests/smart/__init__.py +0 -0
  106. kasa/tests/smart/features/__init__.py +0 -0
  107. kasa/tests/smart/features/test_brightness.py +55 -0
  108. kasa/tests/smart/features/test_colortemp.py +30 -0
  109. kasa/tests/smart/modules/__init__.py +0 -0
  110. kasa/tests/smart/modules/test_contact.py +28 -0
  111. kasa/tests/smart/modules/test_fan.py +79 -0
  112. kasa/tests/smart/modules/test_firmware.py +108 -0
  113. kasa/tests/smart/modules/test_humidity.py +28 -0
  114. kasa/tests/smart/modules/test_light_effect.py +41 -0
  115. kasa/tests/smart/modules/test_temperature.py +47 -0
  116. kasa/tests/smart/modules/test_temperaturecontrol.py +137 -0
  117. kasa/tests/smart/modules/test_waterleak.py +42 -0
  118. kasa/tests/test_aestransport.py +115 -23
  119. kasa/tests/test_bulb.py +115 -85
  120. kasa/tests/test_childdevice.py +19 -7
  121. kasa/tests/test_cli.py +453 -99
  122. kasa/tests/test_common_modules.py +216 -0
  123. kasa/tests/test_device.py +268 -0
  124. kasa/tests/test_device_factory.py +61 -35
  125. kasa/tests/test_device_type.py +1 -1
  126. kasa/tests/test_deviceconfig.py +2 -2
  127. kasa/tests/test_dimmer.py +33 -24
  128. kasa/tests/test_discovery.py +112 -63
  129. kasa/tests/test_emeter.py +14 -10
  130. kasa/tests/test_feature.py +205 -0
  131. kasa/tests/test_httpclient.py +9 -9
  132. kasa/tests/test_iotdevice.py +286 -0
  133. kasa/tests/test_klapprotocol.py +94 -37
  134. kasa/tests/test_lightstrip.py +24 -19
  135. kasa/tests/test_plug.py +46 -8
  136. kasa/tests/test_protocol.py +8 -10
  137. kasa/tests/test_readme_examples.py +87 -26
  138. kasa/tests/test_smartdevice.py +203 -311
  139. kasa/tests/test_smartprotocol.py +130 -25
  140. kasa/tests/test_strip.py +15 -6
  141. kasa/tests/test_usage.py +1 -1
  142. kasa/xortransport.py +15 -12
  143. {python_kasa-0.6.2.1.dist-info → python_kasa-0.7.0.dev0.dist-info}/METADATA +45 -143
  144. python_kasa-0.7.0.dev0.dist-info/RECORD +239 -0
  145. kasa/modules/emeter.py +0 -111
  146. kasa/smartlightstrip.py +0 -143
  147. kasa/smartplug.py +0 -91
  148. kasa/tapo/__init__.py +0 -7
  149. kasa/tapo/childdevice.py +0 -41
  150. kasa/tapo/tapobulb.py +0 -262
  151. kasa/tapo/tapodevice.py +0 -409
  152. kasa/tapo/tapoplug.py +0 -45
  153. kasa/tests/fixtures/HS105(US)_1.0_mocked.json +0 -47
  154. kasa/tests/fixtures/HS110(EU)_2.0_mocked.json +0 -50
  155. kasa/tests/fixtures/HS110(US)_1.0_mocked.json +0 -50
  156. kasa/tests/fixtures/HS200(US)_1.0_mocked.json +0 -47
  157. kasa/tests/fixtures/HS220(US)_1.0_mocked.json +0 -75
  158. kasa/tests/fixtures/LB100(US)_1.0_mocked.json +0 -103
  159. kasa/tests/fixtures/LB120(US)_1.0_mocked.json +0 -103
  160. kasa/tests/fixtures/LB130(US)_1.0_mocked.json +0 -104
  161. python_kasa-0.6.2.1.dist-info/RECORD +0 -167
  162. {python_kasa-0.6.2.1.dist-info → python_kasa-0.7.0.dev0.dist-info}/LICENSE +0 -0
  163. {python_kasa-0.6.2.1.dist-info → python_kasa-0.7.0.dev0.dist-info}/WHEEL +0 -0
  164. {python_kasa-0.6.2.1.dist-info → python_kasa-0.7.0.dev0.dist-info}/entry_points.txt +0 -0
@@ -1,50 +1,31 @@
1
1
  """Module for bulbs (LB*, KL*, KB*)."""
2
+
3
+ from __future__ import annotations
4
+
2
5
  import logging
3
6
  import re
4
7
  from enum import Enum
5
- from typing import Any, Dict, List, NamedTuple, Optional, cast
6
-
7
- try:
8
- from pydantic.v1 import BaseModel, Field, root_validator
9
- except ImportError:
10
- from pydantic import BaseModel, Field, root_validator
11
-
12
- from .deviceconfig import DeviceConfig
13
- from .modules import Antitheft, Cloud, Countdown, Emeter, Schedule, Time, Usage
14
- from .protocol import BaseProtocol
15
- from .smartdevice import DeviceType, SmartDevice, SmartDeviceException, requires_update
16
-
17
-
18
- class ColorTempRange(NamedTuple):
19
- """Color temperature range."""
20
-
21
- min: int
22
- max: int
23
-
24
-
25
- class HSV(NamedTuple):
26
- """Hue-saturation-value."""
27
-
28
- hue: int
29
- saturation: int
30
- value: int
31
-
32
-
33
- class SmartBulbPreset(BaseModel):
34
- """Bulb configuration preset."""
35
-
36
- index: int
37
- brightness: int
38
-
39
- # These are not available for effect mode presets on light strips
40
- hue: Optional[int]
41
- saturation: Optional[int]
42
- color_temp: Optional[int]
43
-
44
- # Variables for effect mode presets
45
- custom: Optional[int]
46
- id: Optional[str]
47
- mode: Optional[int]
8
+ from typing import Optional, cast
9
+
10
+ from pydantic.v1 import BaseModel, Field, root_validator
11
+
12
+ from ..device_type import DeviceType
13
+ from ..deviceconfig import DeviceConfig
14
+ from ..interfaces.light import HSV, ColorTempRange
15
+ from ..module import Module
16
+ from ..protocol import BaseProtocol
17
+ from .iotdevice import IotDevice, KasaException, requires_update
18
+ from .modules import (
19
+ Antitheft,
20
+ Cloud,
21
+ Countdown,
22
+ Emeter,
23
+ Light,
24
+ LightPreset,
25
+ Schedule,
26
+ Time,
27
+ Usage,
28
+ )
48
29
 
49
30
 
50
31
  class BehaviorMode(str, Enum):
@@ -68,7 +49,7 @@ class TurnOnBehavior(BaseModel):
68
49
  """
69
50
 
70
51
  #: Index of preset to use, or ``None`` for the last known state.
71
- preset: Optional[int] = Field(alias="index", default=None)
52
+ preset: Optional[int] = Field(alias="index", default=None) # noqa: UP007
72
53
  #: Wanted behavior
73
54
  mode: BehaviorMode
74
55
 
@@ -116,7 +97,7 @@ NON_COLOR_MODE_FLAGS = {"transition_period", "on_off"}
116
97
  _LOGGER = logging.getLogger(__name__)
117
98
 
118
99
 
119
- class SmartBulb(SmartDevice):
100
+ class IotBulb(IotDevice):
120
101
  r"""Representation of a TP-Link Smart Bulb.
121
102
 
122
103
  To initialize, you have to await :func:`update()` at least once.
@@ -127,12 +108,12 @@ class SmartBulb(SmartDevice):
127
108
  so you must await :func:`update()` to fetch updates values from the device.
128
109
 
129
110
  Errors reported by the device are raised as
130
- :class:`SmartDeviceExceptions <kasa.exceptions.SmartDeviceException>`,
111
+ :class:`KasaException <kasa.exceptions.KasaException>`,
131
112
  and should be handled by the user of the library.
132
113
 
133
114
  Examples:
134
115
  >>> import asyncio
135
- >>> bulb = SmartBulb("127.0.0.1")
116
+ >>> bulb = IotBulb("127.0.0.1")
136
117
  >>> asyncio.run(bulb.update())
137
118
  >>> print(bulb.alias)
138
119
  Bulb2
@@ -198,9 +179,9 @@ class SmartBulb(SmartDevice):
198
179
  Bulb configuration presets can be accessed using the :func:`presets` property:
199
180
 
200
181
  >>> bulb.presets
201
- [SmartBulbPreset(index=0, brightness=50, hue=0, saturation=0, color_temp=2700, custom=None, id=None, mode=None), SmartBulbPreset(index=1, brightness=100, hue=0, saturation=75, color_temp=0, custom=None, id=None, mode=None), SmartBulbPreset(index=2, brightness=100, hue=120, saturation=75, color_temp=0, custom=None, id=None, mode=None), SmartBulbPreset(index=3, brightness=100, hue=240, saturation=75, color_temp=0, custom=None, id=None, mode=None)]
182
+ [IotLightPreset(index=0, brightness=50, hue=0, saturation=0, color_temp=2700, custom=None, id=None, mode=None), IotLightPreset(index=1, brightness=100, hue=0, saturation=75, color_temp=0, custom=None, id=None, mode=None), IotLightPreset(index=2, brightness=100, hue=120, saturation=75, color_temp=0, custom=None, id=None, mode=None), IotLightPreset(index=3, brightness=100, hue=240, saturation=75, color_temp=0, custom=None, id=None, mode=None)]
202
183
 
203
- To modify an existing preset, pass :class:`~kasa.smartbulb.SmartBulbPreset`
184
+ To modify an existing preset, pass :class:`~kasa.interfaces.light.LightPreset`
204
185
  instance to :func:`save_preset` method:
205
186
 
206
187
  >>> preset = bulb.presets[0]
@@ -208,6 +189,7 @@ class SmartBulb(SmartDevice):
208
189
  50
209
190
  >>> preset.brightness = 100
210
191
  >>> asyncio.run(bulb.save_preset(preset))
192
+ >>> asyncio.run(bulb.update())
211
193
  >>> bulb.presets[0].brightness
212
194
  100
213
195
 
@@ -221,49 +203,59 @@ class SmartBulb(SmartDevice):
221
203
  self,
222
204
  host: str,
223
205
  *,
224
- config: Optional[DeviceConfig] = None,
225
- protocol: Optional[BaseProtocol] = None,
206
+ config: DeviceConfig | None = None,
207
+ protocol: BaseProtocol | None = None,
226
208
  ) -> None:
227
209
  super().__init__(host=host, config=config, protocol=protocol)
228
210
  self._device_type = DeviceType.Bulb
229
- self.add_module("schedule", Schedule(self, "smartlife.iot.common.schedule"))
230
- self.add_module("usage", Usage(self, "smartlife.iot.common.schedule"))
231
- self.add_module("antitheft", Antitheft(self, "smartlife.iot.common.anti_theft"))
232
- self.add_module("time", Time(self, "smartlife.iot.common.timesetting"))
233
- self.add_module("emeter", Emeter(self, self.emeter_type))
234
- self.add_module("countdown", Countdown(self, "countdown"))
235
- self.add_module("cloud", Cloud(self, "smartlife.iot.common.cloud"))
211
+
212
+ async def _initialize_modules(self):
213
+ """Initialize modules not added in init."""
214
+ await super()._initialize_modules()
215
+ self.add_module(
216
+ Module.IotSchedule, Schedule(self, "smartlife.iot.common.schedule")
217
+ )
218
+ self.add_module(Module.IotUsage, Usage(self, "smartlife.iot.common.schedule"))
219
+ self.add_module(
220
+ Module.IotAntitheft, Antitheft(self, "smartlife.iot.common.anti_theft")
221
+ )
222
+ self.add_module(Module.IotTime, Time(self, "smartlife.iot.common.timesetting"))
223
+ self.add_module(Module.IotEmeter, Emeter(self, self.emeter_type))
224
+ self.add_module(Module.IotCountdown, Countdown(self, "countdown"))
225
+ self.add_module(Module.IotCloud, Cloud(self, "smartlife.iot.common.cloud"))
226
+ self.add_module(Module.Light, Light(self, self.LIGHT_SERVICE))
227
+ self.add_module(Module.LightPreset, LightPreset(self, self.LIGHT_SERVICE))
236
228
 
237
229
  @property # type: ignore
238
230
  @requires_update
239
- def is_color(self) -> bool:
231
+ def _is_color(self) -> bool:
240
232
  """Whether the bulb supports color changes."""
241
233
  sys_info = self.sys_info
242
234
  return bool(sys_info["is_color"])
243
235
 
244
236
  @property # type: ignore
245
237
  @requires_update
246
- def is_dimmable(self) -> bool:
238
+ def _is_dimmable(self) -> bool:
247
239
  """Whether the bulb supports brightness changes."""
248
240
  sys_info = self.sys_info
249
241
  return bool(sys_info["is_dimmable"])
250
242
 
251
243
  @property # type: ignore
252
244
  @requires_update
253
- def is_variable_color_temp(self) -> bool:
245
+ def _is_variable_color_temp(self) -> bool:
254
246
  """Whether the bulb supports color temperature changes."""
255
247
  sys_info = self.sys_info
256
248
  return bool(sys_info["is_variable_color_temp"])
257
249
 
258
250
  @property # type: ignore
259
251
  @requires_update
260
- def valid_temperature_range(self) -> ColorTempRange:
252
+ def _valid_temperature_range(self) -> ColorTempRange:
261
253
  """Return the device-specific white temperature range (in Kelvin).
262
254
 
263
255
  :return: White temperature range in Kelvin (minimum, maximum)
264
256
  """
265
- if not self.is_variable_color_temp:
266
- raise SmartDeviceException("Color temperature not supported")
257
+ if not self._is_variable_color_temp:
258
+ raise KasaException("Color temperature not supported")
267
259
 
268
260
  for model, temp_range in TPLINK_KELVIN.items():
269
261
  sys_info = self.sys_info
@@ -275,11 +267,11 @@ class SmartBulb(SmartDevice):
275
267
 
276
268
  @property # type: ignore
277
269
  @requires_update
278
- def light_state(self) -> Dict[str, str]:
270
+ def light_state(self) -> dict[str, str]:
279
271
  """Query the light state."""
280
272
  light_state = self.sys_info["light_state"]
281
273
  if light_state is None:
282
- raise SmartDeviceException(
274
+ raise KasaException(
283
275
  "The device has no light_state or you have not called update()"
284
276
  )
285
277
 
@@ -294,11 +286,11 @@ class SmartBulb(SmartDevice):
294
286
 
295
287
  @property # type: ignore
296
288
  @requires_update
297
- def has_effects(self) -> bool:
289
+ def _has_effects(self) -> bool:
298
290
  """Return True if the device supports effects."""
299
291
  return "lighting_effect_state" in self.sys_info
300
292
 
301
- async def get_light_details(self) -> Dict[str, int]:
293
+ async def get_light_details(self) -> dict[str, int]:
302
294
  """Return light details.
303
295
 
304
296
  Example::
@@ -325,14 +317,14 @@ class SmartBulb(SmartDevice):
325
317
  self.LIGHT_SERVICE, "set_default_behavior", behavior.dict(by_alias=True)
326
318
  )
327
319
 
328
- async def get_light_state(self) -> Dict[str, Dict]:
320
+ async def get_light_state(self) -> dict[str, dict]:
329
321
  """Query the light state."""
330
322
  # TODO: add warning and refer to use light.state?
331
323
  return await self._query_helper(self.LIGHT_SERVICE, "get_light_state")
332
324
 
333
- async def set_light_state(
334
- self, state: Dict, *, transition: Optional[int] = None
335
- ) -> Dict:
325
+ async def _set_light_state(
326
+ self, state: dict, *, transition: int | None = None
327
+ ) -> dict:
336
328
  """Set the light state."""
337
329
  if transition is not None:
338
330
  state["transition_period"] = transition
@@ -357,13 +349,13 @@ class SmartBulb(SmartDevice):
357
349
 
358
350
  @property # type: ignore
359
351
  @requires_update
360
- def hsv(self) -> HSV:
352
+ def _hsv(self) -> HSV:
361
353
  """Return the current HSV state of the bulb.
362
354
 
363
355
  :return: hue, saturation and value (degrees, %, %)
364
356
  """
365
- if not self.is_color:
366
- raise SmartDeviceException("Bulb does not support color.")
357
+ if not self._is_color:
358
+ raise KasaException("Bulb does not support color.")
367
359
 
368
360
  light_state = cast(dict, self.light_state)
369
361
 
@@ -373,19 +365,15 @@ class SmartBulb(SmartDevice):
373
365
 
374
366
  return HSV(hue, saturation, value)
375
367
 
376
- def _raise_for_invalid_brightness(self, value):
377
- if not isinstance(value, int) or not (0 <= value <= 100):
378
- raise ValueError(f"Invalid brightness value: {value} (valid range: 0-100%)")
379
-
380
368
  @requires_update
381
- async def set_hsv(
369
+ async def _set_hsv(
382
370
  self,
383
371
  hue: int,
384
372
  saturation: int,
385
- value: Optional[int] = None,
373
+ value: int | None = None,
386
374
  *,
387
- transition: Optional[int] = None,
388
- ) -> Dict:
375
+ transition: int | None = None,
376
+ ) -> dict:
389
377
  """Set new HSV.
390
378
 
391
379
  :param int hue: hue in degrees
@@ -393,8 +381,8 @@ class SmartBulb(SmartDevice):
393
381
  :param int value: value in percentage [0, 100]
394
382
  :param int transition: transition in milliseconds.
395
383
  """
396
- if not self.is_color:
397
- raise SmartDeviceException("Bulb does not support color.")
384
+ if not self._is_color:
385
+ raise KasaException("Bulb does not support color.")
398
386
 
399
387
  if not isinstance(hue, int) or not (0 <= hue <= 360):
400
388
  raise ValueError(f"Invalid hue value: {hue} (valid range: 0-360)")
@@ -414,29 +402,29 @@ class SmartBulb(SmartDevice):
414
402
  self._raise_for_invalid_brightness(value)
415
403
  light_state["brightness"] = value
416
404
 
417
- return await self.set_light_state(light_state, transition=transition)
405
+ return await self._set_light_state(light_state, transition=transition)
418
406
 
419
407
  @property # type: ignore
420
408
  @requires_update
421
- def color_temp(self) -> int:
409
+ def _color_temp(self) -> int:
422
410
  """Return color temperature of the device in kelvin."""
423
- if not self.is_variable_color_temp:
424
- raise SmartDeviceException("Bulb does not support colortemp.")
411
+ if not self._is_variable_color_temp:
412
+ raise KasaException("Bulb does not support colortemp.")
425
413
 
426
414
  light_state = self.light_state
427
415
  return int(light_state["color_temp"])
428
416
 
429
417
  @requires_update
430
- async def set_color_temp(
431
- self, temp: int, *, brightness=None, transition: Optional[int] = None
432
- ) -> Dict:
418
+ async def _set_color_temp(
419
+ self, temp: int, *, brightness=None, transition: int | None = None
420
+ ) -> dict:
433
421
  """Set the color temperature of the device in kelvin.
434
422
 
435
423
  :param int temp: The new color temperature, in Kelvin
436
424
  :param int transition: transition in milliseconds.
437
425
  """
438
- if not self.is_variable_color_temp:
439
- raise SmartDeviceException("Bulb does not support colortemp.")
426
+ if not self._is_variable_color_temp:
427
+ raise KasaException("Bulb does not support colortemp.")
440
428
 
441
429
  valid_temperature_range = self.valid_temperature_range
442
430
  if temp < valid_temperature_range[0] or temp > valid_temperature_range[1]:
@@ -450,51 +438,38 @@ class SmartBulb(SmartDevice):
450
438
  if brightness is not None:
451
439
  light_state["brightness"] = brightness
452
440
 
453
- return await self.set_light_state(light_state, transition=transition)
441
+ return await self._set_light_state(light_state, transition=transition)
442
+
443
+ def _raise_for_invalid_brightness(self, value):
444
+ if not isinstance(value, int) or not (0 <= value <= 100):
445
+ raise ValueError(f"Invalid brightness value: {value} (valid range: 0-100%)")
454
446
 
455
447
  @property # type: ignore
456
448
  @requires_update
457
- def brightness(self) -> int:
449
+ def _brightness(self) -> int:
458
450
  """Return the current brightness in percentage."""
459
- if not self.is_dimmable: # pragma: no cover
460
- raise SmartDeviceException("Bulb is not dimmable.")
451
+ if not self._is_dimmable: # pragma: no cover
452
+ raise KasaException("Bulb is not dimmable.")
461
453
 
462
454
  light_state = self.light_state
463
455
  return int(light_state["brightness"])
464
456
 
465
457
  @requires_update
466
- async def set_brightness(
467
- self, brightness: int, *, transition: Optional[int] = None
468
- ) -> Dict:
458
+ async def _set_brightness(
459
+ self, brightness: int, *, transition: int | None = None
460
+ ) -> dict:
469
461
  """Set the brightness in percentage.
470
462
 
471
463
  :param int brightness: brightness in percent
472
464
  :param int transition: transition in milliseconds.
473
465
  """
474
- if not self.is_dimmable: # pragma: no cover
475
- raise SmartDeviceException("Bulb is not dimmable.")
466
+ if not self._is_dimmable: # pragma: no cover
467
+ raise KasaException("Bulb is not dimmable.")
476
468
 
477
469
  self._raise_for_invalid_brightness(brightness)
478
470
 
479
471
  light_state = {"brightness": brightness}
480
- return await self.set_light_state(light_state, transition=transition)
481
-
482
- @property # type: ignore
483
- @requires_update
484
- def state_information(self) -> Dict[str, Any]:
485
- """Return bulb-specific state information."""
486
- info: Dict[str, Any] = {
487
- "Brightness": self.brightness,
488
- "Is dimmable": self.is_dimmable,
489
- }
490
- if self.is_variable_color_temp:
491
- info["Color temperature"] = self.color_temp
492
- info["Valid temperature range"] = self.valid_temperature_range
493
- if self.is_color:
494
- info["HSV"] = self.hsv
495
- info["Presets"] = self.presets
496
-
497
- return info
472
+ return await self._set_light_state(light_state, transition=transition)
498
473
 
499
474
  @property # type: ignore
500
475
  @requires_update
@@ -503,19 +478,19 @@ class SmartBulb(SmartDevice):
503
478
  light_state = self.light_state
504
479
  return bool(light_state["on_off"])
505
480
 
506
- async def turn_off(self, *, transition: Optional[int] = None, **kwargs) -> Dict:
481
+ async def turn_off(self, *, transition: int | None = None, **kwargs) -> dict:
507
482
  """Turn the bulb off.
508
483
 
509
484
  :param int transition: transition in milliseconds.
510
485
  """
511
- return await self.set_light_state({"on_off": 0}, transition=transition)
486
+ return await self._set_light_state({"on_off": 0}, transition=transition)
512
487
 
513
- async def turn_on(self, *, transition: Optional[int] = None, **kwargs) -> Dict:
488
+ async def turn_on(self, *, transition: int | None = None, **kwargs) -> dict:
514
489
  """Turn the bulb on.
515
490
 
516
491
  :param int transition: transition in milliseconds.
517
492
  """
518
- return await self.set_light_state({"on_off": 1}, transition=transition)
493
+ return await self._set_light_state({"on_off": 1}, transition=transition)
519
494
 
520
495
  @property # type: ignore
521
496
  @requires_update
@@ -532,28 +507,6 @@ class SmartBulb(SmartDevice):
532
507
  "smartlife.iot.common.system", "set_dev_alias", {"alias": alias}
533
508
  )
534
509
 
535
- @property # type: ignore
536
- @requires_update
537
- def presets(self) -> List[SmartBulbPreset]:
538
- """Return a list of available bulb setting presets."""
539
- return [SmartBulbPreset(**vals) for vals in self.sys_info["preferred_state"]]
540
-
541
- async def save_preset(self, preset: SmartBulbPreset):
542
- """Save a setting preset.
543
-
544
- You can either construct a preset object manually, or pass an existing one
545
- obtained using :func:`presets`.
546
- """
547
- if len(self.presets) == 0:
548
- raise SmartDeviceException("Device does not supported saving presets")
549
-
550
- if preset.index >= len(self.presets):
551
- raise SmartDeviceException("Invalid preset index")
552
-
553
- return await self._query_helper(
554
- self.LIGHT_SERVICE, "set_preferred_state", preset.dict(exclude_none=True)
555
- )
556
-
557
510
  @property
558
511
  def max_device_response_size(self) -> int:
559
512
  """Returns the maximum response size the device can safely construct."""