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 Xiaomi vacuum platform."""
|
2019-12-10 08:25:42 +00:00
|
|
|
from datetime import time, timedelta
|
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 unittest import mock
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
|
|
|
|
from homeassistant.components.vacuum import (
|
|
|
|
ATTR_BATTERY_ICON,
|
2019-07-31 19:25:30 +00:00
|
|
|
ATTR_FAN_SPEED,
|
|
|
|
ATTR_FAN_SPEED_LIST,
|
|
|
|
DOMAIN,
|
|
|
|
SERVICE_CLEAN_SPOT,
|
|
|
|
SERVICE_LOCATE,
|
|
|
|
SERVICE_RETURN_TO_BASE,
|
|
|
|
SERVICE_SEND_COMMAND,
|
|
|
|
SERVICE_SET_FAN_SPEED,
|
2019-11-09 13:07:01 +00:00
|
|
|
SERVICE_START,
|
2019-07-31 19:25:30 +00:00
|
|
|
SERVICE_STOP,
|
2019-11-09 13:07:01 +00:00
|
|
|
STATE_CLEANING,
|
|
|
|
STATE_ERROR,
|
2019-07-31 19:25:30 +00:00
|
|
|
)
|
2019-02-02 15:13:16 +00:00
|
|
|
from homeassistant.components.xiaomi_miio.vacuum import (
|
2019-07-31 19:25:30 +00:00
|
|
|
ATTR_CLEANED_AREA,
|
2019-12-10 08:25:42 +00:00
|
|
|
ATTR_CLEANED_TOTAL_AREA,
|
|
|
|
ATTR_CLEANING_COUNT,
|
2019-07-31 19:25:30 +00:00
|
|
|
ATTR_CLEANING_TIME,
|
2019-12-10 08:25:42 +00:00
|
|
|
ATTR_CLEANING_TOTAL_TIME,
|
2019-07-31 19:25:30 +00:00
|
|
|
ATTR_DO_NOT_DISTURB,
|
|
|
|
ATTR_DO_NOT_DISTURB_END,
|
2019-12-10 08:25:42 +00:00
|
|
|
ATTR_DO_NOT_DISTURB_START,
|
2019-07-31 19:25:30 +00:00
|
|
|
ATTR_ERROR,
|
2019-12-10 08:25:42 +00:00
|
|
|
ATTR_FILTER_LEFT,
|
2019-07-31 19:25:30 +00:00
|
|
|
ATTR_MAIN_BRUSH_LEFT,
|
|
|
|
ATTR_SIDE_BRUSH_LEFT,
|
|
|
|
CONF_HOST,
|
|
|
|
CONF_NAME,
|
|
|
|
CONF_TOKEN,
|
2019-12-02 19:49:39 +00:00
|
|
|
DOMAIN as XIAOMI_DOMAIN,
|
2019-12-10 08:25:42 +00:00
|
|
|
SERVICE_CLEAN_ZONE,
|
2019-07-31 19:25:30 +00:00
|
|
|
SERVICE_MOVE_REMOTE_CONTROL,
|
|
|
|
SERVICE_MOVE_REMOTE_CONTROL_STEP,
|
|
|
|
SERVICE_START_REMOTE_CONTROL,
|
|
|
|
SERVICE_STOP_REMOTE_CONTROL,
|
|
|
|
)
|
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,
|
|
|
|
)
|
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.setup import async_setup_component
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
PLATFORM = "xiaomi_miio"
|
2018-02-28 21:15:45 +00:00
|
|
|
|
2017-12-01 11:28:59 +00:00
|
|
|
# calls made when device status is requested
|
2019-11-09 13:07:01 +00:00
|
|
|
STATUS_CALLS = [
|
|
|
|
mock.call.status(),
|
|
|
|
mock.call.consumable_status(),
|
|
|
|
mock.call.clean_history(),
|
|
|
|
mock.call.dnd_status(),
|
2019-07-31 19:25:30 +00:00
|
|
|
]
|
2017-12-01 11:28:59 +00:00
|
|
|
|
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
|
|
|
|
2019-11-09 13:07:01 +00:00
|
|
|
@pytest.fixture(name="mock_mirobo_is_got_error")
|
|
|
|
def mirobo_is_got_error_fixture():
|
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
|
|
|
"""Mock mock_mirobo."""
|
|
|
|
mock_vacuum = mock.MagicMock()
|
2019-11-09 13:07:01 +00:00
|
|
|
mock_vacuum.status().data = {"test": "raw"}
|
|
|
|
mock_vacuum.status().is_on = False
|
|
|
|
mock_vacuum.status().fanspeed = 38
|
|
|
|
mock_vacuum.status().got_error = True
|
|
|
|
mock_vacuum.status().error = "Error message"
|
|
|
|
mock_vacuum.status().battery = 82
|
|
|
|
mock_vacuum.status().clean_area = 123.43218
|
|
|
|
mock_vacuum.status().clean_time = timedelta(hours=2, minutes=35, seconds=34)
|
|
|
|
mock_vacuum.consumable_status().main_brush_left = timedelta(
|
2019-07-31 19:25:30 +00:00
|
|
|
hours=12, minutes=35, seconds=34
|
|
|
|
)
|
2019-11-09 13:07:01 +00:00
|
|
|
mock_vacuum.consumable_status().side_brush_left = timedelta(
|
2019-07-31 19:25:30 +00:00
|
|
|
hours=12, minutes=35, seconds=34
|
|
|
|
)
|
2019-11-09 13:07:01 +00:00
|
|
|
mock_vacuum.consumable_status().filter_left = timedelta(
|
2019-07-31 19:25:30 +00:00
|
|
|
hours=12, minutes=35, seconds=34
|
|
|
|
)
|
2019-11-09 13:07:01 +00:00
|
|
|
mock_vacuum.clean_history().count = "35"
|
|
|
|
mock_vacuum.clean_history().total_area = 123.43218
|
|
|
|
mock_vacuum.clean_history().total_duration = timedelta(
|
2019-07-31 19:25:30 +00:00
|
|
|
hours=11, minutes=35, seconds=34
|
|
|
|
)
|
2019-11-09 13:07:01 +00:00
|
|
|
mock_vacuum.status().state = "Test Xiaomi Charging"
|
|
|
|
mock_vacuum.dnd_status().enabled = True
|
|
|
|
mock_vacuum.dnd_status().start = time(hour=22, minute=0)
|
|
|
|
mock_vacuum.dnd_status().end = time(hour=6, minute=0)
|
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
|
|
|
|
2019-11-09 13:07:01 +00:00
|
|
|
with mock.patch(
|
|
|
|
"homeassistant.components.xiaomi_miio.vacuum.Vacuum"
|
|
|
|
) as mock_vaccum_cls:
|
|
|
|
mock_vaccum_cls.return_value = mock_vacuum
|
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
|
|
|
yield mock_vacuum
|
|
|
|
|
|
|
|
|
2019-11-09 13:07:01 +00:00
|
|
|
@pytest.fixture(name="mock_mirobo_is_on")
|
|
|
|
def mirobo_is_on_fixture():
|
2017-08-05 19:45:59 +00:00
|
|
|
"""Mock mock_mirobo."""
|
|
|
|
mock_vacuum = mock.MagicMock()
|
2019-11-09 13:07:01 +00:00
|
|
|
mock_vacuum.status().data = {"test": "raw"}
|
|
|
|
mock_vacuum.status().is_on = True
|
|
|
|
mock_vacuum.status().fanspeed = 99
|
|
|
|
mock_vacuum.status().got_error = False
|
|
|
|
mock_vacuum.status().battery = 32
|
|
|
|
mock_vacuum.status().clean_area = 133.43218
|
|
|
|
mock_vacuum.status().clean_time = timedelta(hours=2, minutes=55, seconds=34)
|
|
|
|
mock_vacuum.consumable_status().main_brush_left = timedelta(
|
2019-07-31 19:25:30 +00:00
|
|
|
hours=11, minutes=35, seconds=34
|
|
|
|
)
|
2019-11-09 13:07:01 +00:00
|
|
|
mock_vacuum.consumable_status().side_brush_left = timedelta(
|
2019-07-31 19:25:30 +00:00
|
|
|
hours=11, minutes=35, seconds=34
|
|
|
|
)
|
2019-11-09 13:07:01 +00:00
|
|
|
mock_vacuum.consumable_status().filter_left = timedelta(
|
2019-07-31 19:25:30 +00:00
|
|
|
hours=11, minutes=35, seconds=34
|
|
|
|
)
|
2019-11-09 13:07:01 +00:00
|
|
|
mock_vacuum.clean_history().count = "41"
|
|
|
|
mock_vacuum.clean_history().total_area = 323.43218
|
|
|
|
mock_vacuum.clean_history().total_duration = timedelta(
|
2019-07-31 19:25:30 +00:00
|
|
|
hours=11, minutes=15, seconds=34
|
|
|
|
)
|
2019-11-09 13:07:01 +00:00
|
|
|
mock_vacuum.status().state = "Test Xiaomi Cleaning"
|
|
|
|
mock_vacuum.status().state_code = 5
|
|
|
|
mock_vacuum.dnd_status().enabled = False
|
2017-08-05 19:45:59 +00:00
|
|
|
|
2019-11-09 13:07:01 +00:00
|
|
|
with mock.patch(
|
|
|
|
"homeassistant.components.xiaomi_miio.vacuum.Vacuum"
|
|
|
|
) as mock_vaccum_cls:
|
|
|
|
mock_vaccum_cls.return_value = mock_vacuum
|
2017-08-05 19:45:59 +00:00
|
|
|
yield mock_vacuum
|
|
|
|
|
|
|
|
|
2019-11-09 13:07:01 +00:00
|
|
|
@pytest.fixture(name="mock_mirobo_errors")
|
|
|
|
def mirobo_errors_fixture():
|
2017-08-05 19:45:59 +00:00
|
|
|
"""Mock mock_mirobo_errors to simulate a bad vacuum status request."""
|
|
|
|
mock_vacuum = mock.MagicMock()
|
2019-11-09 13:07:01 +00:00
|
|
|
mock_vacuum.status.side_effect = OSError()
|
|
|
|
with mock.patch(
|
|
|
|
"homeassistant.components.xiaomi_miio.vacuum.Vacuum"
|
|
|
|
) as mock_vaccum_cls:
|
|
|
|
mock_vaccum_cls.return_value = mock_vacuum
|
2017-08-05 19:45:59 +00:00
|
|
|
yield mock_vacuum
|
|
|
|
|
|
|
|
|
2019-12-31 22:49:00 +00:00
|
|
|
async def test_xiaomi_exceptions(hass, caplog, mock_mirobo_errors):
|
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
|
|
|
"""Test vacuum supported features."""
|
2019-07-31 19:25:30 +00:00
|
|
|
entity_name = "test_vacuum_cleaner_error"
|
2019-12-31 22:49:00 +00:00
|
|
|
await async_setup_component(
|
2019-07-31 19:25:30 +00:00
|
|
|
hass,
|
|
|
|
DOMAIN,
|
|
|
|
{
|
|
|
|
DOMAIN: {
|
|
|
|
CONF_PLATFORM: PLATFORM,
|
|
|
|
CONF_HOST: "127.0.0.1",
|
|
|
|
CONF_NAME: entity_name,
|
|
|
|
CONF_TOKEN: "12345678901234567890123456789012",
|
|
|
|
}
|
|
|
|
},
|
|
|
|
)
|
2019-12-31 22:49:00 +00:00
|
|
|
await hass.async_block_till_done()
|
2019-07-31 19:25:30 +00:00
|
|
|
|
|
|
|
assert "Initializing with host 127.0.0.1 (token 12345...)" in caplog.text
|
2019-11-09 13:07:01 +00:00
|
|
|
assert mock_mirobo_errors.status.call_count == 1
|
2019-07-31 19:25:30 +00:00
|
|
|
assert "ERROR" in caplog.text
|
|
|
|
assert "Got OSError while fetching the state" in caplog.text
|
2017-08-05 19:45:59 +00:00
|
|
|
|
|
|
|
|
2019-12-31 22:49:00 +00:00
|
|
|
async def test_xiaomi_vacuum_services(hass, caplog, mock_mirobo_is_got_error):
|
2017-08-05 19:45:59 +00:00
|
|
|
"""Test vacuum supported features."""
|
2019-07-31 19:25:30 +00:00
|
|
|
entity_name = "test_vacuum_cleaner_1"
|
2020-01-03 13:47:06 +00:00
|
|
|
entity_id = f"{DOMAIN}.{entity_name}"
|
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
|
|
|
|
2019-12-31 22:49:00 +00:00
|
|
|
await async_setup_component(
|
2019-07-31 19:25:30 +00:00
|
|
|
hass,
|
|
|
|
DOMAIN,
|
|
|
|
{
|
|
|
|
DOMAIN: {
|
|
|
|
CONF_PLATFORM: PLATFORM,
|
|
|
|
CONF_HOST: "127.0.0.1",
|
|
|
|
CONF_NAME: entity_name,
|
|
|
|
CONF_TOKEN: "12345678901234567890123456789012",
|
|
|
|
}
|
|
|
|
},
|
|
|
|
)
|
2019-12-31 22:49:00 +00:00
|
|
|
await hass.async_block_till_done()
|
2019-07-31 19:25:30 +00:00
|
|
|
|
|
|
|
assert "Initializing with host 127.0.0.1 (token 12345...)" in caplog.text
|
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
|
|
|
|
|
|
|
# Check state attributes
|
|
|
|
state = hass.states.get(entity_id)
|
|
|
|
|
2019-11-09 13:07:01 +00:00
|
|
|
assert state.state == STATE_ERROR
|
|
|
|
assert state.attributes.get(ATTR_SUPPORTED_FEATURES) == 14204
|
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
|
|
|
assert state.attributes.get(ATTR_DO_NOT_DISTURB) == STATE_ON
|
2019-07-31 19:25:30 +00:00
|
|
|
assert state.attributes.get(ATTR_DO_NOT_DISTURB_START) == "22:00:00"
|
|
|
|
assert state.attributes.get(ATTR_DO_NOT_DISTURB_END) == "06:00:00"
|
|
|
|
assert state.attributes.get(ATTR_ERROR) == "Error message"
|
2019-11-09 13:07:01 +00:00
|
|
|
assert state.attributes.get(ATTR_BATTERY_ICON) == "mdi:battery-80"
|
2017-09-25 20:27:27 +00:00
|
|
|
assert state.attributes.get(ATTR_CLEANING_TIME) == 155
|
|
|
|
assert state.attributes.get(ATTR_CLEANED_AREA) == 123
|
2020-01-09 22:49:13 +00:00
|
|
|
assert state.attributes.get(ATTR_FAN_SPEED) == "Silent"
|
2019-07-31 19:25:30 +00:00
|
|
|
assert state.attributes.get(ATTR_FAN_SPEED_LIST) == [
|
2020-01-09 22:49:13 +00:00
|
|
|
"Silent",
|
|
|
|
"Standard",
|
|
|
|
"Medium",
|
2019-07-31 19:25:30 +00:00
|
|
|
"Turbo",
|
2019-11-27 12:46:13 +00:00
|
|
|
"Gentle",
|
2019-07-31 19:25:30 +00:00
|
|
|
]
|
2017-09-25 20:27:27 +00:00
|
|
|
assert state.attributes.get(ATTR_MAIN_BRUSH_LEFT) == 12
|
|
|
|
assert state.attributes.get(ATTR_SIDE_BRUSH_LEFT) == 12
|
|
|
|
assert state.attributes.get(ATTR_FILTER_LEFT) == 12
|
|
|
|
assert state.attributes.get(ATTR_CLEANING_COUNT) == 35
|
|
|
|
assert state.attributes.get(ATTR_CLEANED_TOTAL_AREA) == 123
|
|
|
|
assert state.attributes.get(ATTR_CLEANING_TOTAL_TIME) == 695
|
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
|
|
|
|
|
|
|
# Call services
|
2019-12-31 22:49:00 +00:00
|
|
|
await hass.services.async_call(
|
2019-11-09 13:07:01 +00:00
|
|
|
DOMAIN, SERVICE_START, {"entity_id": entity_id}, blocking=True
|
|
|
|
)
|
|
|
|
mock_mirobo_is_got_error.assert_has_calls(
|
|
|
|
[mock.call.resume_or_start()], any_order=True
|
|
|
|
)
|
|
|
|
mock_mirobo_is_got_error.assert_has_calls(STATUS_CALLS, any_order=True)
|
|
|
|
mock_mirobo_is_got_error.reset_mock()
|
|
|
|
|
2019-12-31 22:49:00 +00:00
|
|
|
await hass.services.async_call(
|
2019-11-09 13:07:01 +00:00
|
|
|
DOMAIN, SERVICE_STOP, {"entity_id": entity_id}, blocking=True
|
|
|
|
)
|
|
|
|
mock_mirobo_is_got_error.assert_has_calls([mock.call.stop()], any_order=True)
|
|
|
|
mock_mirobo_is_got_error.assert_has_calls(STATUS_CALLS, any_order=True)
|
|
|
|
mock_mirobo_is_got_error.reset_mock()
|
|
|
|
|
2019-12-31 22:49:00 +00:00
|
|
|
await hass.services.async_call(
|
2019-11-09 13:07:01 +00:00
|
|
|
DOMAIN, SERVICE_RETURN_TO_BASE, {"entity_id": entity_id}, blocking=True
|
|
|
|
)
|
|
|
|
mock_mirobo_is_got_error.assert_has_calls([mock.call.home()], any_order=True)
|
|
|
|
mock_mirobo_is_got_error.assert_has_calls(STATUS_CALLS, any_order=True)
|
|
|
|
mock_mirobo_is_got_error.reset_mock()
|
|
|
|
|
2019-12-31 22:49:00 +00:00
|
|
|
await hass.services.async_call(
|
2019-11-09 13:07:01 +00:00
|
|
|
DOMAIN, SERVICE_LOCATE, {"entity_id": entity_id}, blocking=True
|
|
|
|
)
|
|
|
|
mock_mirobo_is_got_error.assert_has_calls([mock.call.find()], any_order=True)
|
|
|
|
mock_mirobo_is_got_error.assert_has_calls(STATUS_CALLS, any_order=True)
|
|
|
|
mock_mirobo_is_got_error.reset_mock()
|
|
|
|
|
2019-12-31 22:49:00 +00:00
|
|
|
await hass.services.async_call(
|
2019-11-09 13:07:01 +00:00
|
|
|
DOMAIN, SERVICE_CLEAN_SPOT, {"entity_id": entity_id}, blocking=True
|
|
|
|
)
|
|
|
|
mock_mirobo_is_got_error.assert_has_calls([mock.call.spot()], any_order=True)
|
|
|
|
mock_mirobo_is_got_error.assert_has_calls(STATUS_CALLS, any_order=True)
|
|
|
|
mock_mirobo_is_got_error.reset_mock()
|
2017-08-06 17:23:22 +00:00
|
|
|
|
2017-08-05 19:45:59 +00:00
|
|
|
# Set speed service:
|
2019-12-31 22:49:00 +00:00
|
|
|
await hass.services.async_call(
|
2019-11-09 13:07:01 +00:00
|
|
|
DOMAIN,
|
|
|
|
SERVICE_SET_FAN_SPEED,
|
|
|
|
{"entity_id": entity_id, "fan_speed": 60},
|
|
|
|
blocking=True,
|
2019-07-31 19:25:30 +00:00
|
|
|
)
|
2019-11-09 13:07:01 +00:00
|
|
|
mock_mirobo_is_got_error.assert_has_calls(
|
|
|
|
[mock.call.set_fan_speed(60)], any_order=True
|
2019-07-31 19:25:30 +00:00
|
|
|
)
|
2019-11-09 13:07:01 +00:00
|
|
|
mock_mirobo_is_got_error.assert_has_calls(STATUS_CALLS, any_order=True)
|
|
|
|
mock_mirobo_is_got_error.reset_mock()
|
2017-08-05 19:45:59 +00:00
|
|
|
|
2019-12-31 22:49:00 +00:00
|
|
|
await hass.services.async_call(
|
2019-11-09 13:07:01 +00:00
|
|
|
DOMAIN,
|
|
|
|
SERVICE_SET_FAN_SPEED,
|
2020-01-09 22:49:13 +00:00
|
|
|
{"entity_id": entity_id, "fan_speed": "Medium"},
|
2019-11-09 13:07:01 +00:00
|
|
|
blocking=True,
|
2019-07-31 19:25:30 +00:00
|
|
|
)
|
2019-11-09 13:07:01 +00:00
|
|
|
mock_mirobo_is_got_error.assert_has_calls(
|
|
|
|
[mock.call.set_fan_speed(77)], any_order=True
|
2019-07-31 19:25:30 +00:00
|
|
|
)
|
2019-11-09 13:07:01 +00:00
|
|
|
mock_mirobo_is_got_error.assert_has_calls(STATUS_CALLS, any_order=True)
|
|
|
|
mock_mirobo_is_got_error.reset_mock()
|
2017-08-05 19:45:59 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
assert "ERROR" not in caplog.text
|
2019-12-31 22:49:00 +00:00
|
|
|
await hass.services.async_call(
|
2019-11-09 13:07:01 +00:00
|
|
|
DOMAIN,
|
|
|
|
SERVICE_SET_FAN_SPEED,
|
|
|
|
{"entity_id": entity_id, "fan_speed": "invent"},
|
|
|
|
blocking=True,
|
2019-07-31 19:25:30 +00:00
|
|
|
)
|
|
|
|
assert "ERROR" in caplog.text
|
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
|
|
|
|
2019-12-31 22:49:00 +00:00
|
|
|
await hass.services.async_call(
|
2019-11-09 13:07:01 +00:00
|
|
|
DOMAIN,
|
|
|
|
SERVICE_SEND_COMMAND,
|
|
|
|
{"entity_id": entity_id, "command": "raw"},
|
|
|
|
blocking=True,
|
2019-07-31 19:25:30 +00:00
|
|
|
)
|
2019-11-09 13:07:01 +00:00
|
|
|
mock_mirobo_is_got_error.assert_has_calls(
|
|
|
|
[mock.call.raw_command("raw", None)], any_order=True
|
2019-07-31 19:25:30 +00:00
|
|
|
)
|
2019-11-09 13:07:01 +00:00
|
|
|
mock_mirobo_is_got_error.assert_has_calls(STATUS_CALLS, any_order=True)
|
|
|
|
mock_mirobo_is_got_error.reset_mock()
|
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
|
|
|
|
2019-12-31 22:49:00 +00:00
|
|
|
await hass.services.async_call(
|
2019-07-31 19:25:30 +00:00
|
|
|
DOMAIN,
|
|
|
|
SERVICE_SEND_COMMAND,
|
2019-11-09 13:07:01 +00:00
|
|
|
{"entity_id": entity_id, "command": "raw", "params": {"k1": 2}},
|
2019-07-31 19:25:30 +00:00
|
|
|
blocking=True,
|
|
|
|
)
|
2019-11-09 13:07:01 +00:00
|
|
|
mock_mirobo_is_got_error.assert_has_calls(
|
|
|
|
[mock.call.raw_command("raw", {"k1": 2})], any_order=True
|
2019-07-31 19:25:30 +00:00
|
|
|
)
|
2019-11-09 13:07:01 +00:00
|
|
|
mock_mirobo_is_got_error.assert_has_calls(STATUS_CALLS, any_order=True)
|
|
|
|
mock_mirobo_is_got_error.reset_mock()
|
2017-08-05 19:45:59 +00:00
|
|
|
|
|
|
|
|
2019-12-31 22:49:00 +00:00
|
|
|
async def test_xiaomi_specific_services(hass, caplog, mock_mirobo_is_on):
|
2017-08-05 19:45:59 +00:00
|
|
|
"""Test vacuum supported features."""
|
2019-07-31 19:25:30 +00:00
|
|
|
entity_name = "test_vacuum_cleaner_2"
|
2020-01-03 13:47:06 +00:00
|
|
|
entity_id = f"{DOMAIN}.{entity_name}"
|
2017-08-05 19:45:59 +00:00
|
|
|
|
2019-12-31 22:49:00 +00:00
|
|
|
await async_setup_component(
|
2019-07-31 19:25:30 +00:00
|
|
|
hass,
|
|
|
|
DOMAIN,
|
|
|
|
{
|
|
|
|
DOMAIN: {
|
|
|
|
CONF_PLATFORM: PLATFORM,
|
|
|
|
CONF_HOST: "192.168.1.100",
|
|
|
|
CONF_NAME: entity_name,
|
|
|
|
CONF_TOKEN: "12345678901234567890123456789012",
|
|
|
|
}
|
|
|
|
},
|
|
|
|
)
|
2019-12-31 22:49:00 +00:00
|
|
|
await hass.async_block_till_done()
|
2019-07-31 19:25:30 +00:00
|
|
|
|
|
|
|
assert "Initializing with host 192.168.1.100 (token 12345" in caplog.text
|
2017-08-05 19:45:59 +00:00
|
|
|
|
|
|
|
# Check state attributes
|
|
|
|
state = hass.states.get(entity_id)
|
2019-11-09 13:07:01 +00:00
|
|
|
assert state.state == STATE_CLEANING
|
|
|
|
assert state.attributes.get(ATTR_SUPPORTED_FEATURES) == 14204
|
2017-08-05 19:45:59 +00:00
|
|
|
assert state.attributes.get(ATTR_DO_NOT_DISTURB) == STATE_OFF
|
|
|
|
assert state.attributes.get(ATTR_ERROR) is None
|
2019-07-31 19:25:30 +00:00
|
|
|
assert state.attributes.get(ATTR_BATTERY_ICON) == "mdi:battery-30"
|
2017-09-25 20:27:27 +00:00
|
|
|
assert state.attributes.get(ATTR_CLEANING_TIME) == 175
|
|
|
|
assert state.attributes.get(ATTR_CLEANED_AREA) == 133
|
2017-08-05 19:45:59 +00:00
|
|
|
assert state.attributes.get(ATTR_FAN_SPEED) == 99
|
2019-07-31 19:25:30 +00:00
|
|
|
assert state.attributes.get(ATTR_FAN_SPEED_LIST) == [
|
2020-01-09 22:49:13 +00:00
|
|
|
"Silent",
|
|
|
|
"Standard",
|
|
|
|
"Medium",
|
2019-07-31 19:25:30 +00:00
|
|
|
"Turbo",
|
2019-11-27 12:46:13 +00:00
|
|
|
"Gentle",
|
2019-07-31 19:25:30 +00:00
|
|
|
]
|
2017-09-25 20:27:27 +00:00
|
|
|
assert state.attributes.get(ATTR_MAIN_BRUSH_LEFT) == 11
|
|
|
|
assert state.attributes.get(ATTR_SIDE_BRUSH_LEFT) == 11
|
|
|
|
assert state.attributes.get(ATTR_FILTER_LEFT) == 11
|
|
|
|
assert state.attributes.get(ATTR_CLEANING_COUNT) == 41
|
|
|
|
assert state.attributes.get(ATTR_CLEANED_TOTAL_AREA) == 323
|
|
|
|
assert state.attributes.get(ATTR_CLEANING_TOTAL_TIME) == 675
|
2017-08-05 19:45:59 +00:00
|
|
|
|
|
|
|
# Xiaomi vacuum specific services:
|
2019-12-31 22:49:00 +00:00
|
|
|
await hass.services.async_call(
|
2019-12-02 19:49:39 +00:00
|
|
|
XIAOMI_DOMAIN,
|
|
|
|
SERVICE_START_REMOTE_CONTROL,
|
|
|
|
{ATTR_ENTITY_ID: entity_id},
|
|
|
|
blocking=True,
|
2019-07-31 19:25:30 +00:00
|
|
|
)
|
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
|
|
|
|
2019-11-09 13:07:01 +00:00
|
|
|
mock_mirobo_is_on.assert_has_calls([mock.call.manual_start()], any_order=True)
|
|
|
|
mock_mirobo_is_on.assert_has_calls(STATUS_CALLS, any_order=True)
|
2017-12-01 11:28:59 +00:00
|
|
|
mock_mirobo_is_on.reset_mock()
|
|
|
|
|
|
|
|
control = {"duration": 1000, "rotation": -40, "velocity": -0.1}
|
2019-12-31 22:49:00 +00:00
|
|
|
await hass.services.async_call(
|
2019-12-02 19:49:39 +00:00
|
|
|
XIAOMI_DOMAIN, SERVICE_MOVE_REMOTE_CONTROL, control, blocking=True
|
2019-07-31 19:25:30 +00:00
|
|
|
)
|
2019-11-09 13:07:01 +00:00
|
|
|
mock_mirobo_is_on.manual_control.assert_has_calls(
|
|
|
|
[mock.call(**control)], any_order=True
|
2019-07-31 19:25:30 +00:00
|
|
|
)
|
2019-11-09 13:07:01 +00:00
|
|
|
mock_mirobo_is_on.assert_has_calls(STATUS_CALLS, any_order=True)
|
2017-12-01 11:28:59 +00:00
|
|
|
mock_mirobo_is_on.reset_mock()
|
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
|
|
|
|
2019-12-31 22:49:00 +00:00
|
|
|
await hass.services.async_call(
|
2019-12-02 19:49:39 +00:00
|
|
|
XIAOMI_DOMAIN, SERVICE_STOP_REMOTE_CONTROL, {}, blocking=True
|
2019-07-31 19:25:30 +00:00
|
|
|
)
|
2019-11-09 13:07:01 +00:00
|
|
|
mock_mirobo_is_on.assert_has_calls([mock.call.manual_stop()], any_order=True)
|
|
|
|
mock_mirobo_is_on.assert_has_calls(STATUS_CALLS, any_order=True)
|
2017-12-01 11:28:59 +00:00
|
|
|
mock_mirobo_is_on.reset_mock()
|
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
|
|
|
|
2017-12-01 11:28:59 +00:00
|
|
|
control_once = {"duration": 2000, "rotation": 120, "velocity": 0.1}
|
2019-12-31 22:49:00 +00:00
|
|
|
await hass.services.async_call(
|
2019-12-02 19:49:39 +00:00
|
|
|
XIAOMI_DOMAIN, SERVICE_MOVE_REMOTE_CONTROL_STEP, control_once, blocking=True
|
2019-07-31 19:25:30 +00:00
|
|
|
)
|
2019-11-09 13:07:01 +00:00
|
|
|
mock_mirobo_is_on.manual_control_once.assert_has_calls(
|
|
|
|
[mock.call(**control_once)], any_order=True
|
2019-07-31 19:25:30 +00:00
|
|
|
)
|
2019-11-09 13:07:01 +00:00
|
|
|
mock_mirobo_is_on.assert_has_calls(STATUS_CALLS, any_order=True)
|
2017-12-01 11:28:59 +00:00
|
|
|
mock_mirobo_is_on.reset_mock()
|
2019-02-20 14:44:04 +00:00
|
|
|
|
|
|
|
control = {"zone": [[123, 123, 123, 123]], "repeats": 2}
|
2019-12-31 22:49:00 +00:00
|
|
|
await hass.services.async_call(
|
2019-12-02 19:49:39 +00:00
|
|
|
XIAOMI_DOMAIN, SERVICE_CLEAN_ZONE, control, blocking=True
|
2019-07-31 19:25:30 +00:00
|
|
|
)
|
2019-11-09 13:07:01 +00:00
|
|
|
mock_mirobo_is_on.zoned_clean.assert_has_calls(
|
|
|
|
[mock.call([[123, 123, 123, 123, 2]])], any_order=True
|
2019-07-31 19:25:30 +00:00
|
|
|
)
|
2019-11-09 13:07:01 +00:00
|
|
|
mock_mirobo_is_on.assert_has_calls(STATUS_CALLS, any_order=True)
|
|
|
|
mock_mirobo_is_on.reset_mock()
|