Improve type hints in xiaomi_miio vacuum entities (#76563)
Co-authored-by: Teemu R. <tpr@iki.fi>
This commit is contained in:
parent
0639681991
commit
54fc17e10d
1 changed files with 25 additions and 22 deletions
|
@ -3,6 +3,7 @@ from __future__ import annotations
|
|||
|
||||
from functools import partial
|
||||
import logging
|
||||
from typing import Any
|
||||
|
||||
from miio import DeviceException
|
||||
import voluptuous as vol
|
||||
|
@ -214,7 +215,7 @@ class MiroboVacuum(
|
|||
self._handle_coordinator_update()
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
def state(self) -> str | None:
|
||||
"""Return the status of the vacuum cleaner."""
|
||||
# The vacuum reverts back to an idle state after erroring out.
|
||||
# We want to keep returning an error until it has been cleared.
|
||||
|
@ -247,7 +248,7 @@ class MiroboVacuum(
|
|||
return []
|
||||
|
||||
@property
|
||||
def timers(self):
|
||||
def timers(self) -> list[dict[str, Any]]:
|
||||
"""Get the list of added timers of the vacuum cleaner."""
|
||||
return [
|
||||
{
|
||||
|
@ -259,9 +260,9 @@ class MiroboVacuum(
|
|||
]
|
||||
|
||||
@property
|
||||
def extra_state_attributes(self):
|
||||
def extra_state_attributes(self) -> dict[str, Any]:
|
||||
"""Return the specific state attributes of this vacuum cleaner."""
|
||||
attrs = {}
|
||||
attrs: dict[str, Any] = {}
|
||||
attrs[ATTR_STATUS] = str(self.coordinator.data.status.state)
|
||||
|
||||
if self.coordinator.data.status.got_error:
|
||||
|
@ -281,27 +282,27 @@ class MiroboVacuum(
|
|||
_LOGGER.error(mask_error, exc)
|
||||
return False
|
||||
|
||||
async def async_start(self):
|
||||
async def async_start(self) -> None:
|
||||
"""Start or resume the cleaning task."""
|
||||
await self._try_command(
|
||||
"Unable to start the vacuum: %s", self._device.resume_or_start
|
||||
)
|
||||
|
||||
async def async_pause(self):
|
||||
async def async_pause(self) -> None:
|
||||
"""Pause the cleaning task."""
|
||||
await self._try_command("Unable to set start/pause: %s", self._device.pause)
|
||||
|
||||
async def async_stop(self, **kwargs):
|
||||
async def async_stop(self, **kwargs: Any) -> None:
|
||||
"""Stop the vacuum cleaner."""
|
||||
await self._try_command("Unable to stop: %s", self._device.stop)
|
||||
|
||||
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."""
|
||||
if fan_speed in self.coordinator.data.fan_speeds:
|
||||
fan_speed = self.coordinator.data.fan_speeds[fan_speed]
|
||||
fan_speed_int = self.coordinator.data.fan_speeds[fan_speed]
|
||||
else:
|
||||
try:
|
||||
fan_speed = int(fan_speed)
|
||||
fan_speed_int = int(fan_speed)
|
||||
except ValueError as exc:
|
||||
_LOGGER.error(
|
||||
"Fan speed step not recognized (%s). Valid speeds are: %s",
|
||||
|
@ -310,24 +311,26 @@ class MiroboVacuum(
|
|||
)
|
||||
return
|
||||
await self._try_command(
|
||||
"Unable to set fan speed: %s", self._device.set_fan_speed, fan_speed
|
||||
"Unable to set fan speed: %s", self._device.set_fan_speed, fan_speed_int
|
||||
)
|
||||
|
||||
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."""
|
||||
await self._try_command("Unable to return home: %s", self._device.home)
|
||||
|
||||
async def async_clean_spot(self, **kwargs):
|
||||
async def async_clean_spot(self, **kwargs: Any) -> None:
|
||||
"""Perform a spot clean-up."""
|
||||
await self._try_command(
|
||||
"Unable to start the vacuum for a spot clean-up: %s", self._device.spot
|
||||
)
|
||||
|
||||
async def async_locate(self, **kwargs):
|
||||
async def async_locate(self, **kwargs: Any) -> None:
|
||||
"""Locate the vacuum cleaner."""
|
||||
await self._try_command("Unable to locate the botvac: %s", self._device.find)
|
||||
|
||||
async def async_send_command(self, command, params=None, **kwargs):
|
||||
async def async_send_command(
|
||||
self, command: str, params: dict | list | None = None, **kwargs: Any
|
||||
) -> None:
|
||||
"""Send raw command."""
|
||||
await self._try_command(
|
||||
"Unable to send command to the vacuum: %s",
|
||||
|
@ -336,13 +339,13 @@ class MiroboVacuum(
|
|||
params,
|
||||
)
|
||||
|
||||
async def async_remote_control_start(self):
|
||||
async def async_remote_control_start(self) -> None:
|
||||
"""Start remote control mode."""
|
||||
await self._try_command(
|
||||
"Unable to start remote control the vacuum: %s", self._device.manual_start
|
||||
)
|
||||
|
||||
async def async_remote_control_stop(self):
|
||||
async def async_remote_control_stop(self) -> None:
|
||||
"""Stop remote control mode."""
|
||||
await self._try_command(
|
||||
"Unable to stop remote control the vacuum: %s", self._device.manual_stop
|
||||
|
@ -350,7 +353,7 @@ class MiroboVacuum(
|
|||
|
||||
async def async_remote_control_move(
|
||||
self, rotation: int = 0, velocity: float = 0.3, duration: int = 1500
|
||||
):
|
||||
) -> None:
|
||||
"""Move vacuum with remote control mode."""
|
||||
await self._try_command(
|
||||
"Unable to move with remote control the vacuum: %s",
|
||||
|
@ -362,7 +365,7 @@ class MiroboVacuum(
|
|||
|
||||
async def async_remote_control_move_step(
|
||||
self, rotation: int = 0, velocity: float = 0.2, duration: int = 1500
|
||||
):
|
||||
) -> None:
|
||||
"""Move vacuum one step with remote control mode."""
|
||||
await self._try_command(
|
||||
"Unable to remote control the vacuum: %s",
|
||||
|
@ -372,7 +375,7 @@ class MiroboVacuum(
|
|||
duration=duration,
|
||||
)
|
||||
|
||||
async def async_goto(self, x_coord: int, y_coord: int):
|
||||
async def async_goto(self, x_coord: int, y_coord: int) -> None:
|
||||
"""Goto the specified coordinates."""
|
||||
await self._try_command(
|
||||
"Unable to send the vacuum cleaner to the specified coordinates: %s",
|
||||
|
@ -381,7 +384,7 @@ class MiroboVacuum(
|
|||
y_coord=y_coord,
|
||||
)
|
||||
|
||||
async def async_clean_segment(self, segments):
|
||||
async def async_clean_segment(self, segments) -> None:
|
||||
"""Clean the specified segments(s)."""
|
||||
if isinstance(segments, int):
|
||||
segments = [segments]
|
||||
|
@ -392,7 +395,7 @@ class MiroboVacuum(
|
|||
segments=segments,
|
||||
)
|
||||
|
||||
async def async_clean_zone(self, zone, repeats=1):
|
||||
async def async_clean_zone(self, zone: list[Any], repeats: int = 1) -> None:
|
||||
"""Clean selected area for the number of repeats indicated."""
|
||||
for _zone in zone:
|
||||
_zone.append(repeats)
|
||||
|
|
Loading…
Add table
Reference in a new issue