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

@@ -234,10 +234,10 @@ class Device(ABC):
return await connect(host=host, config=config) # type: ignore[arg-type]
@abstractmethod
async def update(self, update_children: bool = True):
async def update(self, update_children: bool = True) -> None:
"""Update the device."""
async def disconnect(self):
async def disconnect(self) -> None:
"""Disconnect and close any underlying connection resources."""
await self.protocol.close()
@@ -257,15 +257,15 @@ class Device(ABC):
return not self.is_on
@abstractmethod
async def turn_on(self, **kwargs) -> dict | None:
async def turn_on(self, **kwargs) -> dict:
"""Turn on the device."""
@abstractmethod
async def turn_off(self, **kwargs) -> dict | None:
async def turn_off(self, **kwargs) -> dict:
"""Turn off the device."""
@abstractmethod
async def set_state(self, on: bool):
async def set_state(self, on: bool) -> dict:
"""Set the device state to *on*.
This allows turning the device on and off.
@@ -278,7 +278,7 @@ class Device(ABC):
return self.protocol._transport._host
@host.setter
def host(self, value):
def host(self, value: str) -> None:
"""Set the device host.
Generally used by discovery to set the hostname after ip discovery.
@@ -307,7 +307,7 @@ class Device(ABC):
return self._device_type
@abstractmethod
def update_from_discover_info(self, info):
def update_from_discover_info(self, info: dict) -> None:
"""Update state from info from the discover call."""
@property
@@ -325,7 +325,7 @@ class Device(ABC):
def alias(self) -> str | None:
"""Returns the device alias or nickname."""
async def _raw_query(self, request: str | dict) -> Any:
async def _raw_query(self, request: str | dict) -> dict:
"""Send a raw query to the device."""
return await self.protocol.query(request=request)
@@ -407,7 +407,7 @@ class Device(ABC):
@property
@abstractmethod
def internal_state(self) -> Any:
def internal_state(self) -> dict:
"""Return all the internal state data."""
@property
@@ -420,10 +420,10 @@ class Device(ABC):
"""Return the list of supported features."""
return self._features
def _add_feature(self, feature: Feature):
def _add_feature(self, feature: Feature) -> None:
"""Add a new feature to the device."""
if feature.id in self._features:
raise KasaException("Duplicate feature id %s" % feature.id)
raise KasaException(f"Duplicate feature id {feature.id}")
assert feature.id is not None # TODO: hack for typing # noqa: S101
self._features[feature.id] = feature
@@ -446,11 +446,13 @@ class Device(ABC):
"""Scan for available wifi networks."""
@abstractmethod
async def wifi_join(self, ssid: str, password: str, keytype: str = "wpa2_psk"):
async def wifi_join(
self, ssid: str, password: str, keytype: str = "wpa2_psk"
) -> dict:
"""Join the given wifi network."""
@abstractmethod
async def set_alias(self, alias: str):
async def set_alias(self, alias: str) -> dict:
"""Set the device name (alias)."""
@abstractmethod
@@ -468,7 +470,7 @@ class Device(ABC):
Note, this does not downgrade the firmware.
"""
def __repr__(self):
def __repr__(self) -> str:
update_needed = " - update() needed" if not self._last_update else ""
return (
f"<{self.device_type} at {self.host} -"
@@ -486,7 +488,9 @@ class Device(ABC):
"is_strip_socket": (None, DeviceType.StripSocket),
}
def _get_replacing_attr(self, module_name: ModuleName, *attrs):
def _get_replacing_attr(
self, module_name: ModuleName | None, *attrs: Any
) -> str | None:
# If module name is None check self
if not module_name:
check = self
@@ -540,7 +544,7 @@ class Device(ABC):
"supported_modules": (None, ["modules"]),
}
def __getattr__(self, name):
def __getattr__(self, name: str) -> Any:
# is_device_type
if dep_device_type_attr := self._deprecated_device_type_attributes.get(name):
module = dep_device_type_attr[0]