mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 21:06:19 +00:00
Add update events to registries (#23746)
* Add update events to registries * Add to websocket
This commit is contained in:
@@ -25,6 +25,7 @@ from .typing import HomeAssistantType
|
||||
|
||||
PATH_REGISTRY = 'entity_registry.yaml'
|
||||
DATA_REGISTRY = 'entity_registry'
|
||||
EVENT_ENTITY_REGISTRY_UPDATED = 'entity_registry_updated'
|
||||
SAVE_DELAY = 10
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
_UNDEF = object()
|
||||
@@ -150,12 +151,22 @@ class EntityRegistry:
|
||||
_LOGGER.info('Registered new %s.%s entity: %s',
|
||||
domain, platform, entity_id)
|
||||
self.async_schedule_save()
|
||||
|
||||
self.hass.bus.async_fire(EVENT_ENTITY_REGISTRY_UPDATED, {
|
||||
'action': 'create',
|
||||
'entity_id': entity_id
|
||||
})
|
||||
|
||||
return entity
|
||||
|
||||
@callback
|
||||
def async_remove(self, entity_id):
|
||||
"""Remove an entity from registry."""
|
||||
self.entities.pop(entity_id)
|
||||
self.hass.bus.async_fire(EVENT_ENTITY_REGISTRY_UPDATED, {
|
||||
'action': 'remove',
|
||||
'entity_id': entity_id
|
||||
})
|
||||
self.async_schedule_save()
|
||||
|
||||
@callback
|
||||
@@ -234,6 +245,11 @@ class EntityRegistry:
|
||||
|
||||
self.async_schedule_save()
|
||||
|
||||
self.hass.bus.async_fire(EVENT_ENTITY_REGISTRY_UPDATED, {
|
||||
'action': 'update',
|
||||
'entity_id': entity_id
|
||||
})
|
||||
|
||||
return new
|
||||
|
||||
async def async_load(self):
|
||||
|
||||
Reference in New Issue
Block a user