Allow a list ofr update entity (#17860)
* Allow a list ofr update entity * Update services.yaml * Update services.yamlpull/17895/head
parent
edf2974979
commit
21686c9263
|
@ -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)
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue