Enable and convert to future annotations (#838)

This commit is contained in:
Steven B
2024-04-17 14:39:24 +01:00
committed by GitHub
parent 82d92aeea5
commit 203bd79253
59 changed files with 562 additions and 462 deletions

View File

@@ -1,6 +1,8 @@
"""Implementation of alarm module."""
from typing import TYPE_CHECKING, Dict, List, Optional
from __future__ import annotations
from typing import TYPE_CHECKING
from ...feature import Feature, FeatureType
from ..smartmodule import SmartModule
@@ -14,14 +16,14 @@ class AlarmModule(SmartModule):
REQUIRED_COMPONENT = "alarm"
def query(self) -> Dict:
def query(self) -> dict:
"""Query to execute during the update cycle."""
return {
"get_alarm_configure": None,
"get_support_alarm_type_list": None, # This should be needed only once
}
def __init__(self, device: "SmartDevice", module: str):
def __init__(self, device: SmartDevice, module: str):
super().__init__(device, module)
self._add_feature(
Feature(
@@ -59,7 +61,7 @@ class AlarmModule(SmartModule):
return self.data["get_alarm_configure"]["type"]
@property
def alarm_sounds(self) -> List[str]:
def alarm_sounds(self) -> list[str]:
"""Return list of available alarm sounds."""
return self.data["get_support_alarm_type_list"]["alarm_type_list"]
@@ -74,7 +76,7 @@ class AlarmModule(SmartModule):
return self._device.sys_info["in_alarm"]
@property
def source(self) -> Optional[str]:
def source(self) -> str | None:
"""Return the alarm cause."""
src = self._device.sys_info["in_alarm_source"]
return src if src else None

View File

@@ -1,7 +1,9 @@
"""Implementation of auto off module."""
from __future__ import annotations
from datetime import datetime, timedelta
from typing import TYPE_CHECKING, Dict, Optional
from typing import TYPE_CHECKING
from ...feature import Feature
from ..smartmodule import SmartModule
@@ -16,7 +18,7 @@ class AutoOffModule(SmartModule):
REQUIRED_COMPONENT = "auto_off"
QUERY_GETTER_NAME = "get_auto_off_config"
def __init__(self, device: "SmartDevice", module: str):
def __init__(self, device: SmartDevice, module: str):
super().__init__(device, module)
self._add_feature(
Feature(
@@ -42,7 +44,7 @@ class AutoOffModule(SmartModule):
)
)
def query(self) -> Dict:
def query(self) -> dict:
"""Query to execute during the update cycle."""
return {self.QUERY_GETTER_NAME: {"start_index": 0}}
@@ -75,7 +77,7 @@ class AutoOffModule(SmartModule):
return self._device.sys_info["auto_off_status"] == "on"
@property
def auto_off_at(self) -> Optional[datetime]:
def auto_off_at(self) -> datetime | None:
"""Return when the device will be turned off automatically."""
if not self.is_timer_active:
return None

View File

@@ -1,5 +1,7 @@
"""Implementation of battery module."""
from __future__ import annotations
from typing import TYPE_CHECKING
from ...feature import Feature, FeatureType
@@ -15,7 +17,7 @@ class BatterySensor(SmartModule):
REQUIRED_COMPONENT = "battery_detect"
QUERY_GETTER_NAME = "get_battery_detect_info"
def __init__(self, device: "SmartDevice", module: str):
def __init__(self, device: SmartDevice, module: str):
super().__init__(device, module)
self._add_feature(
Feature(

View File

@@ -1,6 +1,8 @@
"""Implementation of brightness module."""
from typing import TYPE_CHECKING, Dict
from __future__ import annotations
from typing import TYPE_CHECKING
from ...feature import Feature, FeatureType
from ..smartmodule import SmartModule
@@ -14,7 +16,7 @@ class Brightness(SmartModule):
REQUIRED_COMPONENT = "brightness"
def __init__(self, device: "SmartDevice", module: str):
def __init__(self, device: SmartDevice, module: str):
super().__init__(device, module)
self._add_feature(
Feature(
@@ -29,7 +31,7 @@ class Brightness(SmartModule):
)
)
def query(self) -> Dict:
def query(self) -> dict:
"""Query to execute during the update cycle."""
# Brightness is contained in the main device info response.
return {}

View File

@@ -1,5 +1,7 @@
"""Implementation of cloud module."""
from __future__ import annotations
from typing import TYPE_CHECKING
from ...feature import Feature, FeatureType
@@ -15,7 +17,7 @@ class CloudModule(SmartModule):
QUERY_GETTER_NAME = "get_connect_cloud_state"
REQUIRED_COMPONENT = "cloud_connect"
def __init__(self, device: "SmartDevice", module: str):
def __init__(self, device: SmartDevice, module: str):
super().__init__(device, module)
self._add_feature(

View File

@@ -1,6 +1,8 @@
"""Implementation of color temp module."""
from typing import TYPE_CHECKING, Dict
from __future__ import annotations
from typing import TYPE_CHECKING
from ...bulb import ColorTempRange
from ...feature import Feature
@@ -15,7 +17,7 @@ class ColorTemperatureModule(SmartModule):
REQUIRED_COMPONENT = "color_temperature"
def __init__(self, device: "SmartDevice", module: str):
def __init__(self, device: SmartDevice, module: str):
super().__init__(device, module)
self._add_feature(
Feature(
@@ -28,7 +30,7 @@ class ColorTemperatureModule(SmartModule):
)
)
def query(self) -> Dict:
def query(self) -> dict:
"""Query to execute during the update cycle."""
# Color temp is contained in the main device info response.
return {}

View File

@@ -1,6 +1,6 @@
"""Implementation of device module."""
from typing import Dict
from __future__ import annotations
from ..smartmodule import SmartModule
@@ -10,7 +10,7 @@ class DeviceModule(SmartModule):
REQUIRED_COMPONENT = "device"
def query(self) -> Dict:
def query(self) -> dict:
"""Query to execute during the update cycle."""
query = {
"get_device_info": None,

View File

@@ -1,6 +1,8 @@
"""Implementation of energy monitoring module."""
from typing import TYPE_CHECKING, Dict, Optional
from __future__ import annotations
from typing import TYPE_CHECKING
from ...emeterstatus import EmeterStatus
from ...feature import Feature
@@ -15,7 +17,7 @@ class EnergyModule(SmartModule):
REQUIRED_COMPONENT = "energy_monitoring"
def __init__(self, device: "SmartDevice", module: str):
def __init__(self, device: SmartDevice, module: str):
super().__init__(device, module)
self._add_feature(
Feature(
@@ -42,7 +44,7 @@ class EnergyModule(SmartModule):
)
) # Wh or kWH?
def query(self) -> Dict:
def query(self) -> dict:
"""Query to execute during the update cycle."""
req = {
"get_energy_usage": None,
@@ -77,15 +79,15 @@ class EnergyModule(SmartModule):
)
@property
def emeter_this_month(self) -> Optional[float]:
def emeter_this_month(self) -> float | None:
"""Get the emeter value for this month."""
return self._convert_energy_data(self.energy.get("month_energy"), 1 / 1000)
@property
def emeter_today(self) -> Optional[float]:
def emeter_today(self) -> float | None:
"""Get the emeter value for today."""
return self._convert_energy_data(self.energy.get("today_energy"), 1 / 1000)
def _convert_energy_data(self, data, scale) -> Optional[float]:
def _convert_energy_data(self, data, scale) -> float | None:
"""Return adjusted emeter information."""
return data if not data else data * scale

View File

@@ -1,5 +1,8 @@
"""Implementation of fan_control module."""
from typing import TYPE_CHECKING, Dict
from __future__ import annotations
from typing import TYPE_CHECKING
from ...feature import Feature, FeatureType
from ..smartmodule import SmartModule
@@ -13,7 +16,7 @@ class FanModule(SmartModule):
REQUIRED_COMPONENT = "fan_control"
def __init__(self, device: "SmartDevice", module: str):
def __init__(self, device: SmartDevice, module: str):
super().__init__(device, module)
self._add_feature(
@@ -37,11 +40,11 @@ class FanModule(SmartModule):
attribute_getter="sleep_mode",
attribute_setter="set_sleep_mode",
icon="mdi:sleep",
type=FeatureType.Switch
type=FeatureType.Switch,
)
)
def query(self) -> Dict:
def query(self) -> dict:
"""Query to execute during the update cycle."""
return {}

View File

@@ -1,6 +1,8 @@
"""Implementation of firmware module."""
from typing import TYPE_CHECKING, Dict, Optional
from __future__ import annotations
from typing import TYPE_CHECKING, Optional
from ...exceptions import SmartErrorCode
from ...feature import Feature, FeatureType
@@ -20,11 +22,11 @@ class UpdateInfo(BaseModel):
"""Update info status object."""
status: int = Field(alias="type")
fw_ver: Optional[str] = None
release_date: Optional[date] = None
release_notes: Optional[str] = Field(alias="release_note", default=None)
fw_size: Optional[int] = None
oem_id: Optional[str] = None
fw_ver: Optional[str] = None # noqa: UP007
release_date: Optional[date] = None # noqa: UP007
release_notes: Optional[str] = Field(alias="release_note", default=None) # noqa: UP007
fw_size: Optional[int] = None # noqa: UP007
oem_id: Optional[str] = None # noqa: UP007
needs_upgrade: bool = Field(alias="need_to_upgrade")
@validator("release_date", pre=True)
@@ -47,7 +49,7 @@ class Firmware(SmartModule):
REQUIRED_COMPONENT = "firmware"
def __init__(self, device: "SmartDevice", module: str):
def __init__(self, device: SmartDevice, module: str):
super().__init__(device, module)
if self.supported_version > 1:
self._add_feature(
@@ -70,7 +72,7 @@ class Firmware(SmartModule):
)
)
def query(self) -> Dict:
def query(self) -> dict:
"""Query to execute during the update cycle."""
req = {
"get_latest_fw": None,

View File

@@ -1,5 +1,7 @@
"""Implementation of humidity module."""
from __future__ import annotations
from typing import TYPE_CHECKING
from ...feature import Feature, FeatureType
@@ -15,7 +17,7 @@ class HumiditySensor(SmartModule):
REQUIRED_COMPONENT = "humidity"
QUERY_GETTER_NAME = "get_comfort_humidity_config"
def __init__(self, device: "SmartDevice", module: str):
def __init__(self, device: SmartDevice, module: str):
super().__init__(device, module)
self._add_feature(
Feature(

View File

@@ -1,6 +1,8 @@
"""Module for led controls."""
from typing import TYPE_CHECKING, Dict
from __future__ import annotations
from typing import TYPE_CHECKING
from ...feature import Feature, FeatureType
from ..smartmodule import SmartModule
@@ -15,7 +17,7 @@ class LedModule(SmartModule):
REQUIRED_COMPONENT = "led"
QUERY_GETTER_NAME = "get_led_info"
def __init__(self, device: "SmartDevice", module: str):
def __init__(self, device: SmartDevice, module: str):
super().__init__(device, module)
self._add_feature(
Feature(
@@ -29,7 +31,7 @@ class LedModule(SmartModule):
)
)
def query(self) -> Dict:
def query(self) -> dict:
"""Query to execute during the update cycle."""
return {self.QUERY_GETTER_NAME: {"led_rule": None}}

View File

@@ -1,5 +1,7 @@
"""Module for smooth light transitions."""
from __future__ import annotations
from typing import TYPE_CHECKING
from ...exceptions import KasaException
@@ -17,7 +19,7 @@ class LightTransitionModule(SmartModule):
QUERY_GETTER_NAME = "get_on_off_gradually_info"
MAXIMUM_DURATION = 60
def __init__(self, device: "SmartDevice", module: str):
def __init__(self, device: SmartDevice, module: str):
super().__init__(device, module)
self._create_features()

View File

@@ -1,5 +1,7 @@
"""Implementation of report module."""
from __future__ import annotations
from typing import TYPE_CHECKING
from ...feature import Feature
@@ -15,7 +17,7 @@ class ReportModule(SmartModule):
REQUIRED_COMPONENT = "report_mode"
QUERY_GETTER_NAME = "get_report_mode"
def __init__(self, device: "SmartDevice", module: str):
def __init__(self, device: SmartDevice, module: str):
super().__init__(device, module)
self._add_feature(
Feature(

View File

@@ -1,5 +1,7 @@
"""Implementation of temperature module."""
from __future__ import annotations
from typing import TYPE_CHECKING, Literal
from ...feature import Feature, FeatureType
@@ -15,7 +17,7 @@ class TemperatureSensor(SmartModule):
REQUIRED_COMPONENT = "temperature"
QUERY_GETTER_NAME = "get_comfort_temp_config"
def __init__(self, device: "SmartDevice", module: str):
def __init__(self, device: SmartDevice, module: str):
super().__init__(device, module)
self._add_feature(
Feature(

View File

@@ -1,5 +1,7 @@
"""Implementation of time module."""
from __future__ import annotations
from datetime import datetime, timedelta, timezone
from time import mktime
from typing import TYPE_CHECKING, cast
@@ -17,7 +19,7 @@ class TimeModule(SmartModule):
REQUIRED_COMPONENT = "time"
QUERY_GETTER_NAME = "get_device_time"
def __init__(self, device: "SmartDevice", module: str):
def __init__(self, device: SmartDevice, module: str):
super().__init__(device, module)
self._add_feature(