Xiaomi vacuum as platform of new `vacuum` component derived from ToggleEntity, and services (#8623)
* Xiaomi vacuum as component with switch, sensors and services
- Conversion from switch platform to async component.
- Add services proposed in #8416 to the new component, with shorter names.
- Add sensors for the vacuum robot as a selectable list from `battery`, `state`, `error`, `fanspeed`, `clean_time` and `clean_area` (the state attributes of the switch). The sensors don't poll, but listen to a signal to update the state, the switch fires this signal when updating.
- Assign default icons to sensors and the switch (`mdi:google-circles-group` looks like the robot!)
* path change in requirements_all (from switch platform to component)
* copy pasting is a bad habit
* services to the components services.yaml, modify .coveragerc
* review: use with multiple hosts, fix calls to async_add_devices, fix ranges for services
* `icon_for_battery_level` util method
* Xiaomi vacuum as platform of new component vacuum
- Created new component `vacuum` from a ToggleEntity.
- Add services `turn_on`, `turn_off`, `cleaning_play_pause`, `stop`, `return_to_base`, `locate`, `set_fanspeed` and `send_command`.
- Remove the main switch for the xiaomi vacuum (the toggable main entity is the switch).
- Add `support flags` for the common services
- Assign default icons to sensors and the switch (`mdi:google-circles-group` looks like the robot!)
- Move services descriptions to a yaml file for the new component.
- Update requirements_all.
- Update coveragerc.
* fix coveragerc
* fix battery icon helper to use more icons
* remove sensors, create properties and support flags for custom UI
* cleaning
* updated state_attrs for filtering in UI, renamed platform to simply `xiaomi`
* fix platform rename
* change fanspeed and expose `fanspeed_list` to use speed steps
* minor fixes
- Rename service `start_pause`
- Add 'Error' attribute only if `got_error`.
- Minor changes
* rename state attrs
* rename state attrs
* review changes: cut fan__speed, style changes, remove logging, and more
* add ATTR_COMMAND = 'command' to const
* pop entity_id from service data
* remove property accessor for vacuum object
* lint fix
* fix extra attrs names
* module level functions for calling the services
* params as optional keyword for `send_command`
* params as optional keyword for `send_command`, remove debug logs
* explicit parameters for `set_fan_speed` and `send_command`
* Demo platform for the vacuum component
* vacuum tests for the Demo platform
* some fixes
* don't omit vacuum
* vacuum tests for the Xiaomi platform
* fix test
* fix
* fix xiaomi test
* fix coveragerc
* test send command
* fix coveragerc
* fix string formatting
* The coverage is to low. It need 93% or more
2017-08-04 13:27:10 +00:00
|
|
|
"""The tests for vacuum platforms."""
|
2024-05-08 22:33:23 +00:00
|
|
|
|
|
|
|
from typing import Any
|
|
|
|
|
|
|
|
from homeassistant.components.vacuum import (
|
|
|
|
DOMAIN,
|
|
|
|
STATE_CLEANING,
|
|
|
|
STATE_DOCKED,
|
|
|
|
STATE_IDLE,
|
|
|
|
STATE_PAUSED,
|
|
|
|
STATE_RETURNING,
|
|
|
|
StateVacuumEntity,
|
|
|
|
VacuumEntityFeature,
|
|
|
|
)
|
|
|
|
from homeassistant.config_entries import ConfigEntry
|
|
|
|
from homeassistant.const import Platform
|
|
|
|
from homeassistant.core import HomeAssistant
|
|
|
|
|
|
|
|
from tests.common import MockEntity
|
|
|
|
|
|
|
|
|
|
|
|
class MockVacuum(MockEntity, StateVacuumEntity):
|
|
|
|
"""Mock vacuum class."""
|
|
|
|
|
|
|
|
_attr_supported_features = (
|
|
|
|
VacuumEntityFeature.PAUSE
|
|
|
|
| VacuumEntityFeature.STOP
|
|
|
|
| VacuumEntityFeature.RETURN_HOME
|
|
|
|
| VacuumEntityFeature.FAN_SPEED
|
|
|
|
| VacuumEntityFeature.BATTERY
|
|
|
|
| VacuumEntityFeature.CLEAN_SPOT
|
|
|
|
| VacuumEntityFeature.MAP
|
|
|
|
| VacuumEntityFeature.STATE
|
|
|
|
| VacuumEntityFeature.START
|
|
|
|
)
|
|
|
|
_attr_battery_level = 99
|
|
|
|
_attr_fan_speed_list = ["slow", "fast"]
|
|
|
|
|
|
|
|
def __init__(self, **values: Any) -> None:
|
|
|
|
"""Initialize a mock vacuum entity."""
|
|
|
|
super().__init__(**values)
|
|
|
|
self._attr_state = STATE_DOCKED
|
|
|
|
self._attr_fan_speed = "slow"
|
|
|
|
|
|
|
|
def stop(self, **kwargs: Any) -> None:
|
|
|
|
"""Stop cleaning."""
|
|
|
|
self._attr_state = STATE_IDLE
|
|
|
|
|
|
|
|
def return_to_base(self, **kwargs: Any) -> None:
|
|
|
|
"""Return to base."""
|
|
|
|
self._attr_state = STATE_RETURNING
|
|
|
|
|
|
|
|
def clean_spot(self, **kwargs: Any) -> None:
|
|
|
|
"""Clean a spot."""
|
|
|
|
self._attr_state = STATE_CLEANING
|
|
|
|
|
|
|
|
def set_fan_speed(self, fan_speed: str, **kwargs: Any) -> None:
|
|
|
|
"""Set the fan speed."""
|
|
|
|
self._attr_fan_speed = fan_speed
|
|
|
|
|
|
|
|
def start(self) -> None:
|
|
|
|
"""Start cleaning."""
|
|
|
|
self._attr_state = STATE_CLEANING
|
|
|
|
|
|
|
|
def pause(self) -> None:
|
|
|
|
"""Pause cleaning."""
|
|
|
|
self._attr_state = STATE_PAUSED
|
|
|
|
|
|
|
|
|
|
|
|
async def help_async_setup_entry_init(
|
|
|
|
hass: HomeAssistant, config_entry: ConfigEntry
|
|
|
|
) -> bool:
|
|
|
|
"""Set up test config entry."""
|
|
|
|
await hass.config_entries.async_forward_entry_setup(config_entry, DOMAIN)
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
|
|
async def help_async_unload_entry(
|
|
|
|
hass: HomeAssistant, config_entry: ConfigEntry
|
|
|
|
) -> bool:
|
|
|
|
"""Unload test config emntry."""
|
|
|
|
return await hass.config_entries.async_unload_platforms(
|
|
|
|
config_entry, [Platform.VACUUM]
|
|
|
|
)
|