mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 12:59:34 +00:00
WIP: Migrate scene to async + homeassistant scene async (#4665)
* Migrate scene to async + homeassistant scene async * fix lint * Update state.py * Fix tests
This commit is contained in:
committed by
Paulus Schoutsen
parent
49cfe38cca
commit
2e6a48ff5f
@@ -1,4 +1,5 @@
|
||||
"""Helpers that help with state related things."""
|
||||
import asyncio
|
||||
import json
|
||||
import logging
|
||||
from collections import defaultdict
|
||||
@@ -33,6 +34,7 @@ from homeassistant.const import (
|
||||
STATE_OFF, STATE_ON, STATE_OPEN, STATE_PAUSED, STATE_PLAYING,
|
||||
STATE_UNKNOWN, STATE_UNLOCKED)
|
||||
from homeassistant.core import State
|
||||
from homeassistant.util.async import run_coroutine_threadsafe
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
@@ -111,6 +113,13 @@ def get_changed_since(states, utc_point_in_time):
|
||||
|
||||
|
||||
def reproduce_state(hass, states, blocking=False):
|
||||
"""Reproduce given state."""
|
||||
return run_coroutine_threadsafe(
|
||||
async_reproduce_state(hass, states, blocking), hass.loop).result()
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def async_reproduce_state(hass, states, blocking=False):
|
||||
"""Reproduce given state."""
|
||||
if isinstance(states, State):
|
||||
states = [states]
|
||||
@@ -129,7 +138,7 @@ def reproduce_state(hass, states, blocking=False):
|
||||
else:
|
||||
service_domain = state.domain
|
||||
|
||||
domain_services = hass.services.services[service_domain]
|
||||
domain_services = hass.services.async_services()[service_domain]
|
||||
|
||||
service = None
|
||||
for _service in domain_services.keys():
|
||||
@@ -157,7 +166,8 @@ def reproduce_state(hass, states, blocking=False):
|
||||
for (service_domain, service, service_data), entity_ids in to_call.items():
|
||||
data = json.loads(service_data)
|
||||
data[ATTR_ENTITY_ID] = entity_ids
|
||||
hass.services.call(service_domain, service, data, blocking)
|
||||
yield from hass.services.async_call(
|
||||
service_domain, service, data, blocking)
|
||||
|
||||
|
||||
def state_as_number(state):
|
||||
|
||||
Reference in New Issue
Block a user