Allow a list ofr update entity (#17860)
* Allow a list ofr update entity * Update services.yaml * Update services.yaml
This commit is contained in:
parent
a22aad50e1
commit
649bc55a3b
3 changed files with 13 additions and 4 deletions
|
@ -31,7 +31,7 @@ SERVICE_RELOAD_CORE_CONFIG = 'reload_core_config'
|
||||||
SERVICE_CHECK_CONFIG = 'check_config'
|
SERVICE_CHECK_CONFIG = 'check_config'
|
||||||
SERVICE_UPDATE_ENTITY = 'update_entity'
|
SERVICE_UPDATE_ENTITY = 'update_entity'
|
||||||
SCHEMA_UPDATE_ENTITY = vol.Schema({
|
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):
|
async def async_handle_update_service(call):
|
||||||
"""Service handler for updating an entity."""
|
"""Service handler for updating an entity."""
|
||||||
await hass.helpers.entity_component.async_update_entity(
|
tasks = [hass.helpers.entity_component.async_update_entity(entity)
|
||||||
call.data[ATTR_ENTITY_ID])
|
for entity in call.data[ATTR_ENTITY_ID]]
|
||||||
|
|
||||||
|
if tasks:
|
||||||
|
await asyncio.wait(tasks)
|
||||||
|
|
||||||
hass.services.async_register(
|
hass.services.async_register(
|
||||||
ha.DOMAIN, SERVICE_HOMEASSISTANT_STOP, async_handle_core_service)
|
ha.DOMAIN, SERVICE_HOMEASSISTANT_STOP, async_handle_core_service)
|
||||||
|
|
|
@ -527,6 +527,12 @@ homeassistant:
|
||||||
entity_id:
|
entity_id:
|
||||||
description: The entity_id of the device to turn off.
|
description: The entity_id of the device to turn off.
|
||||||
example: light.living_room
|
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:
|
xiaomi_aqara:
|
||||||
play_ringtone:
|
play_ringtone:
|
||||||
|
|
|
@ -364,7 +364,7 @@ async def test_entity_update(hass):
|
||||||
with patch('homeassistant.helpers.entity_component.async_update_entity',
|
with patch('homeassistant.helpers.entity_component.async_update_entity',
|
||||||
return_value=mock_coro()) as mock_update:
|
return_value=mock_coro()) as mock_update:
|
||||||
await hass.services.async_call('homeassistant', 'update_entity', {
|
await hass.services.async_call('homeassistant', 'update_entity', {
|
||||||
'entity_id': 'light.kitchen'
|
'entity_id': ['light.kitchen']
|
||||||
}, blocking=True)
|
}, blocking=True)
|
||||||
|
|
||||||
assert len(mock_update.mock_calls) == 1
|
assert len(mock_update.mock_calls) == 1
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue