mirror of
https://github.com/home-assistant/core.git
synced 2025-07-13 16:27:08 +00:00
Refactor demo vacuum's to only use StateVacuum base class and features (#108150)
* Demo cleanup * Refactor vacuum demo to only use state vacuum base class * Remove unneeded feature checks * Remove exclusion issue for mqtt an demo
This commit is contained in:
parent
6bc36666b1
commit
3ff74fe20f
@ -12,7 +12,6 @@ from homeassistant.components.vacuum import (
|
||||
STATE_PAUSED,
|
||||
STATE_RETURNING,
|
||||
StateVacuumEntity,
|
||||
VacuumEntity,
|
||||
VacuumEntityFeature,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
@ -23,24 +22,26 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
SUPPORT_MINIMAL_SERVICES = VacuumEntityFeature.TURN_ON | VacuumEntityFeature.TURN_OFF
|
||||
|
||||
SUPPORT_BASIC_SERVICES = (
|
||||
VacuumEntityFeature.TURN_ON
|
||||
| VacuumEntityFeature.TURN_OFF
|
||||
| VacuumEntityFeature.STATUS
|
||||
VacuumEntityFeature.STATE
|
||||
| VacuumEntityFeature.START
|
||||
| VacuumEntityFeature.STOP
|
||||
| VacuumEntityFeature.BATTERY
|
||||
)
|
||||
|
||||
SUPPORT_MOST_SERVICES = (
|
||||
VacuumEntityFeature.TURN_ON
|
||||
| VacuumEntityFeature.TURN_OFF
|
||||
VacuumEntityFeature.STATE
|
||||
| VacuumEntityFeature.START
|
||||
| VacuumEntityFeature.STOP
|
||||
| VacuumEntityFeature.PAUSE
|
||||
| VacuumEntityFeature.RETURN_HOME
|
||||
| VacuumEntityFeature.STATUS
|
||||
| VacuumEntityFeature.BATTERY
|
||||
| VacuumEntityFeature.FAN_SPEED
|
||||
)
|
||||
|
||||
SUPPORT_ALL_SERVICES = (
|
||||
VacuumEntityFeature.TURN_ON
|
||||
| VacuumEntityFeature.TURN_OFF
|
||||
VacuumEntityFeature.STATE
|
||||
| VacuumEntityFeature.START
|
||||
| VacuumEntityFeature.STOP
|
||||
| VacuumEntityFeature.PAUSE
|
||||
| VacuumEntityFeature.STOP
|
||||
| VacuumEntityFeature.RETURN_HOME
|
||||
@ -49,27 +50,17 @@ SUPPORT_ALL_SERVICES = (
|
||||
| VacuumEntityFeature.LOCATE
|
||||
| VacuumEntityFeature.STATUS
|
||||
| VacuumEntityFeature.BATTERY
|
||||
| VacuumEntityFeature.LOCATE
|
||||
| VacuumEntityFeature.MAP
|
||||
| VacuumEntityFeature.CLEAN_SPOT
|
||||
)
|
||||
|
||||
SUPPORT_STATE_SERVICES = (
|
||||
VacuumEntityFeature.STATE
|
||||
| VacuumEntityFeature.PAUSE
|
||||
| VacuumEntityFeature.STOP
|
||||
| VacuumEntityFeature.RETURN_HOME
|
||||
| VacuumEntityFeature.FAN_SPEED
|
||||
| VacuumEntityFeature.BATTERY
|
||||
| VacuumEntityFeature.CLEAN_SPOT
|
||||
| VacuumEntityFeature.START
|
||||
)
|
||||
|
||||
FAN_SPEEDS = ["min", "medium", "high", "max"]
|
||||
DEMO_VACUUM_COMPLETE = "0_Ground_floor"
|
||||
DEMO_VACUUM_MOST = "1_First_floor"
|
||||
DEMO_VACUUM_BASIC = "2_Second_floor"
|
||||
DEMO_VACUUM_MINIMAL = "3_Third_floor"
|
||||
DEMO_VACUUM_NONE = "4_Fourth_floor"
|
||||
DEMO_VACUUM_STATE = "5_Fifth_floor"
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
@ -80,18 +71,17 @@ async def async_setup_entry(
|
||||
"""Set up the Demo config entry."""
|
||||
async_add_entities(
|
||||
[
|
||||
DemoVacuum(DEMO_VACUUM_COMPLETE, SUPPORT_ALL_SERVICES),
|
||||
DemoVacuum(DEMO_VACUUM_MOST, SUPPORT_MOST_SERVICES),
|
||||
DemoVacuum(DEMO_VACUUM_BASIC, SUPPORT_BASIC_SERVICES),
|
||||
DemoVacuum(DEMO_VACUUM_MINIMAL, SUPPORT_MINIMAL_SERVICES),
|
||||
DemoVacuum(DEMO_VACUUM_NONE, VacuumEntityFeature(0)),
|
||||
StateDemoVacuum(DEMO_VACUUM_STATE),
|
||||
StateDemoVacuum(DEMO_VACUUM_COMPLETE, SUPPORT_ALL_SERVICES),
|
||||
StateDemoVacuum(DEMO_VACUUM_MOST, SUPPORT_MOST_SERVICES),
|
||||
StateDemoVacuum(DEMO_VACUUM_BASIC, SUPPORT_BASIC_SERVICES),
|
||||
StateDemoVacuum(DEMO_VACUUM_MINIMAL, SUPPORT_MINIMAL_SERVICES),
|
||||
StateDemoVacuum(DEMO_VACUUM_NONE, VacuumEntityFeature(0)),
|
||||
]
|
||||
)
|
||||
|
||||
|
||||
class DemoVacuum(VacuumEntity):
|
||||
"""Representation of a demo vacuum."""
|
||||
class StateDemoVacuum(StateVacuumEntity):
|
||||
"""Representation of a demo vacuum supporting states."""
|
||||
|
||||
_attr_should_poll = False
|
||||
_attr_translation_key = "model_s"
|
||||
@ -100,148 +90,6 @@ class DemoVacuum(VacuumEntity):
|
||||
"""Initialize the vacuum."""
|
||||
self._attr_name = name
|
||||
self._attr_supported_features = supported_features
|
||||
self._state = False
|
||||
self._status = "Charging"
|
||||
self._fan_speed = FAN_SPEEDS[1]
|
||||
self._cleaned_area: float = 0
|
||||
self._battery_level = 100
|
||||
|
||||
@property
|
||||
def is_on(self) -> bool:
|
||||
"""Return true if vacuum is on."""
|
||||
return self._state
|
||||
|
||||
@property
|
||||
def status(self) -> str:
|
||||
"""Return the status of the vacuum."""
|
||||
return self._status
|
||||
|
||||
@property
|
||||
def fan_speed(self) -> str:
|
||||
"""Return the status of the vacuum."""
|
||||
return self._fan_speed
|
||||
|
||||
@property
|
||||
def fan_speed_list(self) -> list[str]:
|
||||
"""Return the status of the vacuum."""
|
||||
return FAN_SPEEDS
|
||||
|
||||
@property
|
||||
def battery_level(self) -> int:
|
||||
"""Return the status of the vacuum."""
|
||||
return max(0, min(100, self._battery_level))
|
||||
|
||||
@property
|
||||
def extra_state_attributes(self) -> dict[str, Any]:
|
||||
"""Return device state attributes."""
|
||||
return {ATTR_CLEANED_AREA: round(self._cleaned_area, 2)}
|
||||
|
||||
def turn_on(self, **kwargs: Any) -> None:
|
||||
"""Turn the vacuum on."""
|
||||
if self.supported_features & VacuumEntityFeature.TURN_ON == 0:
|
||||
return
|
||||
|
||||
self._state = True
|
||||
self._cleaned_area += 5.32
|
||||
self._battery_level -= 2
|
||||
self._status = "Cleaning"
|
||||
self.schedule_update_ha_state()
|
||||
|
||||
def turn_off(self, **kwargs: Any) -> None:
|
||||
"""Turn the vacuum off."""
|
||||
if self.supported_features & VacuumEntityFeature.TURN_OFF == 0:
|
||||
return
|
||||
|
||||
self._state = False
|
||||
self._status = "Charging"
|
||||
self.schedule_update_ha_state()
|
||||
|
||||
def stop(self, **kwargs: Any) -> None:
|
||||
"""Stop the vacuum."""
|
||||
if self.supported_features & VacuumEntityFeature.STOP == 0:
|
||||
return
|
||||
|
||||
self._state = False
|
||||
self._status = "Stopping the current task"
|
||||
self.schedule_update_ha_state()
|
||||
|
||||
def clean_spot(self, **kwargs: Any) -> None:
|
||||
"""Perform a spot clean-up."""
|
||||
if self.supported_features & VacuumEntityFeature.CLEAN_SPOT == 0:
|
||||
return
|
||||
|
||||
self._state = True
|
||||
self._cleaned_area += 1.32
|
||||
self._battery_level -= 1
|
||||
self._status = "Cleaning spot"
|
||||
self.schedule_update_ha_state()
|
||||
|
||||
def locate(self, **kwargs: Any) -> None:
|
||||
"""Locate the vacuum (usually by playing a song)."""
|
||||
if self.supported_features & VacuumEntityFeature.LOCATE == 0:
|
||||
return
|
||||
|
||||
self._status = "Hi, I'm over here!"
|
||||
self.schedule_update_ha_state()
|
||||
|
||||
def start_pause(self, **kwargs: Any) -> None:
|
||||
"""Start, pause or resume the cleaning task."""
|
||||
if self.supported_features & VacuumEntityFeature.PAUSE == 0:
|
||||
return
|
||||
|
||||
self._state = not self._state
|
||||
if self._state:
|
||||
self._status = "Resuming the current task"
|
||||
self._cleaned_area += 1.32
|
||||
self._battery_level -= 1
|
||||
else:
|
||||
self._status = "Pausing the current task"
|
||||
self.schedule_update_ha_state()
|
||||
|
||||
def set_fan_speed(self, fan_speed: str, **kwargs: Any) -> None:
|
||||
"""Set the vacuum's fan speed."""
|
||||
if self.supported_features & VacuumEntityFeature.FAN_SPEED == 0:
|
||||
return
|
||||
|
||||
if fan_speed in self.fan_speed_list:
|
||||
self._fan_speed = fan_speed
|
||||
self.schedule_update_ha_state()
|
||||
|
||||
def return_to_base(self, **kwargs: Any) -> None:
|
||||
"""Tell the vacuum to return to its dock."""
|
||||
if self.supported_features & VacuumEntityFeature.RETURN_HOME == 0:
|
||||
return
|
||||
|
||||
self._state = False
|
||||
self._status = "Returning home..."
|
||||
self._battery_level += 5
|
||||
self.schedule_update_ha_state()
|
||||
|
||||
def send_command(
|
||||
self,
|
||||
command: str,
|
||||
params: dict[str, Any] | list[Any] | None = None,
|
||||
**kwargs: Any,
|
||||
) -> None:
|
||||
"""Send a command to the vacuum."""
|
||||
if self.supported_features & VacuumEntityFeature.SEND_COMMAND == 0:
|
||||
return
|
||||
|
||||
self._status = f"Executing {command}({params})"
|
||||
self._state = True
|
||||
self.schedule_update_ha_state()
|
||||
|
||||
|
||||
class StateDemoVacuum(StateVacuumEntity):
|
||||
"""Representation of a demo vacuum supporting states."""
|
||||
|
||||
_attr_should_poll = False
|
||||
_attr_supported_features = SUPPORT_STATE_SERVICES
|
||||
_attr_translation_key = "model_s"
|
||||
|
||||
def __init__(self, name: str) -> None:
|
||||
"""Initialize the vacuum."""
|
||||
self._attr_name = name
|
||||
self._state = STATE_DOCKED
|
||||
self._fan_speed = FAN_SPEEDS[1]
|
||||
self._cleaned_area: float = 0
|
||||
@ -274,9 +122,6 @@ class StateDemoVacuum(StateVacuumEntity):
|
||||
|
||||
def start(self) -> None:
|
||||
"""Start or resume the cleaning task."""
|
||||
if self.supported_features & VacuumEntityFeature.START == 0:
|
||||
return
|
||||
|
||||
if self._state != STATE_CLEANING:
|
||||
self._state = STATE_CLEANING
|
||||
self._cleaned_area += 1.32
|
||||
@ -285,26 +130,17 @@ class StateDemoVacuum(StateVacuumEntity):
|
||||
|
||||
def pause(self) -> None:
|
||||
"""Pause the cleaning task."""
|
||||
if self.supported_features & VacuumEntityFeature.PAUSE == 0:
|
||||
return
|
||||
|
||||
if self._state == STATE_CLEANING:
|
||||
self._state = STATE_PAUSED
|
||||
self.schedule_update_ha_state()
|
||||
|
||||
def stop(self, **kwargs: Any) -> None:
|
||||
"""Stop the cleaning task, do not return to dock."""
|
||||
if self.supported_features & VacuumEntityFeature.STOP == 0:
|
||||
return
|
||||
|
||||
self._state = STATE_IDLE
|
||||
self.schedule_update_ha_state()
|
||||
|
||||
def return_to_base(self, **kwargs: Any) -> None:
|
||||
"""Return dock to charging base."""
|
||||
if self.supported_features & VacuumEntityFeature.RETURN_HOME == 0:
|
||||
return
|
||||
|
||||
self._state = STATE_RETURNING
|
||||
self.schedule_update_ha_state()
|
||||
|
||||
@ -312,9 +148,6 @@ class StateDemoVacuum(StateVacuumEntity):
|
||||
|
||||
def clean_spot(self, **kwargs: Any) -> None:
|
||||
"""Perform a spot clean-up."""
|
||||
if self.supported_features & VacuumEntityFeature.CLEAN_SPOT == 0:
|
||||
return
|
||||
|
||||
self._state = STATE_CLEANING
|
||||
self._cleaned_area += 1.32
|
||||
self._battery_level -= 1
|
||||
@ -322,13 +155,35 @@ class StateDemoVacuum(StateVacuumEntity):
|
||||
|
||||
def set_fan_speed(self, fan_speed: str, **kwargs: Any) -> None:
|
||||
"""Set the vacuum's fan speed."""
|
||||
if self.supported_features & VacuumEntityFeature.FAN_SPEED == 0:
|
||||
return
|
||||
|
||||
if fan_speed in self.fan_speed_list:
|
||||
self._fan_speed = fan_speed
|
||||
self.schedule_update_ha_state()
|
||||
|
||||
async def async_locate(self, **kwargs: Any) -> None:
|
||||
"""Locate the vacuum's position."""
|
||||
await self.hass.services.async_call(
|
||||
"notify",
|
||||
"persistent_notification",
|
||||
service_data={"message": "I'm here!", "title": "Locate request"},
|
||||
)
|
||||
self._state = STATE_IDLE
|
||||
self.async_write_ha_state()
|
||||
|
||||
async def async_clean_spot(self, **kwargs: Any) -> None:
|
||||
"""Locate the vacuum's position."""
|
||||
self._state = STATE_CLEANING
|
||||
self.async_write_ha_state()
|
||||
|
||||
async def async_send_command(
|
||||
self,
|
||||
command: str,
|
||||
params: dict[str, Any] | list[Any] | None = None,
|
||||
**kwargs: Any,
|
||||
) -> None:
|
||||
"""Send a command to the vacuum."""
|
||||
self._state = STATE_IDLE
|
||||
self.async_write_ha_state()
|
||||
|
||||
def __set_state_to_dock(self, _: datetime) -> None:
|
||||
self._state = STATE_DOCKED
|
||||
self.schedule_update_ha_state()
|
||||
|
@ -417,10 +417,6 @@ class VacuumEntity(
|
||||
) -> None:
|
||||
"""Start adding an entity to a platform."""
|
||||
super().add_to_platform_start(hass, platform, parallel_updates)
|
||||
# Don't report core integrations known to still use the deprecated base class;
|
||||
# we don't worry about demo and mqtt has it's own deprecation warnings.
|
||||
if self.platform.platform_name in ("demo", "mqtt"):
|
||||
return
|
||||
translation_key = "deprecated_vacuum_base_class"
|
||||
translation_placeholders = {"platform": self.platform.platform_name}
|
||||
issue_tracker = async_get_issue_tracker(
|
||||
|
@ -4,14 +4,12 @@ from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
|
||||
from homeassistant.components import vacuum
|
||||
from homeassistant.components.demo.vacuum import (
|
||||
DEMO_VACUUM_BASIC,
|
||||
DEMO_VACUUM_COMPLETE,
|
||||
DEMO_VACUUM_MINIMAL,
|
||||
DEMO_VACUUM_MOST,
|
||||
DEMO_VACUUM_NONE,
|
||||
DEMO_VACUUM_STATE,
|
||||
FAN_SPEEDS,
|
||||
)
|
||||
from homeassistant.components.vacuum import (
|
||||
@ -20,7 +18,6 @@ from homeassistant.components.vacuum import (
|
||||
ATTR_FAN_SPEED,
|
||||
ATTR_FAN_SPEED_LIST,
|
||||
ATTR_PARAMS,
|
||||
ATTR_STATUS,
|
||||
DOMAIN,
|
||||
SERVICE_SEND_COMMAND,
|
||||
SERVICE_SET_FAN_SPEED,
|
||||
@ -34,8 +31,6 @@ from homeassistant.const import (
|
||||
ATTR_ENTITY_ID,
|
||||
ATTR_SUPPORTED_FEATURES,
|
||||
CONF_PLATFORM,
|
||||
STATE_OFF,
|
||||
STATE_ON,
|
||||
Platform,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
@ -51,7 +46,6 @@ ENTITY_VACUUM_COMPLETE = f"{DOMAIN}.{DEMO_VACUUM_COMPLETE}".lower()
|
||||
ENTITY_VACUUM_MINIMAL = f"{DOMAIN}.{DEMO_VACUUM_MINIMAL}".lower()
|
||||
ENTITY_VACUUM_MOST = f"{DOMAIN}.{DEMO_VACUUM_MOST}".lower()
|
||||
ENTITY_VACUUM_NONE = f"{DOMAIN}.{DEMO_VACUUM_NONE}".lower()
|
||||
ENTITY_VACUUM_STATE = f"{DOMAIN}.{DEMO_VACUUM_STATE}".lower()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@ -74,166 +68,103 @@ async def setup_demo_vacuum(hass: HomeAssistant, vacuum_only: None):
|
||||
async def test_supported_features(hass: HomeAssistant) -> None:
|
||||
"""Test vacuum supported features."""
|
||||
state = hass.states.get(ENTITY_VACUUM_COMPLETE)
|
||||
assert state.attributes.get(ATTR_SUPPORTED_FEATURES) == 2047
|
||||
assert state.attributes.get(ATTR_STATUS) == "Charging"
|
||||
assert state.attributes.get(ATTR_SUPPORTED_FEATURES) == 16380
|
||||
assert state.attributes.get(ATTR_BATTERY_LEVEL) == 100
|
||||
assert state.attributes.get(ATTR_FAN_SPEED) == "medium"
|
||||
assert state.attributes.get(ATTR_FAN_SPEED_LIST) == FAN_SPEEDS
|
||||
assert state.state == STATE_OFF
|
||||
assert state.state == STATE_DOCKED
|
||||
|
||||
state = hass.states.get(ENTITY_VACUUM_MOST)
|
||||
assert state.attributes.get(ATTR_SUPPORTED_FEATURES) == 219
|
||||
assert state.attributes.get(ATTR_STATUS) == "Charging"
|
||||
assert state.attributes.get(ATTR_SUPPORTED_FEATURES) == 12412
|
||||
assert state.attributes.get(ATTR_BATTERY_LEVEL) == 100
|
||||
assert state.attributes.get(ATTR_FAN_SPEED) is None
|
||||
assert state.attributes.get(ATTR_FAN_SPEED_LIST) is None
|
||||
assert state.state == STATE_OFF
|
||||
assert state.attributes.get(ATTR_FAN_SPEED) == "medium"
|
||||
assert state.attributes.get(ATTR_FAN_SPEED_LIST) == FAN_SPEEDS
|
||||
assert state.state == STATE_DOCKED
|
||||
|
||||
state = hass.states.get(ENTITY_VACUUM_BASIC)
|
||||
assert state.attributes.get(ATTR_SUPPORTED_FEATURES) == 195
|
||||
assert state.attributes.get(ATTR_STATUS) == "Charging"
|
||||
assert state.attributes.get(ATTR_SUPPORTED_FEATURES) == 12360
|
||||
assert state.attributes.get(ATTR_BATTERY_LEVEL) == 100
|
||||
assert state.attributes.get(ATTR_FAN_SPEED) is None
|
||||
assert state.attributes.get(ATTR_FAN_SPEED_LIST) is None
|
||||
assert state.state == STATE_OFF
|
||||
assert state.state == STATE_DOCKED
|
||||
|
||||
state = hass.states.get(ENTITY_VACUUM_MINIMAL)
|
||||
assert state.attributes.get(ATTR_SUPPORTED_FEATURES) == 3
|
||||
assert state.attributes.get(ATTR_STATUS) is None
|
||||
assert state.attributes.get(ATTR_BATTERY_LEVEL) is None
|
||||
assert state.attributes.get(ATTR_FAN_SPEED) is None
|
||||
assert state.attributes.get(ATTR_FAN_SPEED_LIST) is None
|
||||
assert state.state == STATE_OFF
|
||||
assert state.state == STATE_DOCKED
|
||||
|
||||
state = hass.states.get(ENTITY_VACUUM_NONE)
|
||||
assert state.attributes.get(ATTR_SUPPORTED_FEATURES) == 0
|
||||
assert state.attributes.get(ATTR_STATUS) is None
|
||||
assert state.attributes.get(ATTR_BATTERY_LEVEL) is None
|
||||
assert state.attributes.get(ATTR_FAN_SPEED) is None
|
||||
assert state.attributes.get(ATTR_FAN_SPEED_LIST) is None
|
||||
assert state.state == STATE_OFF
|
||||
|
||||
state = hass.states.get(ENTITY_VACUUM_STATE)
|
||||
assert state.attributes.get(ATTR_SUPPORTED_FEATURES) == 13436
|
||||
assert state.state == STATE_DOCKED
|
||||
assert state.attributes.get(ATTR_BATTERY_LEVEL) == 100
|
||||
assert state.attributes.get(ATTR_FAN_SPEED) == "medium"
|
||||
assert state.attributes.get(ATTR_FAN_SPEED_LIST) == FAN_SPEEDS
|
||||
|
||||
|
||||
async def test_methods(hass: HomeAssistant) -> None:
|
||||
"""Test if methods call the services as expected."""
|
||||
hass.states.async_set(ENTITY_VACUUM_BASIC, STATE_ON)
|
||||
await common.async_start(hass, ENTITY_VACUUM_BASIC)
|
||||
await hass.async_block_till_done()
|
||||
assert vacuum.is_on(hass, ENTITY_VACUUM_BASIC)
|
||||
state = hass.states.get(ENTITY_VACUUM_BASIC)
|
||||
assert state.state == STATE_CLEANING
|
||||
|
||||
hass.states.async_set(ENTITY_VACUUM_BASIC, STATE_OFF)
|
||||
await common.async_stop(hass, ENTITY_VACUUM_BASIC)
|
||||
await hass.async_block_till_done()
|
||||
assert not vacuum.is_on(hass, ENTITY_VACUUM_BASIC)
|
||||
|
||||
await common.async_turn_on(hass, ENTITY_VACUUM_COMPLETE)
|
||||
assert vacuum.is_on(hass, ENTITY_VACUUM_COMPLETE)
|
||||
|
||||
await common.async_turn_off(hass, ENTITY_VACUUM_COMPLETE)
|
||||
assert not vacuum.is_on(hass, ENTITY_VACUUM_COMPLETE)
|
||||
|
||||
await common.async_toggle(hass, ENTITY_VACUUM_COMPLETE)
|
||||
assert vacuum.is_on(hass, ENTITY_VACUUM_COMPLETE)
|
||||
|
||||
await common.async_start_pause(hass, ENTITY_VACUUM_COMPLETE)
|
||||
assert not vacuum.is_on(hass, ENTITY_VACUUM_COMPLETE)
|
||||
|
||||
await common.async_start_pause(hass, ENTITY_VACUUM_COMPLETE)
|
||||
assert vacuum.is_on(hass, ENTITY_VACUUM_COMPLETE)
|
||||
|
||||
await common.async_stop(hass, ENTITY_VACUUM_COMPLETE)
|
||||
assert not vacuum.is_on(hass, ENTITY_VACUUM_COMPLETE)
|
||||
state = hass.states.get(ENTITY_VACUUM_BASIC)
|
||||
assert state.state == STATE_IDLE
|
||||
|
||||
state = hass.states.get(ENTITY_VACUUM_COMPLETE)
|
||||
assert state.attributes.get(ATTR_BATTERY_LEVEL) < 100
|
||||
assert state.attributes.get(ATTR_STATUS) != "Charging"
|
||||
await hass.async_block_till_done()
|
||||
assert state.attributes.get(ATTR_BATTERY_LEVEL) == 100
|
||||
assert state.state == STATE_DOCKED
|
||||
|
||||
await async_setup_component(hass, "notify", {})
|
||||
await hass.async_block_till_done()
|
||||
await common.async_locate(hass, ENTITY_VACUUM_COMPLETE)
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get(ENTITY_VACUUM_COMPLETE)
|
||||
assert "I'm over here" in state.attributes.get(ATTR_STATUS)
|
||||
assert state.state == STATE_IDLE
|
||||
|
||||
await common.async_return_to_base(hass, ENTITY_VACUUM_COMPLETE)
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get(ENTITY_VACUUM_COMPLETE)
|
||||
assert "Returning home" in state.attributes.get(ATTR_STATUS)
|
||||
assert state.state == STATE_RETURNING
|
||||
|
||||
await common.async_set_fan_speed(
|
||||
hass, FAN_SPEEDS[-1], entity_id=ENTITY_VACUUM_COMPLETE
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get(ENTITY_VACUUM_COMPLETE)
|
||||
assert state.attributes.get(ATTR_FAN_SPEED) == FAN_SPEEDS[-1]
|
||||
|
||||
await common.async_clean_spot(hass, entity_id=ENTITY_VACUUM_COMPLETE)
|
||||
await common.async_clean_spot(hass, ENTITY_VACUUM_COMPLETE)
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get(ENTITY_VACUUM_COMPLETE)
|
||||
assert "spot" in state.attributes.get(ATTR_STATUS)
|
||||
assert state.state == STATE_ON
|
||||
|
||||
await common.async_start(hass, ENTITY_VACUUM_STATE)
|
||||
state = hass.states.get(ENTITY_VACUUM_STATE)
|
||||
assert state.state == STATE_CLEANING
|
||||
|
||||
await common.async_pause(hass, ENTITY_VACUUM_STATE)
|
||||
state = hass.states.get(ENTITY_VACUUM_STATE)
|
||||
await common.async_pause(hass, ENTITY_VACUUM_COMPLETE)
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get(ENTITY_VACUUM_COMPLETE)
|
||||
assert state.state == STATE_PAUSED
|
||||
|
||||
await common.async_stop(hass, ENTITY_VACUUM_STATE)
|
||||
state = hass.states.get(ENTITY_VACUUM_STATE)
|
||||
assert state.state == STATE_IDLE
|
||||
|
||||
state = hass.states.get(ENTITY_VACUUM_STATE)
|
||||
assert state.attributes.get(ATTR_BATTERY_LEVEL) < 100
|
||||
assert state.state != STATE_DOCKED
|
||||
|
||||
await common.async_return_to_base(hass, ENTITY_VACUUM_STATE)
|
||||
state = hass.states.get(ENTITY_VACUUM_STATE)
|
||||
await common.async_return_to_base(hass, ENTITY_VACUUM_COMPLETE)
|
||||
state = hass.states.get(ENTITY_VACUUM_COMPLETE)
|
||||
assert state.state == STATE_RETURNING
|
||||
|
||||
async_fire_time_changed(hass, dt_util.utcnow() + timedelta(seconds=31))
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get(ENTITY_VACUUM_STATE)
|
||||
state = hass.states.get(ENTITY_VACUUM_COMPLETE)
|
||||
assert state.state == STATE_DOCKED
|
||||
|
||||
await common.async_set_fan_speed(
|
||||
hass, FAN_SPEEDS[-1], entity_id=ENTITY_VACUUM_STATE
|
||||
)
|
||||
state = hass.states.get(ENTITY_VACUUM_STATE)
|
||||
assert state.attributes.get(ATTR_FAN_SPEED) == FAN_SPEEDS[-1]
|
||||
|
||||
await common.async_clean_spot(hass, entity_id=ENTITY_VACUUM_STATE)
|
||||
state = hass.states.get(ENTITY_VACUUM_STATE)
|
||||
assert state.state == STATE_CLEANING
|
||||
|
||||
|
||||
async def test_unsupported_methods(hass: HomeAssistant) -> None:
|
||||
"""Test service calls for unsupported vacuums."""
|
||||
hass.states.async_set(ENTITY_VACUUM_NONE, STATE_ON)
|
||||
await hass.async_block_till_done()
|
||||
assert vacuum.is_on(hass, ENTITY_VACUUM_NONE)
|
||||
|
||||
with pytest.raises(HomeAssistantError):
|
||||
await common.async_turn_off(hass, ENTITY_VACUUM_NONE)
|
||||
|
||||
with pytest.raises(HomeAssistantError):
|
||||
await common.async_stop(hass, ENTITY_VACUUM_NONE)
|
||||
|
||||
hass.states.async_set(ENTITY_VACUUM_NONE, STATE_OFF)
|
||||
await hass.async_block_till_done()
|
||||
assert not vacuum.is_on(hass, ENTITY_VACUUM_NONE)
|
||||
|
||||
with pytest.raises(HomeAssistantError):
|
||||
await common.async_turn_on(hass, ENTITY_VACUUM_NONE)
|
||||
|
||||
with pytest.raises(HomeAssistantError):
|
||||
await common.async_toggle(hass, ENTITY_VACUUM_NONE)
|
||||
|
||||
# Non supported methods:
|
||||
with pytest.raises(HomeAssistantError):
|
||||
await common.async_start_pause(hass, ENTITY_VACUUM_NONE)
|
||||
|
||||
with pytest.raises(HomeAssistantError):
|
||||
await common.async_locate(hass, ENTITY_VACUUM_NONE)
|
||||
|
||||
@ -244,34 +175,14 @@ async def test_unsupported_methods(hass: HomeAssistant) -> None:
|
||||
await common.async_set_fan_speed(
|
||||
hass, FAN_SPEEDS[-1], entity_id=ENTITY_VACUUM_NONE
|
||||
)
|
||||
with pytest.raises(HomeAssistantError):
|
||||
await common.async_clean_spot(hass, ENTITY_VACUUM_NONE)
|
||||
|
||||
with pytest.raises(HomeAssistantError):
|
||||
await common.async_clean_spot(hass, entity_id=ENTITY_VACUUM_BASIC)
|
||||
|
||||
# VacuumEntity should not support start and pause methods.
|
||||
hass.states.async_set(ENTITY_VACUUM_COMPLETE, STATE_ON)
|
||||
await hass.async_block_till_done()
|
||||
assert vacuum.is_on(hass, ENTITY_VACUUM_COMPLETE)
|
||||
|
||||
with pytest.raises(AttributeError):
|
||||
await common.async_pause(hass, ENTITY_VACUUM_COMPLETE)
|
||||
|
||||
hass.states.async_set(ENTITY_VACUUM_COMPLETE, STATE_OFF)
|
||||
await hass.async_block_till_done()
|
||||
assert not vacuum.is_on(hass, ENTITY_VACUUM_COMPLETE)
|
||||
await common.async_pause(hass, ENTITY_VACUUM_NONE)
|
||||
|
||||
with pytest.raises(HomeAssistantError):
|
||||
await common.async_start(hass, ENTITY_VACUUM_COMPLETE)
|
||||
|
||||
# StateVacuumEntity does not support on/off
|
||||
with pytest.raises(HomeAssistantError):
|
||||
await common.async_turn_on(hass, entity_id=ENTITY_VACUUM_STATE)
|
||||
|
||||
with pytest.raises(HomeAssistantError):
|
||||
await common.async_turn_off(hass, entity_id=ENTITY_VACUUM_STATE)
|
||||
|
||||
with pytest.raises(HomeAssistantError):
|
||||
await common.async_toggle(hass, entity_id=ENTITY_VACUUM_STATE)
|
||||
await common.async_start(hass, ENTITY_VACUUM_NONE)
|
||||
|
||||
|
||||
async def test_services(hass: HomeAssistant) -> None:
|
||||
@ -295,9 +206,7 @@ async def test_services(hass: HomeAssistant) -> None:
|
||||
# Test set fan speed
|
||||
set_fan_speed_calls = async_mock_service(hass, DOMAIN, SERVICE_SET_FAN_SPEED)
|
||||
|
||||
await common.async_set_fan_speed(
|
||||
hass, FAN_SPEEDS[0], entity_id=ENTITY_VACUUM_COMPLETE
|
||||
)
|
||||
await common.async_set_fan_speed(hass, FAN_SPEEDS[0], ENTITY_VACUUM_COMPLETE)
|
||||
assert len(set_fan_speed_calls) == 1
|
||||
call = set_fan_speed_calls[-1]
|
||||
|
||||
@ -309,22 +218,22 @@ async def test_services(hass: HomeAssistant) -> None:
|
||||
|
||||
async def test_set_fan_speed(hass: HomeAssistant) -> None:
|
||||
"""Test vacuum service to set the fan speed."""
|
||||
group_vacuums = ",".join([ENTITY_VACUUM_COMPLETE, ENTITY_VACUUM_STATE])
|
||||
group_vacuums = ",".join([ENTITY_VACUUM_COMPLETE, ENTITY_VACUUM_MOST])
|
||||
old_state_complete = hass.states.get(ENTITY_VACUUM_COMPLETE)
|
||||
old_state_state = hass.states.get(ENTITY_VACUUM_STATE)
|
||||
old_state_most = hass.states.get(ENTITY_VACUUM_MOST)
|
||||
|
||||
await common.async_set_fan_speed(hass, FAN_SPEEDS[0], entity_id=group_vacuums)
|
||||
|
||||
new_state_complete = hass.states.get(ENTITY_VACUUM_COMPLETE)
|
||||
new_state_state = hass.states.get(ENTITY_VACUUM_STATE)
|
||||
new_state_most = hass.states.get(ENTITY_VACUUM_MOST)
|
||||
|
||||
assert old_state_complete != new_state_complete
|
||||
assert old_state_complete.attributes[ATTR_FAN_SPEED] == FAN_SPEEDS[1]
|
||||
assert new_state_complete.attributes[ATTR_FAN_SPEED] == FAN_SPEEDS[0]
|
||||
|
||||
assert old_state_state != new_state_state
|
||||
assert old_state_state.attributes[ATTR_FAN_SPEED] == FAN_SPEEDS[1]
|
||||
assert new_state_state.attributes[ATTR_FAN_SPEED] == FAN_SPEEDS[0]
|
||||
assert old_state_most != new_state_most
|
||||
assert old_state_most.attributes[ATTR_FAN_SPEED] == FAN_SPEEDS[1]
|
||||
assert new_state_most.attributes[ATTR_FAN_SPEED] == FAN_SPEEDS[0]
|
||||
|
||||
|
||||
async def test_send_command(hass: HomeAssistant) -> None:
|
||||
@ -339,8 +248,4 @@ async def test_send_command(hass: HomeAssistant) -> None:
|
||||
new_state_complete = hass.states.get(ENTITY_VACUUM_COMPLETE)
|
||||
|
||||
assert old_state_complete != new_state_complete
|
||||
assert new_state_complete.state == STATE_ON
|
||||
assert (
|
||||
new_state_complete.attributes[ATTR_STATUS]
|
||||
== "Executing test_command({'p1': 3})"
|
||||
)
|
||||
assert new_state_complete.state == STATE_IDLE
|
||||
|
Loading…
x
Reference in New Issue
Block a user