Add type hints to Vacuum platform (#69960)

This commit is contained in:
epenet 2022-04-13 17:33:55 +02:00 committed by GitHub
parent 88cfc9229d
commit 28ba57ed94
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 50 additions and 42 deletions

View File

@ -205,7 +205,7 @@ class TuyaVacuumEntity(TuyaEntity, StateVacuumEntity):
self._send_command([{"code": DPCode.SUCTION, "value": fan_speed}])
def send_command(
self, command: str, params: list[str] | None = None, **kwargs: Any
self, command: str, params: dict | list | None = None, **kwargs: Any
) -> None:
"""Send raw command."""
if not params:

View File

@ -1,10 +1,13 @@
"""Support for vacuum cleaner robots (botvacs)."""
from __future__ import annotations
from collections.abc import Mapping
from dataclasses import dataclass
from datetime import timedelta
from enum import IntEnum
from functools import partial
import logging
from typing import final
from typing import Any, final
import voluptuous as vol
@ -174,40 +177,41 @@ class _BaseVacuum(Entity):
"""
@property
def supported_features(self):
def supported_features(self) -> int:
"""Flag vacuum cleaner features that are supported."""
raise NotImplementedError()
@property
def battery_level(self):
def battery_level(self) -> int | None:
"""Return the battery level of the vacuum cleaner."""
return None
@property
def battery_icon(self):
def battery_icon(self) -> str:
"""Return the battery icon for the vacuum cleaner."""
raise NotImplementedError()
@property
def fan_speed(self):
def fan_speed(self) -> str | None:
"""Return the fan speed of the vacuum cleaner."""
return None
@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."""
raise NotImplementedError()
@property
def capability_attributes(self):
def capability_attributes(self) -> Mapping[str, Any] | None:
"""Return capability attributes."""
if self.supported_features & VacuumEntityFeature.FAN_SPEED:
return {ATTR_FAN_SPEED_LIST: self.fan_speed_list}
return None
@property
def state_attributes(self):
def state_attributes(self) -> dict[str, Any]:
"""Return the state attributes of the vacuum cleaner."""
data = {}
data: dict[str, Any] = {}
if self.supported_features & VacuumEntityFeature.BATTERY:
data[ATTR_BATTERY_LEVEL] = self.battery_level
@ -218,55 +222,55 @@ class _BaseVacuum(Entity):
return data
def stop(self, **kwargs):
def stop(self, **kwargs: Any) -> None:
"""Stop the vacuum cleaner."""
raise NotImplementedError()
async def async_stop(self, **kwargs):
async def async_stop(self, **kwargs: Any) -> None:
"""Stop the vacuum cleaner.
This method must be run in the event loop.
"""
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."""
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.
This method must be run in the event loop.
"""
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."""
raise NotImplementedError()
async def async_clean_spot(self, **kwargs):
async def async_clean_spot(self, **kwargs: Any) -> None:
"""Perform a spot clean-up.
This method must be run in the event loop.
"""
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."""
raise NotImplementedError()
async def async_locate(self, **kwargs):
async def async_locate(self, **kwargs: Any) -> None:
"""Locate the vacuum cleaner.
This method must be run in the event loop.
"""
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."""
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.
This method must be run in the event loop.
@ -275,11 +279,15 @@ class _BaseVacuum(Entity):
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."""
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.
This method must be run in the event loop.
@ -300,12 +308,12 @@ class VacuumEntity(_BaseVacuum, ToggleEntity):
entity_description: VacuumEntityDescription
@property
def status(self):
def status(self) -> str | None:
"""Return the status of the vacuum cleaner."""
return None
@property
def battery_icon(self):
def battery_icon(self) -> str:
"""Return the battery icon for the vacuum cleaner."""
charging = False
if self.status is not None:
@ -316,7 +324,7 @@ class VacuumEntity(_BaseVacuum, ToggleEntity):
@final
@property
def state_attributes(self):
def state_attributes(self) -> dict[str, Any]:
"""Return the state attributes of the vacuum cleaner."""
data = super().state_attributes
@ -325,43 +333,43 @@ class VacuumEntity(_BaseVacuum, ToggleEntity):
return data
def turn_on(self, **kwargs):
def turn_on(self, **kwargs: Any) -> None:
"""Turn the vacuum on and start cleaning."""
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.
This method must be run in the event loop.
"""
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."""
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.
This method must be run in the event loop.
"""
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."""
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.
This method must be run in the event loop.
"""
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."""
async def async_start(self):
async def async_start(self) -> None:
"""Not supported."""
@ -376,12 +384,12 @@ class StateVacuumEntity(_BaseVacuum):
entity_description: StateVacuumEntityDescription
@property
def state(self):
def state(self) -> str | None:
"""Return the state of the vacuum cleaner."""
return None
@property
def battery_icon(self):
def battery_icon(self) -> str:
"""Return the battery icon for the vacuum cleaner."""
charging = bool(self.state == STATE_DOCKED)
@ -389,33 +397,33 @@ class StateVacuumEntity(_BaseVacuum):
battery_level=self.battery_level, charging=charging
)
def start(self):
def start(self) -> None:
"""Start or resume the cleaning task."""
raise NotImplementedError()
async def async_start(self):
async def async_start(self) -> None:
"""Start or resume the cleaning task.
This method must be run in the event loop.
"""
await self.hass.async_add_executor_job(self.start)
def pause(self):
def pause(self) -> None:
"""Pause the cleaning task."""
raise NotImplementedError()
async def async_pause(self):
async def async_pause(self) -> None:
"""Pause the cleaning task.
This method must be run in the event loop.
"""
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."""
async def async_turn_off(self, **kwargs):
async def async_turn_off(self, **kwargs: Any) -> None:
"""Not supported."""
async def async_toggle(self, **kwargs):
async def async_toggle(self, **kwargs: Any) -> None:
"""Not supported."""