Add transition support to scenes, cleanup blocking parameter (#34434)

This commit is contained in:
Franck Nijhof authored and GitHub committed 2020-04-20 18:07:50 -07:00
1 parent 19be31d13a
commit bc5a2da7b7
66 files changed
+547 -229

No files matched your search

+1 -1
View File
@@ -40,7 +40,7 @@ SUPPORT_COLOR = 16
SUPPORT_TRANSITION = 32
SUPPORT_WHITE_VALUE = 128
# Integer that represents transition time in seconds to make change.
# Float that represents transition time in seconds to make change.
ATTR_TRANSITION = "transition"
# Lists holding color values
@@ -2,7 +2,7 @@
import asyncio
import logging
from types import MappingProxyType
from typing import Iterable, Optional
from typing import Any, Dict, Iterable, Optional
from homeassistant.const import (
ATTR_ENTITY_ID,
@@ -71,7 +71,11 @@ DEPRECATION_WARNING = (
async def _async_reproduce_state(
hass: HomeAssistantType, state: State, context: Optional[Context] = None
hass: HomeAssistantType,
state: State,
*,
context: Optional[Context] = None,
reproduce_options: Optional[Dict[str, Any]] = None,
) -> None:
"""Reproduce a single state."""
cur_state = hass.states.get(state.entity_id)
@@ -98,7 +102,10 @@ async def _async_reproduce_state(
):
return
service_data = {ATTR_ENTITY_ID: state.entity_id}
service_data: Dict[str, Any] = {ATTR_ENTITY_ID: state.entity_id}
if reproduce_options is not None and ATTR_TRANSITION in reproduce_options:
service_data[ATTR_TRANSITION] = reproduce_options[ATTR_TRANSITION]
if state.state == STATE_ON:
service = SERVICE_TURN_ON
@@ -122,11 +129,20 @@ async def _async_reproduce_state(
async def async_reproduce_states(
hass: HomeAssistantType, states: Iterable[State], context: Optional[Context] = None
hass: HomeAssistantType,
states: Iterable[State],
*,
context: Optional[Context] = None,
reproduce_options: Optional[Dict[str, Any]] = None,
) -> None:
"""Reproduce Light states."""
await asyncio.gather(
*(_async_reproduce_state(hass, state, context) for state in states)
*(
_async_reproduce_state(
hass, state, context=context, reproduce_options=reproduce_options
)
for state in states
)
)