Do not select all entities when omitting entity ID in service call (#29178)
* Do not select all entities when omitting entity ID * Address comments Matthew * Require either area_id or entity_id * Fix tests * Fix test
This commit is contained in:
parent
9587afc5ce
commit
02d9ed5e36
47 changed files with 538 additions and 626 deletions
|
@ -15,7 +15,7 @@ from homeassistant.const import (
|
|||
from homeassistant.core import callback
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.helpers import config_per_platform, discovery
|
||||
from homeassistant.helpers.config_validation import ENTITY_SERVICE_SCHEMA
|
||||
from homeassistant.helpers.config_validation import make_entity_service_schema
|
||||
from homeassistant.helpers.service import async_extract_entity_ids
|
||||
from homeassistant.loader import bind_hass, async_get_integration
|
||||
from homeassistant.util import slugify
|
||||
|
@ -173,24 +173,16 @@ class EntityComponent:
|
|||
async def async_extract_from_service(self, service, expand_group=True):
|
||||
"""Extract all known and available entities from a service call.
|
||||
|
||||
Will return all entities if no entities specified in call.
|
||||
Will return an empty list if entities specified but unknown.
|
||||
|
||||
This method must be run in the event loop.
|
||||
"""
|
||||
data_ent_id = service.data.get(ATTR_ENTITY_ID)
|
||||
|
||||
if data_ent_id in (None, ENTITY_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: %s",
|
||||
service.domain,
|
||||
service.service,
|
||||
ENTITY_MATCH_ALL,
|
||||
)
|
||||
if data_ent_id is None:
|
||||
return []
|
||||
|
||||
if data_ent_id == ENTITY_MATCH_ALL:
|
||||
return [entity for entity in self.entities if entity.available]
|
||||
|
||||
entity_ids = await async_extract_entity_ids(self.hass, service, expand_group)
|
||||
|
@ -204,7 +196,7 @@ class EntityComponent:
|
|||
def async_register_entity_service(self, name, schema, func, required_features=None):
|
||||
"""Register an entity service."""
|
||||
if isinstance(schema, dict):
|
||||
schema = ENTITY_SERVICE_SCHEMA.extend(schema)
|
||||
schema = make_entity_service_schema(schema)
|
||||
|
||||
async def handle_service(call):
|
||||
"""Handle the service."""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue