mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 21:06:19 +00:00
Merge remote-tracking branch 'balloob/dev' into automation-decorator
# Conflicts: # homeassistant/helpers/service.py # tests/helpers/test_service.py
This commit is contained in:
@@ -2,8 +2,9 @@
|
||||
import functools
|
||||
import logging
|
||||
|
||||
from homeassistant.util import split_entity_id
|
||||
from homeassistant.const import ATTR_ENTITY_ID
|
||||
from homeassistant.helpers.entity import split_entity_id
|
||||
from homeassistant.loader import get_component
|
||||
|
||||
HASS = None
|
||||
|
||||
@@ -61,3 +62,22 @@ def call_from_config(hass, config, blocking=False):
|
||||
service_data[ATTR_ENTITY_ID] = entity_id
|
||||
|
||||
hass.services.call(domain, service_name, service_data, blocking)
|
||||
|
||||
|
||||
def extract_entity_ids(hass, service):
|
||||
"""
|
||||
Helper method to extract a list of entity ids from a service call.
|
||||
Will convert group entity ids to the entity ids it represents.
|
||||
"""
|
||||
if not (service.data and ATTR_ENTITY_ID in service.data):
|
||||
return []
|
||||
|
||||
group = get_component('group')
|
||||
|
||||
# Entity ID attr can be a list or a string
|
||||
service_ent_id = service.data[ATTR_ENTITY_ID]
|
||||
|
||||
if isinstance(service_ent_id, str):
|
||||
return group.expand_entity_ids(hass, [service_ent_id])
|
||||
|
||||
return [ent_id for ent_id in group.expand_entity_ids(hass, service_ent_id)]
|
||||
|
||||
Reference in New Issue
Block a user