python-kasa 0.7.3__py3-none-any.whl → 0.7.5__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 (39) hide show
  1. kasa/cachedzoneinfo.py +28 -0
  2. kasa/cli/device.py +13 -2
  3. kasa/device.py +22 -3
  4. kasa/device_factory.py +2 -2
  5. kasa/discover.py +2 -2
  6. kasa/iot/iotbulb.py +1 -1
  7. kasa/iot/iotdevice.py +25 -10
  8. kasa/iot/iotstrip.py +12 -5
  9. kasa/iot/iottimezone.py +156 -0
  10. kasa/iot/modules/ambientlight.py +3 -3
  11. kasa/iot/modules/cloud.py +3 -3
  12. kasa/iot/modules/emeter.py +1 -1
  13. kasa/iot/modules/light.py +1 -1
  14. kasa/iot/modules/lightpreset.py +1 -1
  15. kasa/iot/modules/time.py +16 -5
  16. kasa/klaptransport.py +0 -1
  17. kasa/module.py +1 -1
  18. kasa/smart/modules/cloud.py +3 -9
  19. kasa/smart/modules/color.py +3 -8
  20. kasa/smart/modules/contactsensor.py +3 -8
  21. kasa/smart/modules/devicemodule.py +1 -1
  22. kasa/smart/modules/fan.py +4 -10
  23. kasa/smart/modules/humiditysensor.py +4 -9
  24. kasa/smart/modules/light.py +1 -1
  25. kasa/smart/modules/lighteffect.py +1 -1
  26. kasa/smart/modules/lightpreset.py +1 -1
  27. kasa/smart/modules/lighttransition.py +1 -1
  28. kasa/smart/modules/reportmode.py +3 -8
  29. kasa/smart/modules/temperaturesensor.py +7 -10
  30. kasa/smart/modules/time.py +28 -14
  31. kasa/smart/modules/waterleaksensor.py +4 -8
  32. kasa/smart/smartchilddevice.py +1 -1
  33. kasa/smart/smartdevice.py +23 -11
  34. kasa/smart/smartmodule.py +3 -3
  35. {python_kasa-0.7.3.dist-info → python_kasa-0.7.5.dist-info}/METADATA +2 -1
  36. {python_kasa-0.7.3.dist-info → python_kasa-0.7.5.dist-info}/RECORD +39 -37
  37. {python_kasa-0.7.3.dist-info → python_kasa-0.7.5.dist-info}/WHEEL +0 -0
  38. {python_kasa-0.7.3.dist-info → python_kasa-0.7.5.dist-info}/entry_points.txt +0 -0
  39. {python_kasa-0.7.3.dist-info → python_kasa-0.7.5.dist-info}/licenses/LICENSE +0 -0
