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,7 +1,8 @@
"""Implementation of the emeter module."""
from __future__ import annotations
from datetime import datetime
from typing import Dict, List, Optional, Union
from ...emeterstatus import EmeterStatus
from .usage import Usage
@@ -16,7 +17,7 @@ class Emeter(Usage):
return EmeterStatus(self.data["get_realtime"])
@property
def emeter_today(self) -> Optional[float]:
def emeter_today(self) -> float | None:
"""Return today's energy consumption in kWh."""
raw_data = self.daily_data
today = datetime.now().day
@@ -24,7 +25,7 @@ class Emeter(Usage):
return data.get(today)
@property
def emeter_this_month(self) -> Optional[float]:
def emeter_this_month(self) -> float | None:
"""Return this month's energy consumption in kWh."""
raw_data = self.monthly_data
current_month = datetime.now().month
@@ -42,7 +43,7 @@ class Emeter(Usage):
"""Return real-time statistics."""
return await self.call("get_realtime")
async def get_daystat(self, *, year=None, month=None, kwh=True) -> Dict:
async def get_daystat(self, *, year=None, month=None, kwh=True) -> dict:
"""Return daily stats for the given year & month.
The return value is a dictionary of {day: energy, ...}.
@@ -51,7 +52,7 @@ class Emeter(Usage):
data = self._convert_stat_data(data["day_list"], entry_key="day", kwh=kwh)
return data
async def get_monthstat(self, *, year=None, kwh=True) -> Dict:
async def get_monthstat(self, *, year=None, kwh=True) -> dict:
"""Return monthly stats for the given year.
The return value is a dictionary of {month: energy, ...}.
@@ -62,11 +63,11 @@ class Emeter(Usage):
def _convert_stat_data(
self,
data: List[Dict[str, Union[int, float]]],
data: list[dict[str, int | float]],
entry_key: str,
kwh: bool = True,
key: Optional[int] = None,
) -> Dict[Union[int, float], Union[int, float]]:
key: int | None = None,
) -> dict[int | float, int | float]:
"""Return emeter information keyed with the day/month.
The incoming data is a list of dictionaries::

View File

@@ -1,7 +1,8 @@
"""Implementation of the motion detection (PIR) module found in some dimmers."""
from __future__ import annotations
from enum import Enum
from typing import Optional
from ...exceptions import KasaException
from ..iotmodule import IotModule
@@ -43,7 +44,7 @@ class Motion(IotModule):
return await self.call("set_enable", {"enable": int(state)})
async def set_range(
self, *, range: Optional[Range] = None, custom_range: Optional[int] = None
self, *, range: Range | None = None, custom_range: int | None = None
):
"""Set the range for the sensor.

View File

@@ -1,5 +1,7 @@
"""Base implementation for all rule-based modules."""
from __future__ import annotations
import logging
from enum import Enum
from typing import Dict, List, Optional
@@ -37,20 +39,20 @@ class Rule(BaseModel):
id: str
name: str
enable: bool
wday: List[int]
wday: List[int] # noqa: UP006
repeat: bool
# start action
sact: Optional[Action]
sact: Optional[Action] # noqa: UP007
stime_opt: TimeOption
smin: int
eact: Optional[Action]
eact: Optional[Action] # noqa: UP007
etime_opt: TimeOption
emin: int
# Only on bulbs
s_light: Optional[Dict]
s_light: Optional[Dict] # noqa: UP006,UP007
_LOGGER = logging.getLogger(__name__)
@@ -65,7 +67,7 @@ class RuleModule(IotModule):
return merge(q, self.query_for_command("get_next_action"))
@property
def rules(self) -> List[Rule]:
def rules(self) -> list[Rule]:
"""Return the list of rules for the service."""
try:
return [

View File

@@ -1,7 +1,8 @@
"""Implementation of the usage interface."""
from __future__ import annotations
from datetime import datetime
from typing import Dict
from ..iotmodule import IotModule, merge
@@ -58,7 +59,7 @@ class Usage(IotModule):
return entry["time"]
return None
async def get_raw_daystat(self, *, year=None, month=None) -> Dict:
async def get_raw_daystat(self, *, year=None, month=None) -> dict:
"""Return raw daily stats for the given year & month."""
if year is None:
year = datetime.now().year
@@ -67,14 +68,14 @@ class Usage(IotModule):
return await self.call("get_daystat", {"year": year, "month": month})
async def get_raw_monthstat(self, *, year=None) -> Dict:
async def get_raw_monthstat(self, *, year=None) -> dict:
"""Return raw monthly stats for the given year."""
if year is None:
year = datetime.now().year
return await self.call("get_monthstat", {"year": year})
async def get_daystat(self, *, year=None, month=None) -> Dict:
async def get_daystat(self, *, year=None, month=None) -> dict:
"""Return daily stats for the given year & month.
The return value is a dictionary of {day: time, ...}.
@@ -83,7 +84,7 @@ class Usage(IotModule):
data = self._convert_stat_data(data["day_list"], entry_key="day")
return data
async def get_monthstat(self, *, year=None) -> Dict:
async def get_monthstat(self, *, year=None) -> dict:
"""Return monthly stats for the given year.
The return value is a dictionary of {month: time, ...}.
@@ -96,7 +97,7 @@ class Usage(IotModule):
"""Erase all stats."""
return await self.call("erase_runtime_stat")
def _convert_stat_data(self, data, entry_key) -> Dict:
def _convert_stat_data(self, data, entry_key) -> dict:
"""Return usage information keyed with the day/month.
The incoming data is a list of dictionaries::