mirror of https://github.com/home-assistant/core
Make some Area and EntityRegistry member functions callbacks (#46433)
This commit is contained in:
parent
8418489345
commit
f1714dd541
|
@ -90,7 +90,7 @@ async def websocket_delete_area(hass, connection, msg):
|
|||
registry = await async_get_registry(hass)
|
||||
|
||||
try:
|
||||
await registry.async_delete(msg["area_id"])
|
||||
registry.async_delete(msg["area_id"])
|
||||
except KeyError:
|
||||
connection.send_message(
|
||||
websocket_api.error_message(
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
"""Provide a way to connect devices to one physical location."""
|
||||
from asyncio import gather
|
||||
from collections import OrderedDict
|
||||
from typing import Container, Dict, Iterable, List, MutableMapping, Optional, cast
|
||||
|
||||
import attr
|
||||
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.helpers import device_registry as dr, entity_registry as er
|
||||
from homeassistant.loader import bind_hass
|
||||
from homeassistant.util import slugify
|
||||
|
||||
|
@ -72,12 +72,11 @@ class AreaRegistry:
|
|||
)
|
||||
return area
|
||||
|
||||
async def async_delete(self, area_id: str) -> None:
|
||||
@callback
|
||||
def async_delete(self, area_id: str) -> None:
|
||||
"""Delete area."""
|
||||
device_registry, entity_registry = await gather(
|
||||
self.hass.helpers.device_registry.async_get_registry(),
|
||||
self.hass.helpers.entity_registry.async_get_registry(),
|
||||
)
|
||||
device_registry = dr.async_get(self.hass)
|
||||
entity_registry = er.async_get(self.hass)
|
||||
device_registry.async_clear_area_id(area_id)
|
||||
entity_registry.async_clear_area_id(area_id)
|
||||
|
||||
|
|
|
@ -35,6 +35,7 @@ from homeassistant.const import (
|
|||
STATE_UNAVAILABLE,
|
||||
)
|
||||
from homeassistant.core import Event, callback, split_entity_id, valid_entity_id
|
||||
from homeassistant.helpers import device_registry as dr
|
||||
from homeassistant.helpers.device_registry import EVENT_DEVICE_REGISTRY_UPDATED
|
||||
from homeassistant.loader import bind_hass
|
||||
from homeassistant.util import slugify
|
||||
|
@ -313,7 +314,8 @@ class EntityRegistry:
|
|||
)
|
||||
self.async_schedule_save()
|
||||
|
||||
async def async_device_modified(self, event: Event) -> None:
|
||||
@callback
|
||||
def async_device_modified(self, event: Event) -> None:
|
||||
"""Handle the removal or update of a device.
|
||||
|
||||
Remove entities from the registry that are associated to a device when
|
||||
|
@ -333,7 +335,7 @@ class EntityRegistry:
|
|||
if event.data["action"] != "update":
|
||||
return
|
||||
|
||||
device_registry = await self.hass.helpers.device_registry.async_get_registry()
|
||||
device_registry = dr.async_get(self.hass)
|
||||
device = device_registry.async_get(event.data["device_id"])
|
||||
|
||||
# The device may be deleted already if the event handling is late
|
||||
|
|
|
@ -81,7 +81,7 @@ async def test_delete_area(hass, registry, update_events):
|
|||
"""Make sure that we can delete an area."""
|
||||
area = registry.async_create("mock")
|
||||
|
||||
await registry.async_delete(area.id)
|
||||
registry.async_delete(area.id)
|
||||
|
||||
assert not registry.areas
|
||||
|
||||
|
|
Loading…
Reference in New Issue