kasa/cachedzoneinfo.py ADDED
@@ -0,0 +1,28 @@
1
+ """Module for caching ZoneInfos."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import asyncio
6
+
7
+ from zoneinfo import ZoneInfo
8
+
9
+
10
+ class CachedZoneInfo(ZoneInfo):
11
+ """Cache ZoneInfo objects."""
12
+
13
+ _cache: dict[str, ZoneInfo] = {}
14
+
15
+ @classmethod
16
+ async def get_cached_zone_info(cls, time_zone_str: str) -> ZoneInfo:
17
+ """Get a cached zone info object."""
18
+ if cached := cls._cache.get(time_zone_str):
19
+ return cached
20
+ loop = asyncio.get_running_loop()
21
+ zinfo = await loop.run_in_executor(None, _get_zone_info, time_zone_str)
22
+ cls._cache[time_zone_str] = zinfo
23
+ return zinfo
24
+
25
+
26
+ def _get_zone_info(time_zone_str: str) -> ZoneInfo:
27
+ """Get a time zone object for the given time zone string."""
28
+ return ZoneInfo(time_zone_str)
kasa/cli/device.py CHANGED
@@ -40,7 +40,7 @@ async def state(ctx, dev: Device):
40
40
  echo(f"Port: {dev.port}")
41
41
  echo(f"Device state: {dev.is_on}")
42
42
 
43
- echo(f"Time: {dev.time} (tz: {dev.timezone}")
43
+ echo(f"Time: {dev.time} (tz: {dev.timezone})")
44
44
  echo(f"Hardware: {dev.hw_info['hw_ver']}")
45
45
  echo(f"Software: {dev.hw_info['sw_ver']}")
46
46
  echo(f"MAC (rssi): {dev.mac} ({dev.rssi})")
@@ -99,7 +99,7 @@ async def on(dev: Device, transition: int):
99
99
  return await dev.turn_on(transition=transition)
100
100
 
101
101
 
102
- @click.command
102
+ @device.command
103
103
  @click.option("--transition", type=int, required=False)
104
104
  @pass_dev_or_child
105
105
  async def off(dev: Device, transition: int):
@@ -166,6 +166,17 @@ async def reboot(plug, delay):
166
166
  return await plug.reboot(delay)
167
167
 
168
168
 
169
+ @device.command()
170
+ @pass_dev
171
+ async def factory_reset(plug):
172
+ """Reset device to factory settings."""
173
+ click.confirm(
174
+ "Do you really want to reset the device to factory settings?", abort=True
175
+ )
176
+
177
+ return await plug.factory_reset()
178
+
179
+
169
180
  @device.command()
170
181
  @pass_dev
171
182
  @click.option(
kasa/device.py CHANGED
@@ -109,7 +109,7 @@ import logging
109
109
  from abc import ABC, abstractmethod
110
110
  from collections.abc import Mapping, Sequence
111
111
  from dataclasses import dataclass
112
- from datetime import datetime
112
+ from datetime import datetime, tzinfo
113
113
  from typing import TYPE_CHECKING, Any
114
114
  from warnings import warn
115
115
 
@@ -377,7 +377,7 @@ class Device(ABC):
377
377
 
378
378
  @property
379
379
  @abstractmethod
380
- def timezone(self) -> dict:
380
+ def timezone(self) -> tzinfo:
381
381
  """Return the timezone and time_difference."""
382
382
 
383
383
  @property
@@ -435,7 +435,11 @@ class Device(ABC):
435
435
  @property
436
436
  @abstractmethod
437
437
  def on_since(self) -> datetime | None:
438
- """Return the time that the device was turned on or None if turned off."""
438
+ """Return the time that the device was turned on or None if turned off.
439
+
440
+ This returns a cached value if the device reported value difference is under
441
+ five seconds to avoid device-caused jitter.
442
+ """
439
443
 
440
444
  @abstractmethod
441
445
  async def wifi_scan(self) -> list[WifiNetwork]:
@@ -449,6 +453,21 @@ class Device(ABC):
449
453
  async def set_alias(self, alias: str):
450
454
  """Set the device name (alias)."""
451
455
 
456
+ @abstractmethod
457
+ async def reboot(self, delay: int = 1) -> None:
458
+ """Reboot the device.
459
+
460
+ Note that giving a delay of zero causes this to block,
461
+ as the device reboots immediately without responding to the call.
462
+ """
463
+
464
+ @abstractmethod
465
+ async def factory_reset(self) -> None:
466
+ """Reset device back to factory settings.
467
+
468
+ Note, this does not downgrade the firmware.
469
+ """
470
+
452
471
  def __repr__(self):
453
472
  if self._last_update is None:
454
473
  return f"<{self.device_type} at {self.host} - update() needed>"
kasa/device_factory.py CHANGED
@@ -32,8 +32,8 @@ from .xortransport import XorTransport
32
32
 
33
33
  _LOGGER = logging.getLogger(__name__)
34
34
 
35
- GET_SYSINFO_QUERY = {
36
- "system": {"get_sysinfo": None},
35
+ GET_SYSINFO_QUERY: dict[str, dict[str, dict]] = {
36
+ "system": {"get_sysinfo": {}},
37
37
  }
38
38
 
39
39
 
kasa/discover.py CHANGED
@@ -296,8 +296,8 @@ class Discover:
296
296
 
297
297
  DISCOVERY_PORT = 9999
298
298
 
299
- DISCOVERY_QUERY = {
300
- "system": {"get_sysinfo": None},
299
+ DISCOVERY_QUERY: dict[str, dict[str, dict]] = {
300
+ "system": {"get_sysinfo": {}},
301
301
  }
302
302
 
303
303
  DISCOVERY_PORT_2 = 20002
kasa/iot/iotbulb.py CHANGED
@@ -85,7 +85,7 @@ TPLINK_KELVIN = {
85
85
  "KB130": ColorTempRange(2500, 9000),
86
86
  "KL130": ColorTempRange(2500, 9000),
87
87
  "KL125": ColorTempRange(2500, 6500),
88
- "KL135": ColorTempRange(2500, 6500),
88
+ "KL135": ColorTempRange(2500, 9000),
89
89
  r"KL120\(EU\)": ColorTempRange(2700, 6500),
90
90
  r"KL120\(US\)": ColorTempRange(2700, 5000),
91
91
  r"KL430": ColorTempRange(2500, 9000),
kasa/iot/iotdevice.py CHANGED
@@ -18,7 +18,7 @@ import functools
18
18
  import inspect
19
19
  import logging
20
20
  from collections.abc import Mapping, Sequence
21
- from datetime import datetime, timedelta, timezone
21
+ from datetime import datetime, timedelta, tzinfo
22
22
  from typing import TYPE_CHECKING, Any, cast
23
23
 
24
24
  from ..device import Device, WifiNetwork
@@ -181,6 +181,7 @@ class IotDevice(Device):
181
181
  self._legacy_features: set[str] = set()
182
182
  self._children: Mapping[str, IotDevice] = {}
183
183
  self._modules: dict[str | ModuleName[Module], IotModule] = {}
184
+ self._on_since: datetime | None = None
184
185
 
185
186
  @property
186
187
  def children(self) -> Sequence[IotDevice]:
@@ -207,6 +208,8 @@ class IotDevice(Device):
207
208
  def _create_request(
208
209
  self, target: str, cmd: str, arg: dict | None = None, child_ids=None
209
210
  ):
211
+ if arg is None:
212
+ arg = {}
210
213
  request: dict[str, Any] = {target: {cmd: arg}}
211
214
  if child_ids is not None:
212
215
  request = {"context": {"child_ids": child_ids}, target: {cmd: arg}}
@@ -296,7 +299,7 @@ class IotDevice(Device):
296
299
 
297
300
  self._set_sys_info(self._last_update["system"]["get_sysinfo"])
298
301
  for module in self._modules.values():
299
- module._post_update_hook()
302
+ await module._post_update_hook()
300
303
 
301
304
  if not self._features:
302
305
  await self._initialize_features()
@@ -461,7 +464,7 @@ class IotDevice(Device):
461
464
 
462
465
  @property
463
466
  @requires_update
464
- def timezone(self) -> dict:
467
+ def timezone(self) -> tzinfo:
465
468
  """Return the current timezone."""
466
469
  return self.modules[Module.IotTime].timezone
467
470
 
@@ -561,6 +564,13 @@ class IotDevice(Device):
561
564
  """
562
565
  await self._query_helper("system", "reboot", {"delay": delay})
563
566
 
567
+ async def factory_reset(self) -> None:
568
+ """Reset device back to factory settings.
569
+
570
+ Note, this does not downgrade the firmware.
571
+ """
572
+ await self._query_helper("system", "reset")
573
+
564
574
  async def turn_off(self, **kwargs) -> dict:
565
575
  """Turn off the device."""
566
576
  raise NotImplementedError("Device subclass needs to implement this.")
@@ -585,18 +595,23 @@ class IotDevice(Device):
585
595
  @property # type: ignore
586
596
  @requires_update
587
597
  def on_since(self) -> datetime | None:
588
- """Return pretty-printed on-time, or None if not available."""
589
- if "on_time" not in self._sys_info:
590
- return None
598
+ """Return the time that the device was turned on or None if turned off.
591
599
 
592
- if self.is_off:
600
+ This returns a cached value if the device reported value difference is under
601
+ five seconds to avoid device-caused jitter.
602
+ """
603
+ if self.is_off or "on_time" not in self._sys_info:
604
+ self._on_since = None
593
605
  return None
594
606
 
595
607
  on_time = self._sys_info["on_time"]
596
608
 
597
- return datetime.now(timezone.utc).astimezone().replace(
598
- microsecond=0
599
- ) - timedelta(seconds=on_time)
609
+ on_since = self.time - timedelta(seconds=on_time)
610
+ if not self._on_since or timedelta(
611
+ seconds=0
612
+ ) < on_since - self._on_since > timedelta(seconds=5):
613
+ self._on_since = on_since
614
+ return self._on_since
600
615
 
601
616
  @property # type: ignore
602
617
  @requires_update
kasa/iot/iotstrip.py CHANGED
@@ -4,7 +4,7 @@ from __future__ import annotations
4
4
 
5
5
  import logging
6
6
  from collections import defaultdict
7
- from datetime import datetime, timedelta, timezone
7
+ from datetime import datetime, timedelta
8
8
  from typing import Any
9
9
 
10
10
  from ..device_type import DeviceType
@@ -318,6 +318,7 @@ class IotStripPlug(IotPlug):
318
318
  self._set_sys_info(parent.sys_info)
319
319
  self._device_type = DeviceType.StripSocket
320
320
  self.protocol = parent.protocol # Must use the same connection as the parent
321
+ self._on_since: datetime | None = None
321
322
 
322
323
  async def _initialize_modules(self):
323
324
  """Initialize modules not added in init."""
@@ -372,7 +373,7 @@ class IotStripPlug(IotPlug):
372
373
  """
373
374
  await self._modular_update({})
374
375
  for module in self._modules.values():
375
- module._post_update_hook()
376
+ await module._post_update_hook()
376
377
 
377
378
  if not self._features:
378
379
  await self._initialize_features()
@@ -438,14 +439,20 @@ class IotStripPlug(IotPlug):
438
439
  def on_since(self) -> datetime | None:
439
440
  """Return on-time, if available."""
440
441
  if self.is_off:
442
+ self._on_since = None
441
443
  return None
442
444
 
443
445
  info = self._get_child_info()
444
446
  on_time = info["on_time"]
445
447
 
446
- return datetime.now(timezone.utc).astimezone().replace(
447
- microsecond=0
448
- ) - timedelta(seconds=on_time)
448
+ time = self._parent.time
449
+
450
+ on_since = time - timedelta(seconds=on_time)
451
+ if not self._on_since or timedelta(
452
+ seconds=0
453
+ ) < on_since - self._on_since > timedelta(seconds=5):
454
+ self._on_since = on_since
455
+ return self._on_since
449
456
 
450
457
  @property # type: ignore
451
458
  @requires_update
@@ -0,0 +1,156 @@
1
+ """Module for io device timezone lookups."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import logging
6
+ from datetime import datetime, tzinfo
7
+
8
+ from ..cachedzoneinfo import CachedZoneInfo
9
+
10
+ _LOGGER = logging.getLogger(__name__)
11
+
12
+
13
+ async def get_timezone(index: int) -> tzinfo:
14
+ """Get the timezone from the index."""
15
+ if index > 109:
16
+ _LOGGER.error(
17
+ "Unexpected index %s not configured as a timezone, defaulting to UTC", index
18
+ )
19
+ return await CachedZoneInfo.get_cached_zone_info("Etc/UTC")
20
+
21
+ name = TIMEZONE_INDEX[index]
22
+ return await CachedZoneInfo.get_cached_zone_info(name)
23
+
24
+
25
+ async def get_timezone_index(name: str) -> int:
26
+ """Return the iot firmware index for a valid IANA timezone key."""
27
+ rev = {val: key for key, val in TIMEZONE_INDEX.items()}
28
+ if name in rev:
29
+ return rev[name]
30
+
31
+ # Try to find a supported timezone matching dst true/false
32
+ zone = await CachedZoneInfo.get_cached_zone_info(name)
33
+ now = datetime.now()
34
+ winter = datetime(now.year, 1, 1, 12)
35
+ summer = datetime(now.year, 7, 1, 12)
36
+ for i in range(110):
37
+ configured_zone = await get_timezone(i)
38
+ if zone.utcoffset(winter) == configured_zone.utcoffset(
39
+ winter
40
+ ) and zone.utcoffset(summer) == configured_zone.utcoffset(summer):
41
+ return i
42
+ raise ValueError("Device does not support timezone %s", name)
43
+
44
+
45
+ TIMEZONE_INDEX = {
46
+ 0: "Etc/GMT+12",
47
+ 1: "Pacific/Samoa",
48
+ 2: "US/Hawaii",
49
+ 3: "US/Alaska",
50
+ 4: "Mexico/BajaNorte",
51
+ 5: "Etc/GMT+8",
52
+ 6: "PST8PDT",
53
+ 7: "US/Arizona",
54
+ 8: "America/Mazatlan",
55
+ 9: "MST",
56
+ 10: "MST7MDT",
57
+ 11: "Mexico/General",
58
+ 12: "Etc/GMT+6",
59
+ 13: "CST6CDT",
60
+ 14: "America/Monterrey",
61
+ 15: "Canada/Saskatchewan",
62
+ 16: "America/Bogota",
63
+ 17: "Etc/GMT+5",
64
+ 18: "EST",
65
+ 19: "America/Indiana/Indianapolis",
66
+ 20: "America/Caracas",
67
+ 21: "America/Asuncion",
68
+ 22: "Etc/GMT+4",
69
+ 23: "Canada/Atlantic",
70
+ 24: "America/Cuiaba",
71
+ 25: "Brazil/West",
72
+ 26: "America/Santiago",
73
+ 27: "Canada/Newfoundland",
74
+ 28: "America/Sao_Paulo",
75
+ 29: "America/Argentina/Buenos_Aires",
76
+ 30: "America/Cayenne",
77
+ 31: "America/Miquelon",
78
+ 32: "America/Montevideo",
79
+ 33: "Chile/Continental",
80
+ 34: "Etc/GMT+2",
81
+ 35: "Atlantic/Azores",
82
+ 36: "Atlantic/Cape_Verde",
83
+ 37: "Africa/Casablanca",
84
+ 38: "UCT",
85
+ 39: "GB",
86
+ 40: "Africa/Monrovia",
87
+ 41: "Europe/Amsterdam",
88
+ 42: "Europe/Belgrade",
89
+ 43: "Europe/Brussels",
90
+ 44: "Europe/Sarajevo",
91
+ 45: "Africa/Lagos",
92
+ 46: "Africa/Windhoek",
93
+ 47: "Asia/Amman",
94
+ 48: "Europe/Athens",
95
+ 49: "Asia/Beirut",
96
+ 50: "Africa/Cairo",
97
+ 51: "Asia/Damascus",
98
+ 52: "EET",
99
+ 53: "Africa/Harare",
100
+ 54: "Europe/Helsinki",
101
+ 55: "Asia/Istanbul",
102
+ 56: "Asia/Jerusalem",
103
+ 57: "Europe/Kaliningrad",
104
+ 58: "Africa/Tripoli",
105
+ 59: "Asia/Baghdad",
106
+ 60: "Asia/Kuwait",
107
+ 61: "Europe/Minsk",
108
+ 62: "Europe/Moscow",
109
+ 63: "Africa/Nairobi",
110
+ 64: "Asia/Tehran",
111
+ 65: "Asia/Muscat",
112
+ 66: "Asia/Baku",
113
+ 67: "Europe/Samara",
114
+ 68: "Indian/Mauritius",
115
+ 69: "Asia/Tbilisi",
116
+ 70: "Asia/Yerevan",
117
+ 71: "Asia/Kabul",
118
+ 72: "Asia/Ashgabat",
119
+ 73: "Asia/Yekaterinburg",
120
+ 74: "Asia/Karachi",
121
+ 75: "Asia/Kolkata",
122
+ 76: "Asia/Colombo",
123
+ 77: "Asia/Kathmandu",
124
+ 78: "Asia/Almaty",
125
+ 79: "Asia/Dhaka",
126
+ 80: "Asia/Novosibirsk",
127
+ 81: "Asia/Rangoon",
128
+ 82: "Asia/Bangkok",
129
+ 83: "Asia/Krasnoyarsk",
130
+ 84: "Asia/Chongqing",
131
+ 85: "Asia/Irkutsk",
132
+ 86: "Asia/Singapore",
133
+ 87: "Australia/Perth",
134
+ 88: "Asia/Taipei",
135
+ 89: "Asia/Ulaanbaatar",
136
+ 90: "Asia/Tokyo",
137
+ 91: "Asia/Seoul",
138
+ 92: "Asia/Yakutsk",
139
+ 93: "Australia/Adelaide",
140
+ 94: "Australia/Darwin",
141
+ 95: "Australia/Brisbane",
142
+ 96: "Australia/Canberra",
143
+ 97: "Pacific/Guam",
144
+ 98: "Australia/Hobart",
145
+ 99: "Antarctica/DumontDUrville",
146
+ 100: "Asia/Magadan",
147
+ 101: "Asia/Srednekolymsk",
148
+ 102: "Etc/GMT-11",
149
+ 103: "Asia/Anadyr",
150
+ 104: "Pacific/Auckland",
151
+ 105: "Etc/GMT-12",
152
+ 106: "Pacific/Fiji",
153
+ 107: "Etc/GMT-13",
154
+ 108: "Pacific/Apia",
155
+ 109: "Etc/GMT-14",
156
+ }
@@ -16,11 +16,11 @@ from ..iotmodule import IotModule, merge
16
16
  class AmbientLight(IotModule):
17
17
  """Implements ambient light controls for the motion sensor."""
18
18
 
19
- def __init__(self, device, module):
20
- super().__init__(device, module)
19
+ def _initialize_features(self):
20
+ """Initialize features after the initial update."""
21
21
  self._add_feature(
22
22
  Feature(
23
- device=device,
23
+ device=self._device,
24
24
  container=self,
25
25
  id="ambient_light",
26
26
  name="Ambient Light",
kasa/iot/modules/cloud.py CHANGED
@@ -24,11 +24,11 @@ class CloudInfo(BaseModel):
24
24
  class Cloud(IotModule):
25
25
  """Module implementing support for cloud services."""
26
26
 
27
- def __init__(self, device, module):
28
- super().__init__(device, module)
27
+ def _initialize_features(self):
28
+ """Initialize features after the initial update."""
29
29
  self._add_feature(
30
30
  Feature(
31
- device=device,
31
+ device=self._device,
32
32
  container=self,
33
33
  id="cloud_connection",
34
34
  name="Cloud connection",
@@ -12,7 +12,7 @@ from .usage import Usage
12
12
  class Emeter(Usage, EnergyInterface):
13
13
  """Emeter module."""
14
14
 
15
- def _post_update_hook(self) -> None:
15
+ async def _post_update_hook(self) -> None:
16
16
  self._supported = EnergyInterface.ModuleFeature.PERIODIC_STATS
17
17
  if (
18
18
  "voltage_mv" in self.data["get_realtime"]
kasa/iot/modules/light.py CHANGED
@@ -239,7 +239,7 @@ class Light(IotModule, LightInterface):
239
239
  """Return the current light state."""
240
240
  return self._light_state
241
241
 
242
- def _post_update_hook(self) -> None:
242
+ async def _post_update_hook(self) -> None:
243
243
  if self._device.is_on is False:
244
244
  state = LightState(light_on=False)
245
245
  else:
@@ -41,7 +41,7 @@ class LightPreset(IotModule, LightPresetInterface):
41
41
  _presets: dict[str, IotLightPreset]
42
42
  _preset_list: list[str]
43
43
 
44
- def _post_update_hook(self):
44
+ async def _post_update_hook(self):
45
45
  """Update the internal presets."""
46
46
  self._presets = {
47
47
  f"Light preset {index+1}": IotLightPreset(**vals)
kasa/iot/modules/time.py CHANGED
@@ -1,14 +1,19 @@
1
1
  """Provides the current time and timezone information."""
2
2
 
3
- from datetime import datetime
3
+ from __future__ import annotations
4
+
5
+ from datetime import datetime, timezone, tzinfo
4
6
 
5
7
  from ...exceptions import KasaException
6
8
  from ..iotmodule import IotModule, merge
9
+ from ..iottimezone import get_timezone
7
10
 
8
11
 
9
12
  class Time(IotModule):
10
13
  """Implements the timezone settings."""
11
14
 
15
+ _timezone: tzinfo = timezone.utc
16
+
12
17
  def query(self):
13
18
  """Request time and timezone."""
14
19
  q = self.query_for_command("get_time")
@@ -16,24 +21,30 @@ class Time(IotModule):
16
21
  merge(q, self.query_for_command("get_timezone"))
17
22
  return q
18
23
 
24
+ async def _post_update_hook(self):
25
+ """Perform actions after a device update."""
26
+ if res := self.data.get("get_timezone"):
27
+ self._timezone = await get_timezone(res.get("index"))
28
+
19
29
  @property
20
30
  def time(self) -> datetime:
21
31
  """Return current device time."""
22
32
  res = self.data["get_time"]
23
- return datetime(
33
+ time = datetime(
24
34
  res["year"],
25
35
  res["month"],
26
36
  res["mday"],
27
37
  res["hour"],
28
38
  res["min"],
29
39
  res["sec"],
40
+ tzinfo=self.timezone,
30
41
  )
42
+ return time
31
43
 
32
44
  @property
33
- def timezone(self):
45
+ def timezone(self) -> tzinfo:
34
46
  """Return current timezone."""
35
- res = self.data["get_timezone"]
36
- return res
47
+ return self._timezone
37
48
 
38
49
  async def get_time(self):
39
50
  """Return current device time."""
kasa/klaptransport.py CHANGED
@@ -88,7 +88,6 @@ class KlapTransport(BaseTransport):
88
88
  """
89
89
 
90
90
  DEFAULT_PORT: int = 80
91
- DISCOVERY_QUERY = {"system": {"get_sysinfo": None}}
92
91
  SESSION_COOKIE_NAME = "TP_SESSIONID"
93
92
  TIMEOUT_COOKIE_NAME = "TIMEOUT"
94
93
 
kasa/module.py CHANGED
@@ -155,7 +155,7 @@ class Module(ABC):
155
155
  children's modules.
156
156
  """
157
157
 
158
- def _post_update_hook(self): # noqa: B027
158
+ async def _post_update_hook(self): # noqa: B027
159
159
  """Perform actions after a device update.
160
160
 
161
161
  This can be implemented if a module needs to perform actions each time
@@ -2,14 +2,9 @@
2
2
 
3
3
  from __future__ import annotations
4
4
 
5
- from typing import TYPE_CHECKING
6
-
7
5
  from ...feature import Feature
8
6
  from ..smartmodule import SmartModule
9
7
 
10
- if TYPE_CHECKING:
11
- from ..smartdevice import SmartDevice
12
-
13
8
 
14
9
  class Cloud(SmartModule):
15
10
  """Implementation of cloud module."""
@@ -18,12 +13,11 @@ class Cloud(SmartModule):
18
13
  REQUIRED_COMPONENT = "cloud_connect"
19
14
  MINIMUM_UPDATE_INTERVAL_SECS = 60
20
15
 
21
- def __init__(self, device: SmartDevice, module: str):
22
- super().__init__(device, module)
23
-
16
+ def _initialize_features(self):
17
+ """Initialize features after the initial update."""
24
18
  self._add_feature(
25
19
  Feature(
26
- device,
20
+ self._device,
27
21
  id="cloud_connection",
28
22
  name="Cloud connection",
29
23
  container=self,
@@ -2,26 +2,21 @@
2
2
 
3
3
  from __future__ import annotations
4
4
 
5
- from typing import TYPE_CHECKING
6
-
7
5
  from ...feature import Feature
8
6
  from ...interfaces.light import HSV
9
7
  from ..smartmodule import SmartModule
10
8
 
11
- if TYPE_CHECKING:
12
- from ..smartdevice import SmartDevice
13
-
14
9
 
15
10
  class Color(SmartModule):
16
11
  """Implementation of color module."""
17
12
 
18
13
  REQUIRED_COMPONENT = "color"
19
14
 
20
- def __init__(self, device: SmartDevice, module: str):
21
- super().__init__(device, module)
15
+ def _initialize_features(self):
16
+ """Initialize features after the initial update."""
22
17
  self._add_feature(
23
18
  Feature(
24
- device,
19
+ self._device,
25
20
  "hsv",
26
21
  "HSV",
27
22
  container=self,
@@ -2,14 +2,9 @@
2
2
 
3
3
  from __future__ import annotations
4
4
 
5
- from typing import TYPE_CHECKING
6
-
7
5
  from ...feature import Feature
8
6
  from ..smartmodule import SmartModule
9
7
 
10
- if TYPE_CHECKING:
11
- from ..smartdevice import SmartDevice
12
-
13
8
 
14
9
  class ContactSensor(SmartModule):
15
10
  """Implementation of contact sensor module."""
@@ -17,11 +12,11 @@ class ContactSensor(SmartModule):
17
12
  REQUIRED_COMPONENT = None # we depend on availability of key
18
13
  REQUIRED_KEY_ON_PARENT = "open"
19
14
 
20
- def __init__(self, device: SmartDevice, module: str):
21
- super().__init__(device, module)
15
+ def _initialize_features(self):
16
+ """Initialize features after the initial update."""
22
17
  self._add_feature(
23
18
  Feature(
24
- device,
19
+ self._device,
25
20
  id="is_open",
26
21
  name="Open",
27
22
  container=self,