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 the Demo vacuum platform."""
|
2021-12-17 11:45:53 +00:00
|
|
|
from datetime import timedelta
|
|
|
|
|
2020-04-06 17:09:44 +00:00
|
|
|
import pytest
|
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
|
|
|
|
|
|
|
from homeassistant.components import vacuum
|
2019-12-08 16:59:27 +00:00
|
|
|
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,
|
|
|
|
)
|
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
|
|
|
from homeassistant.components.vacuum import (
|
2019-07-31 19:25:30 +00:00
|
|
|
ATTR_BATTERY_LEVEL,
|
|
|
|
ATTR_COMMAND,
|
|
|
|
ATTR_FAN_SPEED,
|
|
|
|
ATTR_FAN_SPEED_LIST,
|
|
|
|
ATTR_PARAMS,
|
|
|
|
ATTR_STATUS,
|
|
|
|
DOMAIN,
|
|
|
|
SERVICE_SEND_COMMAND,
|
|
|
|
SERVICE_SET_FAN_SPEED,
|
|
|
|
STATE_CLEANING,
|
2019-12-08 16:59:27 +00:00
|
|
|
STATE_DOCKED,
|
2019-07-31 19:25:30 +00:00
|
|
|
STATE_IDLE,
|
2019-12-08 16:59:27 +00:00
|
|
|
STATE_PAUSED,
|
2019-07-31 19:25:30 +00:00
|
|
|
STATE_RETURNING,
|
|
|
|
)
|
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
|
|
|
from homeassistant.const import (
|
2019-07-31 19:25:30 +00:00
|
|
|
ATTR_ENTITY_ID,
|
|
|
|
ATTR_SUPPORTED_FEATURES,
|
|
|
|
CONF_PLATFORM,
|
|
|
|
STATE_OFF,
|
|
|
|
STATE_ON,
|
|
|
|
)
|
2020-04-06 17:09:44 +00:00
|
|
|
from homeassistant.setup import async_setup_component
|
2021-12-17 11:45:53 +00:00
|
|
|
from homeassistant.util import dt
|
2018-09-26 16:02:05 +00:00
|
|
|
|
2021-12-17 11:45:53 +00:00
|
|
|
from tests.common import async_fire_time_changed, async_mock_service
|
2018-09-26 16:02:05 +00:00
|
|
|
from tests.components.vacuum import common
|
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
|
|
|
|
2020-04-04 22:26:08 +00:00
|
|
|
ENTITY_VACUUM_BASIC = f"{DOMAIN}.{DEMO_VACUUM_BASIC}".lower()
|
|
|
|
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()
|
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
|
|
|
|
|
|
|
|
2020-04-06 17:09:44 +00:00
|
|
|
@pytest.fixture(autouse=True)
|
|
|
|
async def setup_demo_vacuum(hass):
|
|
|
|
"""Initialize setup demo vacuum."""
|
|
|
|
assert await async_setup_component(hass, DOMAIN, {DOMAIN: {CONF_PLATFORM: "demo"}})
|
2020-06-01 05:18:30 +00:00
|
|
|
await hass.async_block_till_done()
|
2020-04-06 17:09:44 +00:00
|
|
|
|
|
|
|
|
|
|
|
async def test_supported_features(hass):
|
|
|
|
"""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_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
|
|
|
|
|
|
|
|
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_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
|
|
|
|
|
|
|
|
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_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
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
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):
|
|
|
|
"""Test if methods call the services as expected."""
|
|
|
|
hass.states.async_set(ENTITY_VACUUM_BASIC, STATE_ON)
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
assert vacuum.is_on(hass, ENTITY_VACUUM_BASIC)
|
|
|
|
|
|
|
|
hass.states.async_set(ENTITY_VACUUM_BASIC, STATE_OFF)
|
|
|
|
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_COMPLETE)
|
|
|
|
assert state.attributes.get(ATTR_BATTERY_LEVEL) < 100
|
|
|
|
assert state.attributes.get(ATTR_STATUS) != "Charging"
|
|
|
|
|
|
|
|
await common.async_locate(hass, ENTITY_VACUUM_COMPLETE)
|
|
|
|
state = hass.states.get(ENTITY_VACUUM_COMPLETE)
|
|
|
|
assert "I'm over here" in state.attributes.get(ATTR_STATUS)
|
|
|
|
|
|
|
|
await common.async_return_to_base(hass, ENTITY_VACUUM_COMPLETE)
|
|
|
|
state = hass.states.get(ENTITY_VACUUM_COMPLETE)
|
|
|
|
assert "Returning home" in state.attributes.get(ATTR_STATUS)
|
|
|
|
|
|
|
|
await common.async_set_fan_speed(
|
|
|
|
hass, FAN_SPEEDS[-1], entity_id=ENTITY_VACUUM_COMPLETE
|
|
|
|
)
|
|
|
|
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)
|
|
|
|
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)
|
|
|
|
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)
|
|
|
|
assert state.state == STATE_RETURNING
|
|
|
|
|
2021-12-17 11:45:53 +00:00
|
|
|
async_fire_time_changed(hass, dt.utcnow() + timedelta(seconds=31))
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
state = hass.states.get(ENTITY_VACUUM_STATE)
|
|
|
|
assert state.state == STATE_DOCKED
|
|
|
|
|
2020-04-06 17:09:44 +00:00
|
|
|
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):
|
|
|
|
"""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)
|
|
|
|
|
|
|
|
await common.async_turn_off(hass, ENTITY_VACUUM_NONE)
|
|
|
|
assert vacuum.is_on(hass, ENTITY_VACUUM_NONE)
|
|
|
|
|
|
|
|
await common.async_stop(hass, ENTITY_VACUUM_NONE)
|
|
|
|
assert vacuum.is_on(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)
|
|
|
|
|
|
|
|
await common.async_turn_on(hass, ENTITY_VACUUM_NONE)
|
|
|
|
assert not vacuum.is_on(hass, ENTITY_VACUUM_NONE)
|
|
|
|
|
|
|
|
await common.async_toggle(hass, ENTITY_VACUUM_NONE)
|
|
|
|
assert not vacuum.is_on(hass, ENTITY_VACUUM_NONE)
|
|
|
|
|
|
|
|
# Non supported methods:
|
|
|
|
await common.async_start_pause(hass, ENTITY_VACUUM_NONE)
|
|
|
|
assert not vacuum.is_on(hass, ENTITY_VACUUM_NONE)
|
|
|
|
|
|
|
|
await common.async_locate(hass, ENTITY_VACUUM_NONE)
|
|
|
|
state = hass.states.get(ENTITY_VACUUM_NONE)
|
|
|
|
assert state.attributes.get(ATTR_STATUS) is None
|
|
|
|
|
|
|
|
await common.async_return_to_base(hass, ENTITY_VACUUM_NONE)
|
|
|
|
state = hass.states.get(ENTITY_VACUUM_NONE)
|
|
|
|
assert state.attributes.get(ATTR_STATUS) is None
|
|
|
|
|
|
|
|
await common.async_set_fan_speed(hass, FAN_SPEEDS[-1], entity_id=ENTITY_VACUUM_NONE)
|
|
|
|
state = hass.states.get(ENTITY_VACUUM_NONE)
|
|
|
|
assert state.attributes.get(ATTR_FAN_SPEED) != FAN_SPEEDS[-1]
|
|
|
|
|
|
|
|
await common.async_clean_spot(hass, entity_id=ENTITY_VACUUM_BASIC)
|
|
|
|
state = hass.states.get(ENTITY_VACUUM_BASIC)
|
|
|
|
assert "spot" not in state.attributes.get(ATTR_STATUS)
|
|
|
|
assert state.state == STATE_OFF
|
|
|
|
|
2020-04-26 00:11:08 +00:00
|
|
|
# VacuumEntity should not support start and pause methods.
|
2020-04-06 17:09:44 +00:00
|
|
|
hass.states.async_set(ENTITY_VACUUM_COMPLETE, STATE_ON)
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
assert vacuum.is_on(hass, ENTITY_VACUUM_COMPLETE)
|
|
|
|
|
|
|
|
await common.async_pause(hass, ENTITY_VACUUM_COMPLETE)
|
|
|
|
assert vacuum.is_on(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_start(hass, ENTITY_VACUUM_COMPLETE)
|
|
|
|
assert not vacuum.is_on(hass, ENTITY_VACUUM_COMPLETE)
|
|
|
|
|
2020-04-26 00:11:08 +00:00
|
|
|
# StateVacuumEntity does not support on/off
|
2020-04-06 17:09:44 +00:00
|
|
|
await common.async_turn_on(hass, entity_id=ENTITY_VACUUM_STATE)
|
|
|
|
state = hass.states.get(ENTITY_VACUUM_STATE)
|
|
|
|
assert state.state != STATE_CLEANING
|
|
|
|
|
|
|
|
await common.async_turn_off(hass, entity_id=ENTITY_VACUUM_STATE)
|
|
|
|
state = hass.states.get(ENTITY_VACUUM_STATE)
|
|
|
|
assert state.state != STATE_RETURNING
|
|
|
|
|
|
|
|
await common.async_toggle(hass, entity_id=ENTITY_VACUUM_STATE)
|
|
|
|
state = hass.states.get(ENTITY_VACUUM_STATE)
|
|
|
|
assert state.state != STATE_CLEANING
|
|
|
|
|
|
|
|
|
|
|
|
async def test_services(hass):
|
|
|
|
"""Test vacuum services."""
|
|
|
|
# Test send_command
|
|
|
|
send_command_calls = async_mock_service(hass, DOMAIN, SERVICE_SEND_COMMAND)
|
|
|
|
|
|
|
|
params = {"rotate": 150, "speed": 20}
|
|
|
|
await common.async_send_command(
|
|
|
|
hass, "test_command", entity_id=ENTITY_VACUUM_BASIC, params=params
|
|
|
|
)
|
|
|
|
assert len(send_command_calls) == 1
|
|
|
|
call = send_command_calls[-1]
|
|
|
|
|
|
|
|
assert call.domain == DOMAIN
|
|
|
|
assert call.service == SERVICE_SEND_COMMAND
|
|
|
|
assert call.data[ATTR_ENTITY_ID] == ENTITY_VACUUM_BASIC
|
|
|
|
assert call.data[ATTR_COMMAND] == "test_command"
|
|
|
|
assert call.data[ATTR_PARAMS] == params
|
|
|
|
|
|
|
|
# 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
|
|
|
|
)
|
|
|
|
assert len(set_fan_speed_calls) == 1
|
|
|
|
call = set_fan_speed_calls[-1]
|
|
|
|
|
|
|
|
assert call.domain == DOMAIN
|
|
|
|
assert call.service == SERVICE_SET_FAN_SPEED
|
|
|
|
assert call.data[ATTR_ENTITY_ID] == ENTITY_VACUUM_COMPLETE
|
|
|
|
assert call.data[ATTR_FAN_SPEED] == FAN_SPEEDS[0]
|
|
|
|
|
|
|
|
|
|
|
|
async def test_set_fan_speed(hass):
|
|
|
|
"""Test vacuum service to set the fan speed."""
|
|
|
|
group_vacuums = ",".join(
|
|
|
|
[ENTITY_VACUUM_BASIC, ENTITY_VACUUM_COMPLETE, ENTITY_VACUUM_STATE]
|
|
|
|
)
|
|
|
|
old_state_basic = hass.states.get(ENTITY_VACUUM_BASIC)
|
|
|
|
old_state_complete = hass.states.get(ENTITY_VACUUM_COMPLETE)
|
|
|
|
old_state_state = hass.states.get(ENTITY_VACUUM_STATE)
|
|
|
|
|
|
|
|
await common.async_set_fan_speed(hass, FAN_SPEEDS[0], entity_id=group_vacuums)
|
|
|
|
|
|
|
|
new_state_basic = hass.states.get(ENTITY_VACUUM_BASIC)
|
|
|
|
new_state_complete = hass.states.get(ENTITY_VACUUM_COMPLETE)
|
|
|
|
new_state_state = hass.states.get(ENTITY_VACUUM_STATE)
|
|
|
|
|
|
|
|
assert old_state_basic == new_state_basic
|
|
|
|
assert ATTR_FAN_SPEED not in new_state_basic.attributes
|
|
|
|
|
|
|
|
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]
|
|
|
|
|
|
|
|
|
|
|
|
async def test_send_command(hass):
|
|
|
|
"""Test vacuum service to send a command."""
|
|
|
|
group_vacuums = ",".join([ENTITY_VACUUM_BASIC, ENTITY_VACUUM_COMPLETE])
|
|
|
|
old_state_basic = hass.states.get(ENTITY_VACUUM_BASIC)
|
|
|
|
old_state_complete = hass.states.get(ENTITY_VACUUM_COMPLETE)
|
|
|
|
|
|
|
|
await common.async_send_command(
|
|
|
|
hass, "test_command", params={"p1": 3}, entity_id=group_vacuums
|
|
|
|
)
|
|
|
|
|
|
|
|
new_state_basic = hass.states.get(ENTITY_VACUUM_BASIC)
|
|
|
|
new_state_complete = hass.states.get(ENTITY_VACUUM_COMPLETE)
|
|
|
|
|
|
|
|
assert old_state_basic == new_state_basic
|
|
|
|
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})"
|
|
|
|
)
|