Improve deprecation warnings (#20391)

This commit is contained in:
Anders Melchiorsen 2019-01-24 22:37:30 +01:00 committed by Paulus Schoutsen
parent 3b1534c126
commit 70c5807976
2 changed files with 9 additions and 5 deletions

View file

@ -169,7 +169,8 @@ class EntityComponent:
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)
'instead: entity_id: %s', service.domain, service.service,
ENTITY_MATCH_ALL)
return [entity for entity in self.entities if entity.available]
@ -182,8 +183,9 @@ class EntityComponent:
"""Register an entity service."""
async def handle_service(call):
"""Handle the service."""
service_name = "{}.{}".format(self.domain, name)
await self.hass.helpers.service.entity_service_call(
self._platforms.values(), func, call
self._platforms.values(), func, call, service_name
)
self.hass.services.async_register(

View file

@ -187,7 +187,7 @@ async def async_get_all_descriptions(hass):
@bind_hass
async def entity_service_call(hass, platforms, func, call):
async def entity_service_call(hass, platforms, func, call, service_name=''):
"""Handle an entity service call.
Calls all platforms simultaneously.
@ -204,9 +204,11 @@ async def entity_service_call(hass, platforms, func, call):
if ATTR_ENTITY_ID in call.data:
target_all_entities = call.data[ATTR_ENTITY_ID] == ENTITY_MATCH_ALL
else:
# Remove the service_name parameter along with this warning
_LOGGER.warning(
'Not passing an entity ID to a service to target all entities is '
'deprecated. Use instead: entity_id: "%s"', ENTITY_MATCH_ALL)
'Not passing an entity ID to a service to target all '
'entities is deprecated. Update your call to %s to be '
'instead: entity_id: %s', service_name, ENTITY_MATCH_ALL)
target_all_entities = True
if not target_all_entities: