mirror of
https://github.com/python-kasa/python-kasa.git
synced 2024-12-22 19:23:34 +00:00
Move feature initialization from __init__ to _initialize_features (#1140)
This commit is contained in:
parent
2922c3f574
commit
d897503b58
@ -16,11 +16,11 @@ from ..iotmodule import IotModule, merge
|
|||||||
class AmbientLight(IotModule):
|
class AmbientLight(IotModule):
|
||||||
"""Implements ambient light controls for the motion sensor."""
|
"""Implements ambient light controls for the motion sensor."""
|
||||||
|
|
||||||
def __init__(self, device, module):
|
def _initialize_features(self):
|
||||||
super().__init__(device, module)
|
"""Initialize features after the initial update."""
|
||||||
self._add_feature(
|
self._add_feature(
|
||||||
Feature(
|
Feature(
|
||||||
device=device,
|
device=self._device,
|
||||||
container=self,
|
container=self,
|
||||||
id="ambient_light",
|
id="ambient_light",
|
||||||
name="Ambient Light",
|
name="Ambient Light",
|
||||||
|
@ -24,11 +24,11 @@ class CloudInfo(BaseModel):
|
|||||||
class Cloud(IotModule):
|
class Cloud(IotModule):
|
||||||
"""Module implementing support for cloud services."""
|
"""Module implementing support for cloud services."""
|
||||||
|
|
||||||
def __init__(self, device, module):
|
def _initialize_features(self):
|
||||||
super().__init__(device, module)
|
"""Initialize features after the initial update."""
|
||||||
self._add_feature(
|
self._add_feature(
|
||||||
Feature(
|
Feature(
|
||||||
device=device,
|
device=self._device,
|
||||||
container=self,
|
container=self,
|
||||||
id="cloud_connection",
|
id="cloud_connection",
|
||||||
name="Cloud connection",
|
name="Cloud connection",
|
||||||
|
@ -2,14 +2,9 @@
|
|||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from typing import TYPE_CHECKING
|
|
||||||
|
|
||||||
from ...feature import Feature
|
from ...feature import Feature
|
||||||
from ..smartmodule import SmartModule
|
from ..smartmodule import SmartModule
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
|
||||||
from ..smartdevice import SmartDevice
|
|
||||||
|
|
||||||
|
|
||||||
class Cloud(SmartModule):
|
class Cloud(SmartModule):
|
||||||
"""Implementation of cloud module."""
|
"""Implementation of cloud module."""
|
||||||
@ -18,12 +13,11 @@ class Cloud(SmartModule):
|
|||||||
REQUIRED_COMPONENT = "cloud_connect"
|
REQUIRED_COMPONENT = "cloud_connect"
|
||||||
MINIMUM_UPDATE_INTERVAL_SECS = 60
|
MINIMUM_UPDATE_INTERVAL_SECS = 60
|
||||||
|
|
||||||
def __init__(self, device: SmartDevice, module: str):
|
def _initialize_features(self):
|
||||||
super().__init__(device, module)
|
"""Initialize features after the initial update."""
|
||||||
|
|
||||||
self._add_feature(
|
self._add_feature(
|
||||||
Feature(
|
Feature(
|
||||||
device,
|
self._device,
|
||||||
id="cloud_connection",
|
id="cloud_connection",
|
||||||
name="Cloud connection",
|
name="Cloud connection",
|
||||||
container=self,
|
container=self,
|
||||||
|
@ -2,26 +2,21 @@
|
|||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from typing import TYPE_CHECKING
|
|
||||||
|
|
||||||
from ...feature import Feature
|
from ...feature import Feature
|
||||||
from ...interfaces.light import HSV
|
from ...interfaces.light import HSV
|
||||||
from ..smartmodule import SmartModule
|
from ..smartmodule import SmartModule
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
|
||||||
from ..smartdevice import SmartDevice
|
|
||||||
|
|
||||||
|
|
||||||
class Color(SmartModule):
|
class Color(SmartModule):
|
||||||
"""Implementation of color module."""
|
"""Implementation of color module."""
|
||||||
|
|
||||||
REQUIRED_COMPONENT = "color"
|
REQUIRED_COMPONENT = "color"
|
||||||
|
|
||||||
def __init__(self, device: SmartDevice, module: str):
|
def _initialize_features(self):
|
||||||
super().__init__(device, module)
|
"""Initialize features after the initial update."""
|
||||||
self._add_feature(
|
self._add_feature(
|
||||||
Feature(
|
Feature(
|
||||||
device,
|
self._device,
|
||||||
"hsv",
|
"hsv",
|
||||||
"HSV",
|
"HSV",
|
||||||
container=self,
|
container=self,
|
||||||
|
@ -2,14 +2,9 @@
|
|||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from typing import TYPE_CHECKING
|
|
||||||
|
|
||||||
from ...feature import Feature
|
from ...feature import Feature
|
||||||
from ..smartmodule import SmartModule
|
from ..smartmodule import SmartModule
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
|
||||||
from ..smartdevice import SmartDevice
|
|
||||||
|
|
||||||
|
|
||||||
class ContactSensor(SmartModule):
|
class ContactSensor(SmartModule):
|
||||||
"""Implementation of contact sensor module."""
|
"""Implementation of contact sensor module."""
|
||||||
@ -17,11 +12,11 @@ class ContactSensor(SmartModule):
|
|||||||
REQUIRED_COMPONENT = None # we depend on availability of key
|
REQUIRED_COMPONENT = None # we depend on availability of key
|
||||||
REQUIRED_KEY_ON_PARENT = "open"
|
REQUIRED_KEY_ON_PARENT = "open"
|
||||||
|
|
||||||
def __init__(self, device: SmartDevice, module: str):
|
def _initialize_features(self):
|
||||||
super().__init__(device, module)
|
"""Initialize features after the initial update."""
|
||||||
self._add_feature(
|
self._add_feature(
|
||||||
Feature(
|
Feature(
|
||||||
device,
|
self._device,
|
||||||
id="is_open",
|
id="is_open",
|
||||||
name="Open",
|
name="Open",
|
||||||
container=self,
|
container=self,
|
||||||
|
@ -2,27 +2,21 @@
|
|||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from typing import TYPE_CHECKING
|
|
||||||
|
|
||||||
from ...feature import Feature
|
from ...feature import Feature
|
||||||
from ...interfaces.fan import Fan as FanInterface
|
from ...interfaces.fan import Fan as FanInterface
|
||||||
from ..smartmodule import SmartModule
|
from ..smartmodule import SmartModule
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
|
||||||
from ..smartdevice import SmartDevice
|
|
||||||
|
|
||||||
|
|
||||||
class Fan(SmartModule, FanInterface):
|
class Fan(SmartModule, FanInterface):
|
||||||
"""Implementation of fan_control module."""
|
"""Implementation of fan_control module."""
|
||||||
|
|
||||||
REQUIRED_COMPONENT = "fan_control"
|
REQUIRED_COMPONENT = "fan_control"
|
||||||
|
|
||||||
def __init__(self, device: SmartDevice, module: str):
|
def _initialize_features(self):
|
||||||
super().__init__(device, module)
|
"""Initialize features after the initial update."""
|
||||||
|
|
||||||
self._add_feature(
|
self._add_feature(
|
||||||
Feature(
|
Feature(
|
||||||
device,
|
self._device,
|
||||||
id="fan_speed_level",
|
id="fan_speed_level",
|
||||||
name="Fan speed level",
|
name="Fan speed level",
|
||||||
container=self,
|
container=self,
|
||||||
@ -36,7 +30,7 @@ class Fan(SmartModule, FanInterface):
|
|||||||
)
|
)
|
||||||
self._add_feature(
|
self._add_feature(
|
||||||
Feature(
|
Feature(
|
||||||
device,
|
self._device,
|
||||||
id="fan_sleep_mode",
|
id="fan_sleep_mode",
|
||||||
name="Fan sleep mode",
|
name="Fan sleep mode",
|
||||||
container=self,
|
container=self,
|
||||||
|
@ -2,14 +2,9 @@
|
|||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from typing import TYPE_CHECKING
|
|
||||||
|
|
||||||
from ...feature import Feature
|
from ...feature import Feature
|
||||||
from ..smartmodule import SmartModule
|
from ..smartmodule import SmartModule
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
|
||||||
from ..smartdevice import SmartDevice
|
|
||||||
|
|
||||||
|
|
||||||
class HumiditySensor(SmartModule):
|
class HumiditySensor(SmartModule):
|
||||||
"""Implementation of humidity module."""
|
"""Implementation of humidity module."""
|
||||||
@ -17,11 +12,11 @@ class HumiditySensor(SmartModule):
|
|||||||
REQUIRED_COMPONENT = "humidity"
|
REQUIRED_COMPONENT = "humidity"
|
||||||
QUERY_GETTER_NAME = "get_comfort_humidity_config"
|
QUERY_GETTER_NAME = "get_comfort_humidity_config"
|
||||||
|
|
||||||
def __init__(self, device: SmartDevice, module: str):
|
def _initialize_features(self):
|
||||||
super().__init__(device, module)
|
"""Initialize features after the initial update."""
|
||||||
self._add_feature(
|
self._add_feature(
|
||||||
Feature(
|
Feature(
|
||||||
device,
|
self._device,
|
||||||
id="humidity",
|
id="humidity",
|
||||||
name="Humidity",
|
name="Humidity",
|
||||||
container=self,
|
container=self,
|
||||||
@ -34,7 +29,7 @@ class HumiditySensor(SmartModule):
|
|||||||
)
|
)
|
||||||
self._add_feature(
|
self._add_feature(
|
||||||
Feature(
|
Feature(
|
||||||
device,
|
self._device,
|
||||||
id="humidity_warning",
|
id="humidity_warning",
|
||||||
name="Humidity warning",
|
name="Humidity warning",
|
||||||
container=self,
|
container=self,
|
||||||
|
@ -2,14 +2,9 @@
|
|||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from typing import TYPE_CHECKING
|
|
||||||
|
|
||||||
from ...feature import Feature
|
from ...feature import Feature
|
||||||
from ..smartmodule import SmartModule
|
from ..smartmodule import SmartModule
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
|
||||||
from ..smartdevice import SmartDevice
|
|
||||||
|
|
||||||
|
|
||||||
class ReportMode(SmartModule):
|
class ReportMode(SmartModule):
|
||||||
"""Implementation of report module."""
|
"""Implementation of report module."""
|
||||||
@ -17,11 +12,11 @@ class ReportMode(SmartModule):
|
|||||||
REQUIRED_COMPONENT = "report_mode"
|
REQUIRED_COMPONENT = "report_mode"
|
||||||
QUERY_GETTER_NAME = "get_report_mode"
|
QUERY_GETTER_NAME = "get_report_mode"
|
||||||
|
|
||||||
def __init__(self, device: SmartDevice, module: str):
|
def _initialize_features(self):
|
||||||
super().__init__(device, module)
|
"""Initialize features after the initial update."""
|
||||||
self._add_feature(
|
self._add_feature(
|
||||||
Feature(
|
Feature(
|
||||||
device,
|
self._device,
|
||||||
id="report_interval",
|
id="report_interval",
|
||||||
name="Report interval",
|
name="Report interval",
|
||||||
container=self,
|
container=self,
|
||||||
|
@ -2,14 +2,11 @@
|
|||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from typing import TYPE_CHECKING, Literal
|
from typing import Literal
|
||||||
|
|
||||||
from ...feature import Feature
|
from ...feature import Feature
|
||||||
from ..smartmodule import SmartModule
|
from ..smartmodule import SmartModule
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
|
||||||
from ..smartdevice import SmartDevice
|
|
||||||
|
|
||||||
|
|
||||||
class TemperatureSensor(SmartModule):
|
class TemperatureSensor(SmartModule):
|
||||||
"""Implementation of temperature module."""
|
"""Implementation of temperature module."""
|
||||||
@ -17,11 +14,11 @@ class TemperatureSensor(SmartModule):
|
|||||||
REQUIRED_COMPONENT = "temperature"
|
REQUIRED_COMPONENT = "temperature"
|
||||||
QUERY_GETTER_NAME = "get_comfort_temp_config"
|
QUERY_GETTER_NAME = "get_comfort_temp_config"
|
||||||
|
|
||||||
def __init__(self, device: SmartDevice, module: str):
|
def _initialize_features(self):
|
||||||
super().__init__(device, module)
|
"""Initialize features after the initial update."""
|
||||||
self._add_feature(
|
self._add_feature(
|
||||||
Feature(
|
Feature(
|
||||||
device,
|
self._device,
|
||||||
id="temperature",
|
id="temperature",
|
||||||
name="Temperature",
|
name="Temperature",
|
||||||
container=self,
|
container=self,
|
||||||
@ -32,10 +29,10 @@ class TemperatureSensor(SmartModule):
|
|||||||
type=Feature.Type.Sensor,
|
type=Feature.Type.Sensor,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
if "current_temp_exception" in device.sys_info:
|
if "current_temp_exception" in self._device.sys_info:
|
||||||
self._add_feature(
|
self._add_feature(
|
||||||
Feature(
|
Feature(
|
||||||
device,
|
self._device,
|
||||||
id="temperature_warning",
|
id="temperature_warning",
|
||||||
name="Temperature warning",
|
name="Temperature warning",
|
||||||
container=self,
|
container=self,
|
||||||
@ -47,7 +44,7 @@ class TemperatureSensor(SmartModule):
|
|||||||
)
|
)
|
||||||
self._add_feature(
|
self._add_feature(
|
||||||
Feature(
|
Feature(
|
||||||
device,
|
self._device,
|
||||||
id="temperature_unit",
|
id="temperature_unit",
|
||||||
name="Temperature unit",
|
name="Temperature unit",
|
||||||
container=self,
|
container=self,
|
||||||
|
@ -4,14 +4,11 @@ from __future__ import annotations
|
|||||||
|
|
||||||
from datetime import datetime, timedelta, timezone
|
from datetime import datetime, timedelta, timezone
|
||||||
from time import mktime
|
from time import mktime
|
||||||
from typing import TYPE_CHECKING, cast
|
from typing import cast
|
||||||
|
|
||||||
from ...feature import Feature
|
from ...feature import Feature
|
||||||
from ..smartmodule import SmartModule
|
from ..smartmodule import SmartModule
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
|
||||||
from ..smartdevice import SmartDevice
|
|
||||||
|
|
||||||
|
|
||||||
class Time(SmartModule):
|
class Time(SmartModule):
|
||||||
"""Implementation of device_local_time."""
|
"""Implementation of device_local_time."""
|
||||||
@ -19,12 +16,11 @@ class Time(SmartModule):
|
|||||||
REQUIRED_COMPONENT = "time"
|
REQUIRED_COMPONENT = "time"
|
||||||
QUERY_GETTER_NAME = "get_device_time"
|
QUERY_GETTER_NAME = "get_device_time"
|
||||||
|
|
||||||
def __init__(self, device: SmartDevice, module: str):
|
def _initialize_features(self):
|
||||||
super().__init__(device, module)
|
"""Initialize features after the initial update."""
|
||||||
|
|
||||||
self._add_feature(
|
self._add_feature(
|
||||||
Feature(
|
Feature(
|
||||||
device=device,
|
device=self._device,
|
||||||
id="device_time",
|
id="device_time",
|
||||||
name="Device time",
|
name="Device time",
|
||||||
attribute_getter="time",
|
attribute_getter="time",
|
||||||
|
@ -3,14 +3,10 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
from typing import TYPE_CHECKING
|
|
||||||
|
|
||||||
from ...feature import Feature
|
from ...feature import Feature
|
||||||
from ..smartmodule import SmartModule
|
from ..smartmodule import SmartModule
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
|
||||||
from ..smartdevice import SmartDevice
|
|
||||||
|
|
||||||
|
|
||||||
class WaterleakStatus(Enum):
|
class WaterleakStatus(Enum):
|
||||||
"""Waterleawk status."""
|
"""Waterleawk status."""
|
||||||
@ -25,11 +21,11 @@ class WaterleakSensor(SmartModule):
|
|||||||
|
|
||||||
REQUIRED_COMPONENT = "sensor_alarm"
|
REQUIRED_COMPONENT = "sensor_alarm"
|
||||||
|
|
||||||
def __init__(self, device: SmartDevice, module: str):
|
def _initialize_features(self):
|
||||||
super().__init__(device, module)
|
"""Initialize features after the initial update."""
|
||||||
self._add_feature(
|
self._add_feature(
|
||||||
Feature(
|
Feature(
|
||||||
device,
|
self._device,
|
||||||
id="water_leak",
|
id="water_leak",
|
||||||
name="Water leak",
|
name="Water leak",
|
||||||
container=self,
|
container=self,
|
||||||
@ -41,7 +37,7 @@ class WaterleakSensor(SmartModule):
|
|||||||
)
|
)
|
||||||
self._add_feature(
|
self._add_feature(
|
||||||
Feature(
|
Feature(
|
||||||
device,
|
self._device,
|
||||||
id="water_alert",
|
id="water_alert",
|
||||||
name="Water alert",
|
name="Water alert",
|
||||||
container=self,
|
container=self,
|
||||||
|
Loading…
Reference in New Issue
Block a user