hass-core/tests/components/group/test_reproduce_state.py
Joakim Plate 3bb5caabe2 Reproduce states by letting each component opt in on handling state recovery itself (#18700)
* Move group to it's own setup

* Let each component to handle restore of state

* Move constants for climate into const.py

For now import all into __init__.py to keep backword compat

* Move media plyaer constants to const.py file

For now import all constants into __init__.py to keep
backword compatibility

* Move media player to it's own file

* Move climate to it's own file

* Remove ecobee service from common components

BREAKING CHANGE

* Add tests for climate

* Add test for media_player

* Make sure we clone timestamps of state

* Add tests for groups

* Remove old tests for media player, it's handled by other tests

* Add tests for calls to component functions

* Add docstring for climate const

* Add docstring for media_player const

* Explicitly import constants in climate

* Explicitly import constants in media_player

* Add period to climate const

* Add period to media_player const

* Fix some lint errors in climate

* Fix some lint errors in media_player

* Fix lint warnings on climate tests

* Fix lint warnings on group tests

* Fix lint warnings on media_player tests

* Fix lint warnings on state tests

* Adjust indent for state tests
2019-02-05 17:25:27 -08:00

45 lines
1.5 KiB
Python

"""The tests for reproduction of state."""
from asyncio import Future
from unittest.mock import patch
from homeassistant.components.group import async_reproduce_states
from homeassistant.core import Context, State
async def test_reproduce_group(hass):
"""Test reproduce_state with group."""
context = Context()
def clone_state(state, entity_id):
"""Return a cloned state with different entity_id."""
return State(entity_id,
state.state,
state.attributes,
last_changed=state.last_changed,
last_updated=state.last_updated,
context=state.context)
with patch('homeassistant.helpers.state.async_reproduce_state') as fun:
fun.return_value = Future()
fun.return_value.set_result(None)
hass.states.async_set('group.test', 'off', {
'entity_id': ['light.test1', 'light.test2', 'switch.test1']})
hass.states.async_set('light.test1', 'off')
hass.states.async_set('light.test2', 'off')
hass.states.async_set('switch.test1', 'off')
state = State('group.test', 'on')
await async_reproduce_states(
hass,
[state],
context)
fun.assert_called_once_with(
hass,
[clone_state(state, 'light.test1'),
clone_state(state, 'light.test2'),
clone_state(state, 'switch.test1')],
blocking=True,
context=context)