mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 04:07:08 +00:00
Add type hints to Vacuum platform (#69960)
This commit is contained in:
parent
88cfc9229d
commit
28ba57ed94
@ -205,7 +205,7 @@ class TuyaVacuumEntity(TuyaEntity, StateVacuumEntity):
|
|||||||
self._send_command([{"code": DPCode.SUCTION, "value": fan_speed}])
|
self._send_command([{"code": DPCode.SUCTION, "value": fan_speed}])
|
||||||
|
|
||||||
def send_command(
|
def send_command(
|
||||||
self, command: str, params: list[str] | None = None, **kwargs: Any
|
self, command: str, params: dict | list | None = None, **kwargs: Any
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Send raw command."""
|
"""Send raw command."""
|
||||||
if not params:
|
if not params:
|
||||||
|
@ -1,10 +1,13 @@
|
|||||||
"""Support for vacuum cleaner robots (botvacs)."""
|
"""Support for vacuum cleaner robots (botvacs)."""
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from collections.abc import Mapping
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
from enum import IntEnum
|
from enum import IntEnum
|
||||||
from functools import partial
|
from functools import partial
|
||||||
import logging
|
import logging
|
||||||
from typing import final
|
from typing import Any, final
|
||||||
|
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
@ -174,40 +177,41 @@ class _BaseVacuum(Entity):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def supported_features(self):
|
def supported_features(self) -> int:
|
||||||
"""Flag vacuum cleaner features that are supported."""
|
"""Flag vacuum cleaner features that are supported."""
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def battery_level(self):
|
def battery_level(self) -> int | None:
|
||||||
"""Return the battery level of the vacuum cleaner."""
|
"""Return the battery level of the vacuum cleaner."""
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def battery_icon(self):
|
def battery_icon(self) -> str:
|
||||||
"""Return the battery icon for the vacuum cleaner."""
|
"""Return the battery icon for the vacuum cleaner."""
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def fan_speed(self):
|
def fan_speed(self) -> str | None:
|
||||||
"""Return the fan speed of the vacuum cleaner."""
|
"""Return the fan speed of the vacuum cleaner."""
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def fan_speed_list(self):
|
def fan_speed_list(self) -> list[str]:
|
||||||
"""Get the list of available fan speed steps of the vacuum cleaner."""
|
"""Get the list of available fan speed steps of the vacuum cleaner."""
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def capability_attributes(self):
|
def capability_attributes(self) -> Mapping[str, Any] | None:
|
||||||
"""Return capability attributes."""
|
"""Return capability attributes."""
|
||||||
if self.supported_features & VacuumEntityFeature.FAN_SPEED:
|
if self.supported_features & VacuumEntityFeature.FAN_SPEED:
|
||||||
return {ATTR_FAN_SPEED_LIST: self.fan_speed_list}
|
return {ATTR_FAN_SPEED_LIST: self.fan_speed_list}
|
||||||
|
return None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def state_attributes(self):
|
def state_attributes(self) -> dict[str, Any]:
|
||||||
"""Return the state attributes of the vacuum cleaner."""
|
"""Return the state attributes of the vacuum cleaner."""
|
||||||
data = {}
|
data: dict[str, Any] = {}
|
||||||
|
|
||||||
if self.supported_features & VacuumEntityFeature.BATTERY:
|
if self.supported_features & VacuumEntityFeature.BATTERY:
|
||||||
data[ATTR_BATTERY_LEVEL] = self.battery_level
|
data[ATTR_BATTERY_LEVEL] = self.battery_level
|
||||||
@ -218,55 +222,55 @@ class _BaseVacuum(Entity):
|
|||||||
|
|
||||||
return data
|
return data
|
||||||
|
|
||||||
def stop(self, **kwargs):
|
def stop(self, **kwargs: Any) -> None:
|
||||||
"""Stop the vacuum cleaner."""
|
"""Stop the vacuum cleaner."""
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
async def async_stop(self, **kwargs):
|
async def async_stop(self, **kwargs: Any) -> None:
|
||||||
"""Stop the vacuum cleaner.
|
"""Stop the vacuum cleaner.
|
||||||
|
|
||||||
This method must be run in the event loop.
|
This method must be run in the event loop.
|
||||||
"""
|
"""
|
||||||
await self.hass.async_add_executor_job(partial(self.stop, **kwargs))
|
await self.hass.async_add_executor_job(partial(self.stop, **kwargs))
|
||||||
|
|
||||||
def return_to_base(self, **kwargs):
|
def 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."""
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
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.
|
||||||
|
|
||||||
This method must be run in the event loop.
|
This method must be run in the event loop.
|
||||||
"""
|
"""
|
||||||
await self.hass.async_add_executor_job(partial(self.return_to_base, **kwargs))
|
await self.hass.async_add_executor_job(partial(self.return_to_base, **kwargs))
|
||||||
|
|
||||||
def clean_spot(self, **kwargs):
|
def clean_spot(self, **kwargs: Any) -> None:
|
||||||
"""Perform a spot clean-up."""
|
"""Perform a spot clean-up."""
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
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.
|
||||||
|
|
||||||
This method must be run in the event loop.
|
This method must be run in the event loop.
|
||||||
"""
|
"""
|
||||||
await self.hass.async_add_executor_job(partial(self.clean_spot, **kwargs))
|
await self.hass.async_add_executor_job(partial(self.clean_spot, **kwargs))
|
||||||
|
|
||||||
def locate(self, **kwargs):
|
def locate(self, **kwargs: Any) -> None:
|
||||||
"""Locate the vacuum cleaner."""
|
"""Locate the vacuum cleaner."""
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
async def async_locate(self, **kwargs):
|
async def async_locate(self, **kwargs: Any) -> None:
|
||||||
"""Locate the vacuum cleaner.
|
"""Locate the vacuum cleaner.
|
||||||
|
|
||||||
This method must be run in the event loop.
|
This method must be run in the event loop.
|
||||||
"""
|
"""
|
||||||
await self.hass.async_add_executor_job(partial(self.locate, **kwargs))
|
await self.hass.async_add_executor_job(partial(self.locate, **kwargs))
|
||||||
|
|
||||||
def set_fan_speed(self, fan_speed, **kwargs):
|
def set_fan_speed(self, fan_speed: str, **kwargs: Any) -> None:
|
||||||
"""Set fan speed."""
|
"""Set fan speed."""
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
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.
|
||||||
|
|
||||||
This method must be run in the event loop.
|
This method must be run in the event loop.
|
||||||
@ -275,11 +279,15 @@ class _BaseVacuum(Entity):
|
|||||||
partial(self.set_fan_speed, fan_speed, **kwargs)
|
partial(self.set_fan_speed, fan_speed, **kwargs)
|
||||||
)
|
)
|
||||||
|
|
||||||
def send_command(self, command, params=None, **kwargs):
|
def send_command(
|
||||||
|
self, command: str, params: dict | list | None = None, **kwargs: Any
|
||||||
|
) -> None:
|
||||||
"""Send a command to a vacuum cleaner."""
|
"""Send a command to a vacuum cleaner."""
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
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 a command to a vacuum cleaner.
|
"""Send a command to a vacuum cleaner.
|
||||||
|
|
||||||
This method must be run in the event loop.
|
This method must be run in the event loop.
|
||||||
@ -300,12 +308,12 @@ class VacuumEntity(_BaseVacuum, ToggleEntity):
|
|||||||
entity_description: VacuumEntityDescription
|
entity_description: VacuumEntityDescription
|
||||||
|
|
||||||
@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 None
|
return None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def battery_icon(self):
|
def battery_icon(self) -> str:
|
||||||
"""Return the battery icon for the vacuum cleaner."""
|
"""Return the battery icon for the vacuum cleaner."""
|
||||||
charging = False
|
charging = False
|
||||||
if self.status is not None:
|
if self.status is not None:
|
||||||
@ -316,7 +324,7 @@ class VacuumEntity(_BaseVacuum, ToggleEntity):
|
|||||||
|
|
||||||
@final
|
@final
|
||||||
@property
|
@property
|
||||||
def state_attributes(self):
|
def state_attributes(self) -> dict[str, Any]:
|
||||||
"""Return the state attributes of the vacuum cleaner."""
|
"""Return the state attributes of the vacuum cleaner."""
|
||||||
data = super().state_attributes
|
data = super().state_attributes
|
||||||
|
|
||||||
@ -325,43 +333,43 @@ class VacuumEntity(_BaseVacuum, ToggleEntity):
|
|||||||
|
|
||||||
return data
|
return data
|
||||||
|
|
||||||
def turn_on(self, **kwargs):
|
def turn_on(self, **kwargs: Any) -> None:
|
||||||
"""Turn the vacuum on and start cleaning."""
|
"""Turn the vacuum on and start cleaning."""
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
async def async_turn_on(self, **kwargs):
|
async def async_turn_on(self, **kwargs: Any) -> None:
|
||||||
"""Turn the vacuum on and start cleaning.
|
"""Turn the vacuum on and start cleaning.
|
||||||
|
|
||||||
This method must be run in the event loop.
|
This method must be run in the event loop.
|
||||||
"""
|
"""
|
||||||
await self.hass.async_add_executor_job(partial(self.turn_on, **kwargs))
|
await self.hass.async_add_executor_job(partial(self.turn_on, **kwargs))
|
||||||
|
|
||||||
def turn_off(self, **kwargs):
|
def turn_off(self, **kwargs: Any) -> None:
|
||||||
"""Turn the vacuum off stopping the cleaning and returning home."""
|
"""Turn the vacuum off stopping the cleaning and returning home."""
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
async def async_turn_off(self, **kwargs):
|
async def async_turn_off(self, **kwargs: Any) -> None:
|
||||||
"""Turn the vacuum off stopping the cleaning and returning home.
|
"""Turn the vacuum off stopping the cleaning and returning home.
|
||||||
|
|
||||||
This method must be run in the event loop.
|
This method must be run in the event loop.
|
||||||
"""
|
"""
|
||||||
await self.hass.async_add_executor_job(partial(self.turn_off, **kwargs))
|
await self.hass.async_add_executor_job(partial(self.turn_off, **kwargs))
|
||||||
|
|
||||||
def start_pause(self, **kwargs):
|
def start_pause(self, **kwargs: Any) -> None:
|
||||||
"""Start, pause or resume the cleaning task."""
|
"""Start, pause or resume the cleaning task."""
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
async def async_start_pause(self, **kwargs):
|
async def async_start_pause(self, **kwargs: Any) -> None:
|
||||||
"""Start, pause or resume the cleaning task.
|
"""Start, pause or resume the cleaning task.
|
||||||
|
|
||||||
This method must be run in the event loop.
|
This method must be run in the event loop.
|
||||||
"""
|
"""
|
||||||
await self.hass.async_add_executor_job(partial(self.start_pause, **kwargs))
|
await self.hass.async_add_executor_job(partial(self.start_pause, **kwargs))
|
||||||
|
|
||||||
async def async_pause(self):
|
async def async_pause(self) -> None:
|
||||||
"""Not supported."""
|
"""Not supported."""
|
||||||
|
|
||||||
async def async_start(self):
|
async def async_start(self) -> None:
|
||||||
"""Not supported."""
|
"""Not supported."""
|
||||||
|
|
||||||
|
|
||||||
@ -376,12 +384,12 @@ class StateVacuumEntity(_BaseVacuum):
|
|||||||
entity_description: StateVacuumEntityDescription
|
entity_description: StateVacuumEntityDescription
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def state(self):
|
def state(self) -> str | None:
|
||||||
"""Return the state of the vacuum cleaner."""
|
"""Return the state of the vacuum cleaner."""
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def battery_icon(self):
|
def battery_icon(self) -> str:
|
||||||
"""Return the battery icon for the vacuum cleaner."""
|
"""Return the battery icon for the vacuum cleaner."""
|
||||||
charging = bool(self.state == STATE_DOCKED)
|
charging = bool(self.state == STATE_DOCKED)
|
||||||
|
|
||||||
@ -389,33 +397,33 @@ class StateVacuumEntity(_BaseVacuum):
|
|||||||
battery_level=self.battery_level, charging=charging
|
battery_level=self.battery_level, charging=charging
|
||||||
)
|
)
|
||||||
|
|
||||||
def start(self):
|
def start(self) -> None:
|
||||||
"""Start or resume the cleaning task."""
|
"""Start or resume the cleaning task."""
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
async def async_start(self):
|
async def async_start(self) -> None:
|
||||||
"""Start or resume the cleaning task.
|
"""Start or resume the cleaning task.
|
||||||
|
|
||||||
This method must be run in the event loop.
|
This method must be run in the event loop.
|
||||||
"""
|
"""
|
||||||
await self.hass.async_add_executor_job(self.start)
|
await self.hass.async_add_executor_job(self.start)
|
||||||
|
|
||||||
def pause(self):
|
def pause(self) -> None:
|
||||||
"""Pause the cleaning task."""
|
"""Pause the cleaning task."""
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
async def async_pause(self):
|
async def async_pause(self) -> None:
|
||||||
"""Pause the cleaning task.
|
"""Pause the cleaning task.
|
||||||
|
|
||||||
This method must be run in the event loop.
|
This method must be run in the event loop.
|
||||||
"""
|
"""
|
||||||
await self.hass.async_add_executor_job(self.pause)
|
await self.hass.async_add_executor_job(self.pause)
|
||||||
|
|
||||||
async def async_turn_on(self, **kwargs):
|
async def async_turn_on(self, **kwargs: Any) -> None:
|
||||||
"""Not supported."""
|
"""Not supported."""
|
||||||
|
|
||||||
async def async_turn_off(self, **kwargs):
|
async def async_turn_off(self, **kwargs: Any) -> None:
|
||||||
"""Not supported."""
|
"""Not supported."""
|
||||||
|
|
||||||
async def async_toggle(self, **kwargs):
|
async def async_toggle(self, **kwargs: Any) -> None:
|
||||||
"""Not supported."""
|
"""Not supported."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user