mirror of
https://github.com/home-assistant/core.git
synced 2026-08-09 06:42:33 +01:00
Adapt nest to new device registry API (#176948)
This commit is contained in:
@@ -145,8 +145,8 @@ class SignalUpdateCallback:
|
||||
return
|
||||
_LOGGER.debug("Event Update %s", events.keys())
|
||||
device_registry = dr.async_get(self._hass)
|
||||
device_entry = device_registry.async_get_device(
|
||||
identifiers={(DOMAIN, device_id)}
|
||||
device_entry = device_registry.async_get_device_by_identifier(
|
||||
(DOMAIN, device_id), self._config_entry.entry_id
|
||||
)
|
||||
if not device_entry:
|
||||
return
|
||||
@@ -273,7 +273,9 @@ async def async_setup_entry(hass: HomeAssistant, entry: NestConfigEntry) -> bool
|
||||
subscriber.cache_policy.event_cache_size = EVENT_MEDIA_CACHE_SIZE
|
||||
subscriber.cache_policy.fetch = True
|
||||
# Use disk backed event media store
|
||||
subscriber.cache_policy.store = await async_get_media_event_store(hass, subscriber)
|
||||
subscriber.cache_policy.store = await async_get_media_event_store(
|
||||
hass, entry, subscriber
|
||||
)
|
||||
subscriber.cache_policy.transcoder = await async_get_transcoder(hass)
|
||||
|
||||
# The device manager has a single change callback. When the change
|
||||
|
||||
@@ -76,24 +76,15 @@ class NestDeviceInfo:
|
||||
return None
|
||||
|
||||
|
||||
@callback
|
||||
def async_nest_devices(hass: HomeAssistant) -> Mapping[str, Device]:
|
||||
"""Return a mapping of all nest devices for all config entries."""
|
||||
return {
|
||||
device.name: device
|
||||
for config_entry in hass.config_entries.async_loaded_entries(DOMAIN)
|
||||
for device in config_entry.runtime_data.device_manager.devices.values()
|
||||
}
|
||||
|
||||
|
||||
@callback
|
||||
def async_nest_devices_by_device_id(hass: HomeAssistant) -> Mapping[str, Device]:
|
||||
"""Return a mapping of all nest devices by HA device id."""
|
||||
device_registry = dr.async_get(hass)
|
||||
devices = {}
|
||||
for nest_device_id, device in async_nest_devices(hass).items():
|
||||
if device_entry := device_registry.async_get_device(
|
||||
identifiers={(DOMAIN, nest_device_id)}
|
||||
):
|
||||
devices[device_entry.id] = device
|
||||
for config_entry in hass.config_entries.async_loaded_entries(DOMAIN):
|
||||
for device in config_entry.runtime_data.device_manager.devices.values():
|
||||
if device_entry := device_registry.async_get_device_by_identifier(
|
||||
(DOMAIN, device.name), config_entry.entry_id
|
||||
):
|
||||
devices[device_entry.id] = device
|
||||
return devices
|
||||
|
||||
@@ -55,6 +55,7 @@ from homeassistant.util import dt as dt_util
|
||||
from .const import DOMAIN
|
||||
from .device_info import NestDeviceInfo, async_nest_devices_by_device_id
|
||||
from .events import EVENT_NAME_MAP, MEDIA_SOURCE_EVENT_TITLE_MAP
|
||||
from .types import NestConfigEntry
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
@@ -80,7 +81,7 @@ ORPHANED_MEDIA_AGE_CUTOFF = datetime.timedelta(days=7)
|
||||
|
||||
|
||||
async def async_get_media_event_store(
|
||||
hass: HomeAssistant, subscriber: GoogleNestSubscriber
|
||||
hass: HomeAssistant, config_entry: NestConfigEntry, subscriber: GoogleNestSubscriber
|
||||
) -> EventMediaStore:
|
||||
"""Create the disk backed EventMediaStore."""
|
||||
media_path = pathlib.Path(hass.config.cache_path(DOMAIN, MEDIA_CACHE_PATH))
|
||||
@@ -89,7 +90,7 @@ async def async_get_media_event_store(
|
||||
_prepare_media_cache_dir, media_path, legacy_media_path
|
||||
)
|
||||
store = Store[dict[str, Any]](hass, STORAGE_VERSION, STORAGE_KEY, private=True)
|
||||
return NestEventMediaStore(hass, subscriber, store, str(media_path))
|
||||
return NestEventMediaStore(hass, config_entry, subscriber, store, str(media_path))
|
||||
|
||||
|
||||
def _prepare_media_cache_dir(
|
||||
@@ -138,12 +139,14 @@ class NestEventMediaStore(EventMediaStore):
|
||||
def __init__(
|
||||
self,
|
||||
hass: HomeAssistant,
|
||||
config_entry: NestConfigEntry,
|
||||
subscriber: GoogleNestSubscriber,
|
||||
store: Store[dict[str, Any]],
|
||||
media_path: str,
|
||||
) -> None:
|
||||
"""Initialize NestEventMediaStore."""
|
||||
self._hass = hass
|
||||
self._config_entry = config_entry
|
||||
self._subscriber = subscriber
|
||||
self._store = store
|
||||
self._media_path = media_path
|
||||
@@ -284,8 +287,8 @@ class NestEventMediaStore(EventMediaStore):
|
||||
device_manager = await self._subscriber.async_get_device_manager()
|
||||
devices = {}
|
||||
for device in device_manager.devices.values():
|
||||
if device_entry := device_registry.async_get_device(
|
||||
identifiers={(DOMAIN, device.name)}
|
||||
if device_entry := device_registry.async_get_device_by_identifier(
|
||||
(DOMAIN, device.name), self._config_entry.entry_id
|
||||
):
|
||||
devices[device.name] = device_entry.id
|
||||
return devices
|
||||
|
||||
Reference in New Issue
Block a user