mirror of
https://github.com/home-assistant/core.git
synced 2025-07-15 17:27:10 +00:00
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
@ -3,6 +3,7 @@ from __future__ import annotations
|
|||||||
|
|
||||||
from functools import partial
|
from functools import partial
|
||||||
import logging
|
import logging
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
from miio import DeviceException
|
from miio import DeviceException
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
@ -214,7 +215,7 @@ class MiroboVacuum(
|
|||||||
self._handle_coordinator_update()
|
self._handle_coordinator_update()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def state(self):
|
def state(self) -> str | None:
|
||||||
"""Return the status of the vacuum cleaner."""
|
"""Return the status of the vacuum cleaner."""
|
||||||
# The vacuum reverts back to an idle state after erroring out.
|
# The vacuum reverts back to an idle state after erroring out.
|
||||||
# We want to keep returning an error until it has been cleared.
|
# We want to keep returning an error until it has been cleared.
|
||||||
@ -247,7 +248,7 @@ class MiroboVacuum(
|
|||||||
return []
|
return []
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def timers(self):
|
def timers(self) -> list[dict[str, Any]]:
|
||||||
"""Get the list of added timers of the vacuum cleaner."""
|
"""Get the list of added timers of the vacuum cleaner."""
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
@ -259,9 +260,9 @@ class MiroboVacuum(
|
|||||||
]
|
]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def extra_state_attributes(self):
|
def extra_state_attributes(self) -> dict[str, Any]:
|
||||||
"""Return the specific state attributes of this vacuum cleaner."""
|
"""Return the specific state attributes of this vacuum cleaner."""
|
||||||
attrs = {}
|
attrs: dict[str, Any] = {}
|
||||||
attrs[ATTR_STATUS] = str(self.coordinator.data.status.state)
|
attrs[ATTR_STATUS] = str(self.coordinator.data.status.state)
|
||||||
|
|
||||||
if self.coordinator.data.status.got_error:
|
if self.coordinator.data.status.got_error:
|
||||||
@ -281,27 +282,27 @@ class MiroboVacuum(
|
|||||||
_LOGGER.error(mask_error, exc)
|
_LOGGER.error(mask_error, exc)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
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._try_command(
|
await self._try_command(
|
||||||
"Unable to start the vacuum: %s", self._device.resume_or_start
|
"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."""
|
"""Pause the cleaning task."""
|
||||||
await self._try_command("Unable to set start/pause: %s", self._device.pause)
|
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."""
|
"""Stop the vacuum cleaner."""
|
||||||
await self._try_command("Unable to stop: %s", self._device.stop)
|
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."""
|
"""Set fan speed."""
|
||||||
if fan_speed in self.coordinator.data.fan_speeds:
|
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:
|
else:
|
||||||
try:
|
try:
|
||||||
fan_speed = int(fan_speed)
|
fan_speed_int = int(fan_speed)
|
||||||
except ValueError as exc:
|
except ValueError as exc:
|
||||||
_LOGGER.error(
|
_LOGGER.error(
|
||||||
"Fan speed step not recognized (%s). Valid speeds are: %s",
|
"Fan speed step not recognized (%s). Valid speeds are: %s",
|
||||||
@ -310,24 +311,26 @@ class MiroboVacuum(
|
|||||||
)
|
)
|
||||||
return
|
return
|
||||||
await self._try_command(
|
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."""
|
"""Set the vacuum cleaner to return to the dock."""
|
||||||
await self._try_command("Unable to return home: %s", self._device.home)
|
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."""
|
"""Perform a spot clean-up."""
|
||||||
await self._try_command(
|
await self._try_command(
|
||||||
"Unable to start the vacuum for a spot clean-up: %s", self._device.spot
|
"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."""
|
"""Locate the vacuum cleaner."""
|
||||||
await self._try_command("Unable to locate the botvac: %s", self._device.find)
|
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."""
|
"""Send raw command."""
|
||||||
await self._try_command(
|
await self._try_command(
|
||||||
"Unable to send command to the vacuum: %s",
|
"Unable to send command to the vacuum: %s",
|
||||||
@ -336,13 +339,13 @@ class MiroboVacuum(
|
|||||||
params,
|
params,
|
||||||
)
|
)
|
||||||
|
|
||||||
async def async_remote_control_start(self):
|
async def async_remote_control_start(self) -> None:
|
||||||
"""Start remote control mode."""
|
"""Start remote control mode."""
|
||||||
await self._try_command(
|
await self._try_command(
|
||||||
"Unable to start remote control the vacuum: %s", self._device.manual_start
|
"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."""
|
"""Stop remote control mode."""
|
||||||
await self._try_command(
|
await self._try_command(
|
||||||
"Unable to stop remote control the vacuum: %s", self._device.manual_stop
|
"Unable to stop remote control the vacuum: %s", self._device.manual_stop
|
||||||
@ -350,7 +353,7 @@ class MiroboVacuum(
|
|||||||
|
|
||||||
async def async_remote_control_move(
|
async def async_remote_control_move(
|
||||||
self, rotation: int = 0, velocity: float = 0.3, duration: int = 1500
|
self, rotation: int = 0, velocity: float = 0.3, duration: int = 1500
|
||||||
):
|
) -> None:
|
||||||
"""Move vacuum with remote control mode."""
|
"""Move vacuum with remote control mode."""
|
||||||
await self._try_command(
|
await self._try_command(
|
||||||
"Unable to move with remote control the vacuum: %s",
|
"Unable to move with remote control the vacuum: %s",
|
||||||
@ -362,7 +365,7 @@ class MiroboVacuum(
|
|||||||
|
|
||||||
async def async_remote_control_move_step(
|
async def async_remote_control_move_step(
|
||||||
self, rotation: int = 0, velocity: float = 0.2, duration: int = 1500
|
self, rotation: int = 0, velocity: float = 0.2, duration: int = 1500
|
||||||
):
|
) -> None:
|
||||||
"""Move vacuum one step with remote control mode."""
|
"""Move vacuum one step with remote control mode."""
|
||||||
await self._try_command(
|
await self._try_command(
|
||||||
"Unable to remote control the vacuum: %s",
|
"Unable to remote control the vacuum: %s",
|
||||||
@ -372,7 +375,7 @@ class MiroboVacuum(
|
|||||||
duration=duration,
|
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."""
|
"""Goto the specified coordinates."""
|
||||||
await self._try_command(
|
await self._try_command(
|
||||||
"Unable to send the vacuum cleaner to the specified coordinates: %s",
|
"Unable to send the vacuum cleaner to the specified coordinates: %s",
|
||||||
@ -381,7 +384,7 @@ class MiroboVacuum(
|
|||||||
y_coord=y_coord,
|
y_coord=y_coord,
|
||||||
)
|
)
|
||||||
|
|
||||||
async def async_clean_segment(self, segments):
|
async def async_clean_segment(self, segments) -> None:
|
||||||
"""Clean the specified segments(s)."""
|
"""Clean the specified segments(s)."""
|
||||||
if isinstance(segments, int):
|
if isinstance(segments, int):
|
||||||
segments = [segments]
|
segments = [segments]
|
||||||
@ -392,7 +395,7 @@ class MiroboVacuum(
|
|||||||
segments=segments,
|
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."""
|
"""Clean selected area for the number of repeats indicated."""
|
||||||
for _zone in zone:
|
for _zone in zone:
|
||||||
_zone.append(repeats)
|
_zone.append(repeats)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user