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
This commit is contained in:
Joakim Plate authored and Paulus Schoutsen committed 2019-02-05 17:25:27 -08:00
1 parent c76a61ad16
commit 3bb5caabe2
13 files changed
+846 -228

No files matched your search

@@ -23,6 +23,8 @@ from homeassistant.helpers.event import async_track_state_change
import homeassistant.helpers.config_validation as cv
from homeassistant.util.async_ import run_coroutine_threadsafe
from .reproduce_state import async_reproduce_states # noqa
DOMAIN = 'group'
ENTITY_ID_FORMAT = DOMAIN + '.{}'
@@ -0,0 +1,28 @@
"""Module that groups code required to handle state restore for component."""
from typing import Iterable, Optional
from homeassistant.core import Context, State
from homeassistant.helpers.typing import HomeAssistantType
from homeassistant.loader import bind_hass
@bind_hass
async def async_reproduce_states(hass: HomeAssistantType,
states: Iterable[State],
context: Optional[Context] = None) -> None:
"""Reproduce component states."""
from . import get_entity_ids
from homeassistant.helpers.state import async_reproduce_state
states_copy = []
for state in states:
members = get_entity_ids(hass, state.entity_id)
for member in members:
states_copy.append(
State(member,
state.state,
state.attributes,
last_changed=state.last_changed,
last_updated=state.last_updated,
context=state.context))
await async_reproduce_state(hass, states_copy, blocking=True,
context=context)