Improve type hints in vacuum entities (#76561)

This commit is contained in:
epenet 2022-08-20 08:33:27 +02:00 committed by GitHub
parent 52fbd50d3c
commit fea0ec4d4d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 29 additions and 22 deletions

View File

@ -94,17 +94,17 @@ class EcovacsVacuum(VacuumEntity):
return self.device.vacuum.get("did") return self.device.vacuum.get("did")
@property @property
def is_on(self): def is_on(self) -> bool:
"""Return true if vacuum is currently cleaning.""" """Return true if vacuum is currently cleaning."""
return self.device.is_cleaning return self.device.is_cleaning
@property @property
def is_charging(self): def is_charging(self) -> bool:
"""Return true if vacuum is currently charging.""" """Return true if vacuum is currently charging."""
return self.device.is_charging return self.device.is_charging
@property @property
def status(self): def status(self) -> str | None:
"""Return the status of the vacuum cleaner.""" """Return the status of the vacuum cleaner."""
return self.device.vacuum_status return self.device.vacuum_status
@ -173,9 +173,9 @@ class EcovacsVacuum(VacuumEntity):
self.device.run(sucks.VacBotCommand(command, params)) self.device.run(sucks.VacBotCommand(command, params))
@property @property
def extra_state_attributes(self): def extra_state_attributes(self) -> dict[str, Any]:
"""Return the device-specific state attributes of this vacuum.""" """Return the device-specific state attributes of this vacuum."""
data = {} data: dict[str, Any] = {}
data[ATTR_ERROR] = self._error data[ATTR_ERROR] = self._error
for key, val in self.device.components.items(): for key, val in self.device.components.items():

View File

@ -2,6 +2,7 @@
from __future__ import annotations from __future__ import annotations
from collections.abc import Iterable from collections.abc import Iterable
from typing import Any
from sharkiq import OperatingModes, PowerModes, Properties, SharkIqVacuum from sharkiq import OperatingModes, PowerModes, Properties, SharkIqVacuum
@ -89,11 +90,16 @@ class SharkVacuumEntity(CoordinatorEntity[SharkIqUpdateCoordinator], StateVacuum
self._attr_unique_id = sharkiq.serial_number self._attr_unique_id = sharkiq.serial_number
self._serial_number = sharkiq.serial_number self._serial_number = sharkiq.serial_number
def clean_spot(self, **kwargs): def clean_spot(self, **kwargs: Any) -> None:
"""Clean a spot. Not yet implemented.""" """Clean a spot. Not yet implemented."""
raise NotImplementedError() raise NotImplementedError()
def send_command(self, command, params=None, **kwargs): def send_command(
self,
command: str,
params: dict[str, Any] | list[Any] | None = None,
**kwargs: Any,
) -> None:
"""Send a command to the vacuum. Not yet implemented.""" """Send a command to the vacuum. Not yet implemented."""
raise NotImplementedError() raise NotImplementedError()
@ -146,7 +152,7 @@ class SharkVacuumEntity(CoordinatorEntity[SharkIqUpdateCoordinator], StateVacuum
return self.sharkiq.get_property_value(Properties.RECHARGING_TO_RESUME) return self.sharkiq.get_property_value(Properties.RECHARGING_TO_RESUME)
@property @property
def state(self): def state(self) -> str | None:
""" """
Get the current vacuum state. Get the current vacuum state.
@ -169,27 +175,27 @@ class SharkVacuumEntity(CoordinatorEntity[SharkIqUpdateCoordinator], StateVacuum
"""Get the current battery level.""" """Get the current battery level."""
return self.sharkiq.get_property_value(Properties.BATTERY_CAPACITY) return self.sharkiq.get_property_value(Properties.BATTERY_CAPACITY)
async def async_return_to_base(self, **kwargs): async def async_return_to_base(self, **kwargs: Any) -> None:
"""Have the device return to base.""" """Have the device return to base."""
await self.sharkiq.async_set_operating_mode(OperatingModes.RETURN) await self.sharkiq.async_set_operating_mode(OperatingModes.RETURN)
await self.coordinator.async_refresh() await self.coordinator.async_refresh()
async def async_pause(self): async def async_pause(self) -> None:
"""Pause the cleaning task.""" """Pause the cleaning task."""
await self.sharkiq.async_set_operating_mode(OperatingModes.PAUSE) await self.sharkiq.async_set_operating_mode(OperatingModes.PAUSE)
await self.coordinator.async_refresh() await self.coordinator.async_refresh()
async def async_start(self): async def async_start(self) -> None:
"""Start the device.""" """Start the device."""
await self.sharkiq.async_set_operating_mode(OperatingModes.START) await self.sharkiq.async_set_operating_mode(OperatingModes.START)
await self.coordinator.async_refresh() await self.coordinator.async_refresh()
async def async_stop(self, **kwargs): async def async_stop(self, **kwargs: Any) -> None:
"""Stop the device.""" """Stop the device."""
await self.sharkiq.async_set_operating_mode(OperatingModes.STOP) await self.sharkiq.async_set_operating_mode(OperatingModes.STOP)
await self.coordinator.async_refresh() await self.coordinator.async_refresh()
async def async_locate(self, **kwargs): async def async_locate(self, **kwargs: Any) -> None:
"""Cause the device to generate a loud chirp.""" """Cause the device to generate a loud chirp."""
await self.sharkiq.async_find_device() await self.sharkiq.async_find_device()
@ -203,7 +209,7 @@ class SharkVacuumEntity(CoordinatorEntity[SharkIqUpdateCoordinator], StateVacuum
fan_speed = k fan_speed = k
return fan_speed return fan_speed
async def async_set_fan_speed(self, fan_speed: str, **kwargs): async def async_set_fan_speed(self, fan_speed: str, **kwargs: Any) -> None:
"""Set the fan speed.""" """Set the fan speed."""
await self.sharkiq.async_set_property_value( await self.sharkiq.async_set_property_value(
Properties.POWER_MODE, FAN_SPEEDS_MAP.get(fan_speed.capitalize()) Properties.POWER_MODE, FAN_SPEEDS_MAP.get(fan_speed.capitalize())
@ -227,7 +233,7 @@ class SharkVacuumEntity(CoordinatorEntity[SharkIqUpdateCoordinator], StateVacuum
return self.sharkiq.get_property_value(Properties.LOW_LIGHT_MISSION) return self.sharkiq.get_property_value(Properties.LOW_LIGHT_MISSION)
@property @property
def extra_state_attributes(self) -> dict: def extra_state_attributes(self) -> dict[str, Any]:
"""Return a dictionary of device state attributes specific to sharkiq.""" """Return a dictionary of device state attributes specific to sharkiq."""
data = { data = {
ATTR_ERROR_CODE: self.error_code, ATTR_ERROR_CODE: self.error_code,

View File

@ -2,6 +2,7 @@
from __future__ import annotations from __future__ import annotations
import logging import logging
from typing import Any
import voluptuous as vol import voluptuous as vol
@ -204,46 +205,46 @@ class TemplateVacuum(TemplateEntity, StateVacuumEntity):
"""Return the status of the vacuum cleaner.""" """Return the status of the vacuum cleaner."""
return self._state return self._state
async def async_start(self): async def async_start(self) -> None:
"""Start or resume the cleaning task.""" """Start or resume the cleaning task."""
await self.async_run_script(self._start_script, context=self._context) await self.async_run_script(self._start_script, context=self._context)
async def async_pause(self): async def async_pause(self) -> None:
"""Pause the cleaning task.""" """Pause the cleaning task."""
if self._pause_script is None: if self._pause_script is None:
return return
await self.async_run_script(self._pause_script, context=self._context) await self.async_run_script(self._pause_script, context=self._context)
async def async_stop(self, **kwargs): async def async_stop(self, **kwargs: Any) -> None:
"""Stop the cleaning task.""" """Stop the cleaning task."""
if self._stop_script is None: if self._stop_script is None:
return return
await self.async_run_script(self._stop_script, context=self._context) await self.async_run_script(self._stop_script, context=self._context)
async def async_return_to_base(self, **kwargs): async def async_return_to_base(self, **kwargs: Any) -> None:
"""Set the vacuum cleaner to return to the dock.""" """Set the vacuum cleaner to return to the dock."""
if self._return_to_base_script is None: if self._return_to_base_script is None:
return return
await self.async_run_script(self._return_to_base_script, context=self._context) await self.async_run_script(self._return_to_base_script, context=self._context)
async def async_clean_spot(self, **kwargs): async def async_clean_spot(self, **kwargs: Any) -> None:
"""Perform a spot clean-up.""" """Perform a spot clean-up."""
if self._clean_spot_script is None: if self._clean_spot_script is None:
return return
await self.async_run_script(self._clean_spot_script, context=self._context) await self.async_run_script(self._clean_spot_script, context=self._context)
async def async_locate(self, **kwargs): async def async_locate(self, **kwargs: Any) -> None:
"""Locate the vacuum cleaner.""" """Locate the vacuum cleaner."""
if self._locate_script is None: if self._locate_script is None:
return return
await self.async_run_script(self._locate_script, context=self._context) await self.async_run_script(self._locate_script, context=self._context)
async def async_set_fan_speed(self, fan_speed, **kwargs): async def async_set_fan_speed(self, fan_speed: str, **kwargs: Any) -> None:
"""Set fan speed.""" """Set fan speed."""
if self._set_fan_speed_script is None: if self._set_fan_speed_script is None:
return return