Skip to content
Permalink
Browse files

Add tests for unused services

  • Loading branch information...
luukd committed Apr 15, 2019
1 parent 4bd6b18 commit 7dfa5df991621ad3dae011ce598a45399d20cd08
Showing with 64 additions and 1 deletion.
  1. +64 −1 tests/components/template/test_vacuum.py
@@ -51,7 +51,6 @@ def calls(hass):
_verify(hass, STATE_UNKNOWN, None)


# Configuration tests #
async def test_missing_start_config(hass, calls):
"""Test: missing 'start' will fail."""
with assert_setup_component(0, 'vacuum'):
@@ -216,6 +215,35 @@ def calls(hass):
_verify(hass, STATE_RETURNING, None)


async def test_unused_services(hass, calls):
"""Test calling unused services should not crash."""
await _register_basic_vacuum(hass)

# Pause vacuum
common.async_pause(hass, _TEST_VACUUM)
await hass.async_block_till_done()

# Stop vacuum
common.async_stop(hass, _TEST_VACUUM)
await hass.async_block_till_done()

# Return vacuum to base
common.async_return_to_base(hass, _TEST_VACUUM)
await hass.async_block_till_done()

# Spot cleaning
common.async_clean_spot(hass, _TEST_VACUUM)
await hass.async_block_till_done()

# Locate vacuum
common.async_locate(hass, _TEST_VACUUM)
await hass.async_block_till_done()

# Set fan's speed
common.async_set_fan_speed(hass, 'medium', _TEST_VACUUM)
await hass.async_block_till_done()


async def test_clean_spot_service(hass, calls):
"""Test clean spot service."""
await _register_components(hass)
@@ -286,6 +314,41 @@ def _verify(hass, expected_state, expected_battery_level):
assert attributes.get(ATTR_BATTERY_LEVEL) == expected_battery_level


async def _register_basic_vacuum(hass):
"""Register basic vacuum with only required options for testing."""
with assert_setup_component(1, 'input_select'):
assert await setup.async_setup_component(hass, 'input_select', {
'input_select': {
'state': {
'name': 'State',
'options': [STATE_CLEANING]
}
}
})

with assert_setup_component(1, 'vacuum'):
assert await setup.async_setup_component(hass, 'vacuum', {
'vacuum': {
'platform': 'template',
'vacuums': {
'test_vacuum': {
'start': {
'service': 'input_select.select_option',

'data': {
'entity_id': _STATE_INPUT_SELECT,
'option': STATE_CLEANING
}
}
}
}
}
})

await hass.async_start()
await hass.async_block_till_done()


async def _register_components(hass):
"""Register basic components for testing."""
with assert_setup_component(2, 'input_boolean'):

0 comments on commit 7dfa5df

Please sign in to comment.
You can’t perform that action at this time.