RFC: Deprecate auto target all for services and introduce entity_id: * (#19006)
* Deprecate auto target all * Match on word 'all'
This commit is contained in:
1 parent
56c7e78cf2
commit
8ea0a8d40b
24 files changed
+143
-41
No files matched your search
@@ -15,7 +15,8 @@ from homeassistant.const import (
|
||||
CONF_PLATFORM, CONF_SCAN_INTERVAL, TEMP_CELSIUS, TEMP_FAHRENHEIT,
|
||||
CONF_ALIAS, CONF_ENTITY_ID, CONF_VALUE_TEMPLATE, WEEKDAYS,
|
||||
CONF_CONDITION, CONF_BELOW, CONF_ABOVE, CONF_TIMEOUT, SUN_EVENT_SUNSET,
|
||||
SUN_EVENT_SUNRISE, CONF_UNIT_SYSTEM_IMPERIAL, CONF_UNIT_SYSTEM_METRIC)
|
||||
SUN_EVENT_SUNRISE, CONF_UNIT_SYSTEM_IMPERIAL, CONF_UNIT_SYSTEM_METRIC,
|
||||
ENTITY_MATCH_ALL)
|
||||
from homeassistant.core import valid_entity_id, split_entity_id
|
||||
from homeassistant.exceptions import TemplateError
|
||||
import homeassistant.util.dt as dt_util
|
||||
@@ -161,6 +162,12 @@ def entity_ids(value: Union[str, Sequence]) -> Sequence[str]:
|
||||
return [entity_id(ent_id) for ent_id in value]
|
||||
|
||||
|
||||
comp_entity_ids = vol.Any(
|
||||
vol.All(vol.Lower, ENTITY_MATCH_ALL),
|
||||
entity_ids
|
||||
)
|
||||
|
||||
|
||||
def entity_domain(domain: str):
|
||||
"""Validate that entity belong to domain."""
|
||||
def validate(value: Any) -> str:
|
||||
|
||||
@@ -7,7 +7,7 @@ import logging
|
||||
from homeassistant import config as conf_util
|
||||
from homeassistant.setup import async_prepare_setup_platform
|
||||
from homeassistant.const import (
|
||||
ATTR_ENTITY_ID, CONF_SCAN_INTERVAL, CONF_ENTITY_NAMESPACE)
|
||||
ATTR_ENTITY_ID, CONF_SCAN_INTERVAL, CONF_ENTITY_NAMESPACE, MATCH_ALL)
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.helpers import config_per_platform, discovery
|
||||
@@ -161,7 +161,15 @@ class EntityComponent:
|
||||
|
||||
This method must be run in the event loop.
|
||||
"""
|
||||
if ATTR_ENTITY_ID not in service.data:
|
||||
data_ent_id = service.data.get(ATTR_ENTITY_ID)
|
||||
|
||||
if data_ent_id in (None, MATCH_ALL):
|
||||
if data_ent_id is None:
|
||||
self.logger.warning(
|
||||
'Not passing an entity ID to a service to target all '
|
||||
'entities is deprecated. Update your call to %s.%s to be '
|
||||
'instead: entity_id: "*"', service.domain, service.service)
|
||||
|
||||
return [entity for entity in self.entities if entity.available]
|
||||
|
||||
entity_ids = set(extract_entity_ids(self.hass, service, expand_group))
|
||||
|
||||
@@ -6,7 +6,7 @@ from os import path
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.auth.permissions.const import POLICY_CONTROL
|
||||
from homeassistant.const import ATTR_ENTITY_ID
|
||||
from homeassistant.const import ATTR_ENTITY_ID, ENTITY_MATCH_ALL
|
||||
import homeassistant.core as ha
|
||||
from homeassistant.exceptions import TemplateError, Unauthorized, UnknownUser
|
||||
from homeassistant.helpers import template
|
||||
@@ -197,7 +197,12 @@ async def entity_service_call(hass, platforms, func, call):
|
||||
entity_perms = None
|
||||
|
||||
# Are we trying to target all entities
|
||||
target_all_entities = ATTR_ENTITY_ID not in call.data
|
||||
if ATTR_ENTITY_ID in call.data:
|
||||
target_all_entities = call.data[ATTR_ENTITY_ID] == ENTITY_MATCH_ALL
|
||||
else:
|
||||
_LOGGER.warning('Not passing an entity ID to a service to target all '
|
||||
'entities is deprecated. Use instead: entity_id: "*"')
|
||||
target_all_entities = True
|
||||
|
||||
if not target_all_entities:
|
||||
# A set of entities we're trying to target.
|
||||
|
||||
Reference in new issue
Block a user