Entity service (#15991)
* Add entity service helper * Use entity service helper * Context
This commit is contained in:
1 parent
e52ba87af1
commit
b682e48e12
14 files changed
+276
-387
No files matched your search
@@ -129,61 +129,25 @@ def async_setup(hass, config):
|
||||
if not entities:
|
||||
return False
|
||||
|
||||
@asyncio.coroutine
|
||||
def async_select_option_service(call):
|
||||
"""Handle a calls to the input select option service."""
|
||||
target_inputs = component.async_extract_from_service(call)
|
||||
component.async_register_entity_service(
|
||||
SERVICE_SELECT_OPTION, SERVICE_SELECT_OPTION_SCHEMA,
|
||||
'async_select_option'
|
||||
)
|
||||
|
||||
tasks = [input_select.async_select_option(call.data[ATTR_OPTION])
|
||||
for input_select in target_inputs]
|
||||
if tasks:
|
||||
yield from asyncio.wait(tasks, loop=hass.loop)
|
||||
component.async_register_entity_service(
|
||||
SERVICE_SELECT_NEXT, SERVICE_SELECT_NEXT_SCHEMA,
|
||||
lambda entity, call: entity.async_offset_index(1)
|
||||
)
|
||||
|
||||
hass.services.async_register(
|
||||
DOMAIN, SERVICE_SELECT_OPTION, async_select_option_service,
|
||||
schema=SERVICE_SELECT_OPTION_SCHEMA)
|
||||
component.async_register_entity_service(
|
||||
SERVICE_SELECT_PREVIOUS, SERVICE_SELECT_PREVIOUS_SCHEMA,
|
||||
lambda entity, call: entity.async_offset_index(-1)
|
||||
)
|
||||
|
||||
@asyncio.coroutine
|
||||
def async_select_next_service(call):
|
||||
"""Handle a calls to the input select next service."""
|
||||
target_inputs = component.async_extract_from_service(call)
|
||||
|
||||
tasks = [input_select.async_offset_index(1)
|
||||
for input_select in target_inputs]
|
||||
if tasks:
|
||||
yield from asyncio.wait(tasks, loop=hass.loop)
|
||||
|
||||
hass.services.async_register(
|
||||
DOMAIN, SERVICE_SELECT_NEXT, async_select_next_service,
|
||||
schema=SERVICE_SELECT_NEXT_SCHEMA)
|
||||
|
||||
@asyncio.coroutine
|
||||
def async_select_previous_service(call):
|
||||
"""Handle a calls to the input select previous service."""
|
||||
target_inputs = component.async_extract_from_service(call)
|
||||
|
||||
tasks = [input_select.async_offset_index(-1)
|
||||
for input_select in target_inputs]
|
||||
if tasks:
|
||||
yield from asyncio.wait(tasks, loop=hass.loop)
|
||||
|
||||
hass.services.async_register(
|
||||
DOMAIN, SERVICE_SELECT_PREVIOUS, async_select_previous_service,
|
||||
schema=SERVICE_SELECT_PREVIOUS_SCHEMA)
|
||||
|
||||
@asyncio.coroutine
|
||||
def async_set_options_service(call):
|
||||
"""Handle a calls to the set options service."""
|
||||
target_inputs = component.async_extract_from_service(call)
|
||||
|
||||
tasks = [input_select.async_set_options(call.data[ATTR_OPTIONS])
|
||||
for input_select in target_inputs]
|
||||
if tasks:
|
||||
yield from asyncio.wait(tasks, loop=hass.loop)
|
||||
|
||||
hass.services.async_register(
|
||||
DOMAIN, SERVICE_SET_OPTIONS, async_set_options_service,
|
||||
schema=SERVICE_SET_OPTIONS_SCHEMA)
|
||||
component.async_register_entity_service(
|
||||
SERVICE_SET_OPTIONS, SERVICE_SET_OPTIONS_SCHEMA,
|
||||
'async_set_options'
|
||||
)
|
||||
|
||||
yield from component.async_add_entities(entities)
|
||||
return True
|
||||
|
||||
Reference in new issue
Block a user