mirror of
https://github.com/python-kasa/python-kasa.git
synced 2025-10-10 17:38:01 +00:00
Enable ruff check for ANN (#1139)
This commit is contained in:
@@ -4,6 +4,7 @@ from __future__ import annotations
|
||||
|
||||
from abc import ABC, abstractmethod
|
||||
from enum import IntFlag, auto
|
||||
from typing import Any
|
||||
from warnings import warn
|
||||
|
||||
from ..emeterstatus import EmeterStatus
|
||||
@@ -31,7 +32,7 @@ class Energy(Module, ABC):
|
||||
"""Return True if module supports the feature."""
|
||||
return module_feature in self._supported
|
||||
|
||||
def _initialize_features(self):
|
||||
def _initialize_features(self) -> None:
|
||||
"""Initialize features."""
|
||||
device = self._device
|
||||
self._add_feature(
|
||||
@@ -151,22 +152,26 @@ class Energy(Module, ABC):
|
||||
"""Get the current voltage in V."""
|
||||
|
||||
@abstractmethod
|
||||
async def get_status(self):
|
||||
async def get_status(self) -> EmeterStatus:
|
||||
"""Return real-time statistics."""
|
||||
|
||||
@abstractmethod
|
||||
async def erase_stats(self):
|
||||
async def erase_stats(self) -> dict:
|
||||
"""Erase all stats."""
|
||||
|
||||
@abstractmethod
|
||||
async def get_daily_stats(self, *, year=None, month=None, kwh=True) -> dict:
|
||||
async def get_daily_stats(
|
||||
self, *, year: int | None = None, month: int | None = None, kwh: bool = True
|
||||
) -> dict:
|
||||
"""Return daily stats for the given year & month.
|
||||
|
||||
The return value is a dictionary of {day: energy, ...}.
|
||||
"""
|
||||
|
||||
@abstractmethod
|
||||
async def get_monthly_stats(self, *, year=None, kwh=True) -> dict:
|
||||
async def get_monthly_stats(
|
||||
self, *, year: int | None = None, kwh: bool = True
|
||||
) -> dict:
|
||||
"""Return monthly stats for the given year."""
|
||||
|
||||
_deprecated_attributes = {
|
||||
@@ -179,7 +184,7 @@ class Energy(Module, ABC):
|
||||
"get_monthstat": "get_monthly_stats",
|
||||
}
|
||||
|
||||
def __getattr__(self, name):
|
||||
def __getattr__(self, name: str) -> Any:
|
||||
if attr := self._deprecated_attributes.get(name):
|
||||
msg = f"{name} is deprecated, use {attr} instead"
|
||||
warn(msg, DeprecationWarning, stacklevel=2)
|
||||
|
@@ -16,5 +16,5 @@ class Fan(Module, ABC):
|
||||
"""Return fan speed level."""
|
||||
|
||||
@abstractmethod
|
||||
async def set_fan_speed_level(self, level: int):
|
||||
async def set_fan_speed_level(self, level: int) -> dict:
|
||||
"""Set fan speed level."""
|
||||
|
@@ -11,7 +11,7 @@ from ..module import Module
|
||||
class Led(Module, ABC):
|
||||
"""Base interface to represent a LED module."""
|
||||
|
||||
def _initialize_features(self):
|
||||
def _initialize_features(self) -> None:
|
||||
"""Initialize features."""
|
||||
device = self._device
|
||||
self._add_feature(
|
||||
@@ -34,5 +34,5 @@ class Led(Module, ABC):
|
||||
"""Return current led status."""
|
||||
|
||||
@abstractmethod
|
||||
async def set_led(self, enable: bool) -> None:
|
||||
async def set_led(self, enable: bool) -> dict:
|
||||
"""Set led."""
|
||||
|
@@ -166,7 +166,7 @@ class Light(Module, ABC):
|
||||
|
||||
@abstractmethod
|
||||
async def set_color_temp(
|
||||
self, temp: int, *, brightness=None, transition: int | None = None
|
||||
self, temp: int, *, brightness: int | None = None, transition: int | None = None
|
||||
) -> dict:
|
||||
"""Set the color temperature of the device in kelvin.
|
||||
|
||||
|
@@ -53,7 +53,7 @@ class LightEffect(Module, ABC):
|
||||
|
||||
LIGHT_EFFECTS_OFF = "Off"
|
||||
|
||||
def _initialize_features(self):
|
||||
def _initialize_features(self) -> None:
|
||||
"""Initialize features."""
|
||||
device = self._device
|
||||
self._add_feature(
|
||||
@@ -96,7 +96,7 @@ class LightEffect(Module, ABC):
|
||||
*,
|
||||
brightness: int | None = None,
|
||||
transition: int | None = None,
|
||||
) -> None:
|
||||
) -> dict:
|
||||
"""Set an effect on the device.
|
||||
|
||||
If brightness or transition is defined,
|
||||
@@ -110,10 +110,11 @@ class LightEffect(Module, ABC):
|
||||
:param int transition: The wanted transition time
|
||||
"""
|
||||
|
||||
@abstractmethod
|
||||
async def set_custom_effect(
|
||||
self,
|
||||
effect_dict: dict,
|
||||
) -> None:
|
||||
) -> dict:
|
||||
"""Set a custom effect on the device.
|
||||
|
||||
:param str effect_dict: The custom effect dict to set
|
||||
|
@@ -83,7 +83,7 @@ class LightPreset(Module):
|
||||
|
||||
PRESET_NOT_SET = "Not set"
|
||||
|
||||
def _initialize_features(self):
|
||||
def _initialize_features(self) -> None:
|
||||
"""Initialize features."""
|
||||
device = self._device
|
||||
self._add_feature(
|
||||
@@ -127,7 +127,7 @@ class LightPreset(Module):
|
||||
async def set_preset(
|
||||
self,
|
||||
preset_name: str,
|
||||
) -> None:
|
||||
) -> dict:
|
||||
"""Set a light preset for the device."""
|
||||
|
||||
@abstractmethod
|
||||
@@ -135,7 +135,7 @@ class LightPreset(Module):
|
||||
self,
|
||||
preset_name: str,
|
||||
preset_info: LightState,
|
||||
) -> None:
|
||||
) -> dict:
|
||||
"""Update the preset with *preset_name* with the new *preset_info*."""
|
||||
|
||||
@property
|
||||
|
Reference in New Issue
Block a user