Allow a list ofr update entity (#17860)

* Allow a list ofr update entity

* Update services.yaml

* Update services.yaml
pull/17895/head
Paulus Schoutsen 2018-10-27 21:34:33 +02:00 committed by Paulus Schoutsen
parent edf2974979
commit 21686c9263
3 changed files with 13 additions and 4 deletions

View File

@ -31,7 +31,7 @@ SERVICE_RELOAD_CORE_CONFIG = 'reload_core_config'
SERVICE_CHECK_CONFIG = 'check_config'
SERVICE_UPDATE_ENTITY = 'update_entity'
SCHEMA_UPDATE_ENTITY = vol.Schema({
ATTR_ENTITY_ID: cv.entity_id
ATTR_ENTITY_ID: cv.entity_ids
})
@ -142,8 +142,11 @@ async def async_setup(hass: ha.HomeAssistant, config: dict) -> Awaitable[bool]:
async def async_handle_update_service(call):
"""Service handler for updating an entity."""
await hass.helpers.entity_component.async_update_entity(
call.data[ATTR_ENTITY_ID])
tasks = [hass.helpers.entity_component.async_update_entity(entity)
for entity in call.data[ATTR_ENTITY_ID]]
if tasks:
await asyncio.wait(tasks)
hass.services.async_register(
ha.DOMAIN, SERVICE_HOMEASSISTANT_STOP, async_handle_core_service)

View File

@ -527,6 +527,12 @@ homeassistant:
entity_id:
description: The entity_id of the device to turn off.
example: light.living_room
update_entity:
description: Force one or more entities to update its data
fields:
entity_id:
description: One or multiple entity_ids to update. Can be a list.
example: light.living_room
xiaomi_aqara:
play_ringtone:

View File

@ -364,7 +364,7 @@ async def test_entity_update(hass):
with patch('homeassistant.helpers.entity_component.async_update_entity',
return_value=mock_coro()) as mock_update:
await hass.services.async_call('homeassistant', 'update_entity', {
'entity_id': 'light.kitchen'
'entity_id': ['light.kitchen']
}, blocking=True)
assert len(mock_update.mock_calls) == 1