8000 Move feature initialization from __init__ to _initialize_features (#1… · msz-coder/python-kasa@d897503 · GitHub
[go: up one dir, main page]

Skip to content

Commit d897503

Browse files
authored
Move feature initialization from __init__ to _initialize_features (python-kasa#1140)
1 parent 2922c3f commit d897503

11 files changed

+41
-84
lines changed

kasa/iot/modules/ambientlight.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616
class AmbientLight(IotModule):
1717
"""Implements ambient light controls for the motion sensor."""
1818

19-
def __init__(self, device, module):
20-
super().__init__(device, module)
19+
def _initialize_features(self):
20+
"""Initialize features after the initial update."""
2121
self._add_feature(
2222
Feature(
23-
device=device,
23+
device=self._device,
2424
container=self,
2525
id="ambient_light",
2626
name="Ambient Light",

kasa/iot/modules/cloud.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ class CloudInfo(BaseModel):
2424
class Cloud(IotModule):
2525
"""Module implementing support for cloud services."""
2626

27-
def __init__(self, device, module):
28-
super().__init__(device, module)
27+
def _initialize_features(self):
28+
"""Initialize features after the initial update."""
2929
self._add_feature(
3030
Feature(
31-
device=device,
31+
device=self._device,
3232
container=self,
3333
id="cloud_connection",
3434
name="Cloud connection",

kasa/smart/modules/cloud.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,9 @@
22

33
from __future__ import annotations
44

5-
from typing import TYPE_CHECKING
6-
75
from ...feature import Feature
86
from ..smartmodule import SmartModule
97

10-
if TYPE_CHECKING:
11-
from ..smartdevice import SmartDevice
12-
138

149
class Cloud(SmartModule):
1510
"""Implementation of cloud module."""
@@ -18,12 +13,11 @@ class Cloud(SmartModule):
1813
REQUIRED_COMPONENT = "cloud_connect"
1914
MINIMUM_UPDATE_INTERVAL_SECS = 60
2015

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."""
2418
self._add_feature(
2519
Feature(
26-
device,
20+
self._device,
2721
id="cloud_connection",
2822
name="Cloud connection",
2923
container=self,

kasa/smart/modules/color.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,21 @@
22

33
from __future__ import annotations
44

5-
from typing import TYPE_CHECKING
6-
75
from ...feature import Feature
86
from ...interfaces.light import HSV
97
from ..smartmodule import SmartModule
108

11-
if TYPE_CHECKING:
12-
from ..smartdevice import SmartDevice
13-
149

1510
class Color(SmartModule):
1611
"""Implementation of color module."""
1712

1813
REQUIRED_COMPONENT = "color"
1914

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."""
2217
self._add_feature(
2318
Feature(
24-
device,
19+
self._device,
2520
"hsv",
2621
"HSV",
2722
container=self,

kasa/smart/modules/contactsensor.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,21 @@
22

33
from __future__ import annotations
44

5-
from typing import TYPE_CHECKING
6-
75
from ...feature import Feature
86
from ..smartmodule import SmartModule
97

10-
if TYPE_CHECKING:
11-
from ..smartdevice import SmartDevice
12-
138

149
class ContactSensor(SmartModule):
1510
"""Implementation of contact sensor module."""
1611

1712
REQUIRED_COMPONENT = None # we depend on availability of key
1813
REQUIRED_KEY_ON_PARENT = "open"
1914

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."""
2217
self._add_feature(
2318
Feature(
24-
device,
19+
self._device,
2520
id="is_open",
2621
name="Open",
2722
container=self,

kasa/smart/modules/fan.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,21 @@
22

33
from __future__ import annotations
44

5-
from typing import TYPE_CHECKING
6-
75
from ...feature import Feature
86
from ...interfaces.fan import Fan as FanInterface
97from ..smartmodule import SmartModule
108

11-
if TYPE_CHECKING:
12-
from ..smartdevice import SmartDevice
13-
149

1510
class Fan(SmartModule, FanInterface):
1611
"""Implementation of fan_control module."""
1712

1813
REQUIRED_COMPONENT = "fan_control"
1914

20-
def __init__(self, device: SmartDevice, module: str):
21-
super().__init__(device, module)
22-
15+
def _initialize_features(self):
16+
"""Initialize features after the initial update."""
2317
self._add_feature(
2418
Feature(
25-
device,
19+
self._device,
2620
id="fan_speed_level",
2721
name="Fan speed level",
2822
container=self,
@@ -36,7 +30,7 @@ def __init__(self, device: SmartDevice, module: str):
3630
)
3731
self._add_feature(
3832
Feature(
39-
device,
33+
self._device,
4034
id="fan_sleep_mode",
4135
name="Fan sleep mode",
4236
container=self,

kasa/smart/modules/humiditysensor.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,21 @@
22

33
from __future__ import annotations
44

5-
from typing import TYPE_CHECKING
6-
75
from ...feature import Feature
86
from ..smartmodule import SmartModule
97

10-
if TYPE_CHECKING:
11-
from ..smartdevice import SmartDevice
12-
138

149
class HumiditySensor(SmartModule):
1510
"""Implementation of humidity module."""
1611

1712
REQUIRED_COMPONENT = "humidity"
1813
QUERY_GETTER_NAME = "get_comfort_humidity_config"
1914

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."""
2217
self._add_feature(
2318
Feature(
24-
device,
19+
self._device,
2520
id="humidity",
2621
name="Humidity",
2722
container=self,
@@ -34,7 +29,7 @@ def __init__(self, device: SmartDevice, module: str):
3429
)
3530
self._add_feature(
3631
Feature(
37-
device,
32+
self._device,
3833
id="humidity_warning",
3934
name="Humidity warning",
4035
container=self,

kasa/smart/modules/reportmode.py

Expand all lines: kasa/smart/modules/reportmode.py
Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,21 @@
22

33
from __future__ import annotations
44

5-
from typing import TYPE_CHECKING
6-
75
from ...feature import Feature
86
from ..smartmodule import SmartModule
97

10-
if TYPE_CHECKING:
11-
from ..smartdevice import SmartDevice
12-
138

149
class ReportMode(SmartModule):
1510
"""Implementation of report module."""
1611

1712
REQUIRED_COMPONENT = "report_mode"
1813
QUERY_GETTER_NAME = "get_report_mode"
1914

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."""
2217
self._add_feature(
2318
Feature(
24-
device,
19+
self._device,
2520
id="report_interval",
2621
name="Report interval",
2722
container=self,

kasa/smart/modules/temperaturesensor.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,23 @@
22

33
from __future__ import annotations
44

5-
from typing import TYPE_CHECKING, Literal
5+
from typing import Literal
66

77
from ...feature import Feature
88
from ..smartmodule import SmartModule
99

10-
if TYPE_CHECKING:
11-
from ..smartdevice import SmartDevice
12-
1310

1411
class TemperatureSensor(SmartModule):
1512
"""Implementation of temperature module."""
1613

1714
REQUIRED_COMPONENT = "temperature"
1815
QUERY_GETTER_NAME = "get_comfort_temp_config"
1916

20-
def __init__(self, device: SmartDevice, module: str):
21-
super().__init__(device, module)
17+
def _initialize_features(self):
18+
"""Initialize features after the initial update."""
2219
self._add_feature(
2320
Feature(
24-
device,
21+
self._device,
2522
id="temperature",
2623
name="Temperature",
2724
container=self,
@@ -32,10 +29,10 @@ def __init__(self, device: SmartDevice, module: str):
3229
type=Feature.Type.Sensor,
3330
)
3431
)
35-
if "current_temp_exception" in device.sys_info:
32+
if "current_temp_exception" in self._device.sys_info:
3633
self._add_feature(
3734
Feature(
38-
device,
35+
self._device,
3936
id="temperature_warning",
4037
name="Temperature warning",
4138
container=self,
@@ -47,7 +44,7 @@ def __init__(self, device: SmartDevice, module: str):
4744
)
4845
self._add_feature(
4946
Feature(
50-
device,
47+
self._device,
5148
id="temperature_unit",
5249
name="Temperature unit",
5350
container=self,

kasa/smart/modules/time.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,23 @@
44

55
from datetime import datetime, timedelta, timezone
66
from time import mktime
7-
from typing import TYPE_CHECKING, cast
7+
from typing import cast
88

99
from ...feature import Feature
1010
from ..smartmodule import SmartModule
1111

12-
if TYPE_CHECKING:
13-
from ..smartdevice import SmartDevice
14-
1512

1613
class Time(SmartModule):
1714
"""Implementation of device_local_time."""
1815

1916
REQUIRED_COMPONENT = "time"
2017
QUERY_GETTER_NAME = "get_device_time"
2118

22-
def __init__(self, device: SmartDevice, module: str):
23-
super().__init__(device, module)
24-
19+
def _initialize_features(self):
20+
"""Initialize features after the initial update."""
2521
self._add_feature(
2622
Feature(
27-
device=device,
23+
device=self._device,
2824
id="device_time",
2925
name="Device time",
3026
attribute_getter="time",

kasa/smart/modules/waterleaksensor.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,10 @@
33
from __future__ import annotations
44

55
from enum import Enum
6-
from typing import TYPE_CHECKING
76

87
from ...feature import Feature
98
from ..smartmodule import SmartModule
109

11-
if TYPE_CHECKING:
12-
from ..smartdevice import SmartDevice
13-
1410

1511
class WaterleakStatus(Enum):
1612
"""Waterleawk status."""
@@ -25,11 +21,11 @@ class WaterleakSensor(SmartModule):
2521

2622
REQUIRED_COMPONENT = "sensor_alarm"
2723

28-
def __init__(self, device: SmartDevice, module: str):
29-
super().__init__(device, module)
24+
def _initialize_features(self):
25+
"""Initialize features after the initial update."""
3026
self._add_feature(
3127
Feature(
32-
device,
28+
self._device,
3329
id="water_leak",
3430
name="Water leak",
3531
container=self,
@@ -41,7 +37,7 @@ def __init__(self, device: SmartDevice, module: str):
4137
)
4238
self._add_feature(
4339
Feature(
44-
device,
40+
self._device,
4541
id="water_alert",
4642
name="Water alert",
4743
container=self,

0 commit comments

Comments
 (0)
0