Enable ruff check for ANN (#1139)

This commit is contained in:
Teemu R.
2024-11-10 19:55:13 +01:00
committed by GitHub
parent 6b44fe6242
commit 66eb17057e
89 changed files with 596 additions and 452 deletions

View File

@@ -22,17 +22,17 @@ _R = TypeVar("_R")
def allow_update_after(
func: Callable[Concatenate[_T, _P], Awaitable[None]],
) -> Callable[Concatenate[_T, _P], Coroutine[Any, Any, None]]:
func: Callable[Concatenate[_T, _P], Awaitable[dict]],
) -> Callable[Concatenate[_T, _P], Coroutine[Any, Any, dict]]:
"""Define a wrapper to set _last_update_time to None.
This will ensure that a module is updated in the next update cycle after
a value has been changed.
"""
async def _async_wrap(self: _T, *args: _P.args, **kwargs: _P.kwargs) -> None:
async def _async_wrap(self: _T, *args: _P.args, **kwargs: _P.kwargs) -> dict:
try:
await func(self, *args, **kwargs)
return await func(self, *args, **kwargs)
finally:
self._last_update_time = None
@@ -68,21 +68,21 @@ class SmartModule(Module):
DISABLE_AFTER_ERROR_COUNT = 10
def __init__(self, device: SmartDevice, module: str):
def __init__(self, device: SmartDevice, module: str) -> None:
self._device: SmartDevice
super().__init__(device, module)
self._last_update_time: float | None = None
self._last_update_error: KasaException | None = None
self._error_count = 0
def __init_subclass__(cls, **kwargs):
def __init_subclass__(cls, **kwargs) -> None:
# We only want to register submodules in a modules package so that
# other classes can inherit from smartmodule and not be registered
if cls.__module__.split(".")[-2] == "modules":
_LOGGER.debug("Registering %s", cls)
cls.REGISTERED_MODULES[cls._module_name()] = cls
def _set_error(self, err: Exception | None):
def _set_error(self, err: Exception | None) -> None:
if err is None:
self._error_count = 0
self._last_update_error = None
@@ -119,7 +119,7 @@ class SmartModule(Module):
return self._error_count >= self.DISABLE_AFTER_ERROR_COUNT
@classmethod
def _module_name(cls):
def _module_name(cls) -> str:
return getattr(cls, "NAME", cls.__name__)
@property
@@ -127,7 +127,7 @@ class SmartModule(Module):
"""Name of the module."""
return self._module_name()
async def _post_update_hook(self): # noqa: B027
async def _post_update_hook(self) -> None: # noqa: B027
"""Perform actions after a device update.
Any modules overriding this should ensure that self.data is
@@ -142,7 +142,7 @@ class SmartModule(Module):
"""
return {self.QUERY_GETTER_NAME: None}
async def call(self, method, params=None):
async def call(self, method: str, params: dict | None = None) -> dict:
"""Call a method.
Just a helper method.
@@ -150,7 +150,7 @@ class SmartModule(Module):
return await self._device._query_helper(method, params)
@property
def data(self):
def data(self) -> dict[str, Any]:
"""Return response data for the module.
If the module performs only a single query, the resulting response is unwrapped.