Move feature initialization from __init__ to _initialize_features (#1140)

This commit is contained in:
Teemu R. 2024-09-28 20:14:31 +02:00 committed by GitHub
parent 2922c3f574
commit d897503b58
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
11 changed files with 41 additions and 84 deletions

View File

@ -16,11 +16,11 @@ from ..iotmodule import IotModule, merge
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",

View File

@ -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):
"""Initialize features after the initial update."""
self._add_feature(
Feature(
device=device,
device=self._device,
container=self,
id="cloud_connection",
name="Cloud connection",

View File

@ -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."""
@ -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,

View File

@ -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,

View File

@ -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 ContactSensor(SmartModule):
"""Implementation of contact sensor module."""
@ -17,11 +12,11 @@ class ContactSensor(SmartModule):
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,

View File

@ -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,
@ -36,7 +30,7 @@ class Fan(SmartModule, FanInterface):
)
self._add_feature(
Feature(
device,
self._device,
id="fan_sleep_mode",
name="Fan sleep mode",
container=self,

View File

@ -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 HumiditySensor(SmartModule):
"""Implementation of humidity module."""
@ -17,11 +12,11 @@ class HumiditySensor(SmartModule):
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,
@ -34,7 +29,7 @@ class HumiditySensor(SmartModule):
)
self._add_feature(
Feature(
device,
self._device,
id="humidity_warning",
name="Humidity warning",
container=self,

View File

@ -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 ReportMode(SmartModule):
"""Implementation of report module."""
@ -17,11 +12,11 @@ class ReportMode(SmartModule):
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,

View File

@ -2,14 +2,11 @@
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."""
@ -17,11 +14,11 @@ class TemperatureSensor(SmartModule):
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,
@ -32,10 +29,10 @@ class TemperatureSensor(SmartModule):
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,
@ -47,7 +44,7 @@ class TemperatureSensor(SmartModule):
)
self._add_feature(
Feature(
device,
self._device,
id="temperature_unit",
name="Temperature unit",
container=self,

View File

@ -4,14 +4,11 @@ from __future__ import annotations
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."""
@ -19,12 +16,11 @@ class Time(SmartModule):
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",

View File

@ -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."""
@ -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,
@ -41,7 +37,7 @@ class WaterleakSensor(SmartModule):
)
self._add_feature(
Feature(
device,
self._device,
id="water_alert",
name="Water alert",
container=self,