8000 Move feature initialization from __init__ to _initialize_features by rytilahti · Pull Request #1140 · python-kasa/python-kasa · GitHub
[go: up one dir, main page]

Skip to content

Move feature initialization from __init__ to _initialize_features #1140

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions kasa/iot/modules/ambientlight.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
class AmbientLight(IotModule):
"""Implements ambient light controls for the motion sensor."""

def __init__(self, device, module):
super().__init__(device, module)
def _initialize_features(self):
"""Initialize features after the initial update."""
self._add_feature(
Feature(
device=device,
device=self._device,
container=self,
id="ambient_light",
name="Ambient Light",
Expand Down
6 changes: 3 additions & 3 deletions kasa/iot/modules/cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ class CloudInfo(BaseModel):
class Cloud(IotModule):
"""Module implementing support for cloud services."""

def __init__(self, device, module):
super().__init__(device, module)
def _initialize_features(self):
10000 """Initialize features after the initial update."""
self._add_feature(
Feature(
device=device,
device=self._device,
container=self,
id="cloud_connection",
name="Cloud connection",
Expand Down
12 changes: 3 additions & 9 deletions kasa/smart/modules/cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,9 @@

from __future__ import annotations

from typing import TYPE_CHECKING

from ...feature import Feature
from ..smartmodule import SmartModule

if TYPE_CHECKING:
from ..smartdevice import SmartDevice


class Cloud(SmartModule):
"""Implementation of cloud module."""
Expand All @@ -18,12 +13,11 @@ class Cloud(SmartModule):
REQUIRED_COMPONENT = "cloud_connect"
MINIMUM_UPDATE_INTERVAL_SECS = 60

def __init__(self, device: SmartDevice, module: str):
super().__init__(device, module)

def _initialize_features(self):
"""Initialize features after the initial update."""
self._add_feature(
Feature(
device,
self._device,
id="cloud_connection",
name="Cloud connection",
container=self,
Expand Down
11 changes: 3 additions & 8 deletions kasa/smart/modules/color.py
8000
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,21 @@

from __future__ import annotations

from typing import TYPE_CHECKING

from ...feature import Feature
from ...interfaces.light import HSV
from ..smartmodule import SmartModule

if TYPE_CHECKING:
from ..smartdevice import SmartDevice


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

REQUIRED_COMPONENT = "color"

def __init__(self, device: SmartDevice, module: str):
super().__init__(device, module)
def _initialize_features(self):
"""Initialize features after the initial update."""
self._add_feature(
Feature(
device,
self._device,
"hsv",
"HSV",
container=self,
Expand Down
11 changes: 3 additions & 8 deletions kasa/smart/modules/contactsensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,21 @@

from __future__ import annotations

from typin 8000 g import TYPE_CHECKING

from ...feature import Feature
from ..smartmodule import SmartModule

if TYPE_CHECKING:
from ..smartdevice import SmartDevice


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

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

def __init__(self, device: SmartDevice, module: str):
super().__init__(device, module)
def _initialize_features(self):
"""Initialize features after the initial update."""
self._add_feature(
Feature(
device,
self._device,
id="is_open",
name="Open",
container=self,
Expand Down
14 changes: 4 additions & 10 deletions kasa/smart/modules/fan.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,21 @@

from __future__ import annotations

from typing import TYPE_CHECKING

from ...feature import Feature
from ...interfaces.fan import Fan as FanInterface
from ..smartmodule import SmartModule

if TYPE_CHECKING:
from ..smartdevice import SmartDevice


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

REQUIRED_COMPONENT = "fan_control"

def __init__(self, device: SmartDevice, module: str):
super().__init__(device, module)

def _initialize_features(self):
"""Initialize features after the initial update."""
self._add_feature(
Feature(
device,
self._device,
id="fan_speed_level",
name="Fan speed level",
container=self,
Expand All @@ -36,7 +30,7 @@ def __init__(self, device: SmartDevice, module: str):
)
self._add_feature(
Feature(
device,
self._device,
id="fan_sleep_mode",
name="Fan sleep mode",
container=self,
Expand Down
13 changes: 4 additions & 9 deletions kasa/smart/modules/humiditysensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,21 @@

from __future__ import annotations

from typing import TYPE_CHECKING

from ...feature import Feature
from ..smartmodule import SmartModule

if TYPE_CHECKING:
from ..smartdevice import SmartDevice


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

REQUIRED_COMPONENT = "humidity"
QUERY_GETTER_NAME = "get_comfort_humidity_config"

def __init__(self, device: SmartDevice, module: str):
super().__init__(device, module)
def _initialize_features(self):
"""Initialize features after the initial update."""
self._add_feature(
Feature(
device,
self._device,
id="humidity",
name="Humidity",
container=self,
Expand All @@ -34,7 +29,7 @@ def __init__(self, device: SmartDevice, module: str):
)
self._add_feature(
Feature(
device,
self._device,
id="humidity_warning",
name="Humidity warning",
container=self,
Expand Down
11 changes: 3 additions & 8 deletions kasa/smart/modules/reportmode.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,21 @@

from __future__ import annotations

from typing import TYPE_CHECKING

from ...feature import Feature
from ..smartmodule import SmartModule

if TYPE_CHECKING:
from ..smartdevice import SmartDevice


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

REQUIRED_COMPONENT = "report_mode"
QUERY_GETTER_NAME = "get_report_mode"

def __init__(self, device: SmartDevice, module: str):
super().__init__(device, module)
def _initialize_features(self):
"""Initialize features after the initial update."""
self._add_feature(
Feature(
device,
self._device,
id="report_interval",
name="Report interval",
container=self,
Expand Down
17 changes: 7 additions & 10 deletions kasa/smart/modules/temperaturesensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,23 @@

from __future__ import annotations

from typing import TYPE_CHECKING, Literal
from typing import Literal

from ...feature import Feature
from ..smartmodule import SmartModule

if TYPE_CHECKING:
from ..smartdevice import SmartDevice


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

REQUIRED_COMPONENT = "temperature"
QUERY_GETTER_NAME = "get_comfort_temp_config"

def __init__(self, device: SmartDevice, module: str):
super().__init__(device, module)
def _initialize_features(self):
"""Initialize features after the initial update."""
self._add_feature(
Feature(
device,
self._device,
id="temperature",
name="Temperature",
container=self,
Expand All @@ -32,10 +29,10 @@ def __init__(self, device: SmartDevice, module: str):
type=Feature.Type.Sensor,
)
)
if "current_temp_exception" in device.sys_info:
if "current_temp_exception" in self._device.sys_info:
self._add_feature(
Feature(
device,
self._device,
id="temperature_warning",
name="Temperature warning",
container=self,
Expand All @@ -47,7 +44,7 @@ def __init__(self, device: SmartDevice, module: str):
)
self._add_feature(
Feature(
device,
self._device,
id="temperature_unit",
name="Temperature unit",
container=self,
Expand Down
12 changes: 4 additions & 8 deletions kasa/smart/modules/time.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,23 @@

from datetime import datetime, timedelta, timezone
from time import mktime
from typing import TYPE_CHECKING, cast
from typing import cast

from ...feature import Feature
from ..smartmodule import SmartModule

if TYPE_CHECKING:
from ..smartdevice import SmartDevice


class Time(SmartModule):
"""Implementation of device_local_time."""

REQUIRED_COMPONENT = "time"
QUERY_GETTER_NAME = "get_device_time"

def __init__(self, device: SmartDevice, module: str):
super().__init__(device, module)

def _initialize_features(self):
"""Initialize features after the initial update."""
self._add_feature(
Feature(
device=device,
device=self._device,
id="device_time",
name="Device time",
attribute_getter="time",
Expand Down
12 changes: 4 additions & 8 deletions kasa/smart/modules/waterleaksensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,10 @@
from __future__ import annotations

from enum import Enum
from typing import TYPE_CHECKING

from ...feature import Feature
from ..smartmodule import SmartModule

if TYPE_CHECKING:
from ..smartdevice import SmartDevice


class WaterleakStatus(Enum):
"""Waterleawk status."""
Expand All @@ -25,11 +21,11 @@ class WaterleakSensor(SmartModule):

REQUIRED_COMPONENT = "sensor_alarm"

def __init__(self, device: SmartDevice, module: str):
super().__init__(device, module)
def _initialize_features(self):
"""Initialize features after the initial update."""
self._add_feature(
Feature(
device,
self._device,
id="water_leak",
name="Water leak",
container=self,
Expand All @@ -41,7 +37,7 @@ def __init__(self, device: SmartDevice, module: str):
)
self._add_feature(
Feature(
device,
self._device,
id="water_alert",
name="Water alert",
container=self,
Expand Down
Loading
0