Skip to content

Commit 7739cc0

Browse files
authored
Adapt nest to new device registry API (home-assistant#176948)
1 parent 3f30346 commit 7739cc0

3 files changed

Lines changed: 18 additions & 22 deletions

File tree

homeassistant/components/nest/__init__.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,8 @@ async def async_handle_event(self, event_message: EventMessage) -> None:
145145
return
146146
_LOGGER.debug("Event Update %s", events.keys())
147147
device_registry = dr.async_get(self._hass)
148-
device_entry = device_registry.async_get_device(
149-
identifiers={(DOMAIN, device_id)}
148+
device_entry = device_registry.async_get_device_by_identifier(
149+
(DOMAIN, device_id), self._config_entry.entry_id
150150
)
151151
if not device_entry:
152152
return
@@ -273,7 +273,9 @@ async def async_setup_entry(hass: HomeAssistant, entry: NestConfigEntry) -> bool
273273
subscriber.cache_policy.event_cache_size = EVENT_MEDIA_CACHE_SIZE
274274
subscriber.cache_policy.fetch = True
275275
# Use disk backed event media store
276-
subscriber.cache_policy.store = await async_get_media_event_store(hass, subscriber)
276+
subscriber.cache_policy.store = await async_get_media_event_store(
277+
hass, entry, subscriber
278+
)
277279
subscriber.cache_policy.transcoder = await async_get_transcoder(hass)
278280

279281
# The device manager has a single change callback. When the change

homeassistant/components/nest/device_info.py

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -76,24 +76,15 @@ def suggested_area(self) -> str | None:
7676
return None
7777

7878

79-
@callback
80-
def async_nest_devices(hass: HomeAssistant) -> Mapping[str, Device]:
81-
"""Return a mapping of all nest devices for all config entries."""
82-
return {
83-
device.name: device
84-
for config_entry in hass.config_entries.async_loaded_entries(DOMAIN)
85-
for device in config_entry.runtime_data.device_manager.devices.values()
86-
}
87-
88-
8979
@callback
9080
def async_nest_devices_by_device_id(hass: HomeAssistant) -> Mapping[str, Device]:
9181
"""Return a mapping of all nest devices by HA device id."""
9282
device_registry = dr.async_get(hass)
9383
devices = {}
94-
for nest_device_id, device in async_nest_devices(hass).items():
95-
if device_entry := device_registry.async_get_device(
96-
identifiers={(DOMAIN, nest_device_id)}
97-
):
98-
devices[device_entry.id] = device
84+
for config_entry in hass.config_entries.async_loaded_entries(DOMAIN):
85+
for device in config_entry.runtime_data.device_manager.devices.values():
86+
if device_entry := device_registry.async_get_device_by_identifier(
87+
(DOMAIN, device.name), config_entry.entry_id
88+
):
89+
devices[device_entry.id] = device
9990
return devices

homeassistant/components/nest/media_source.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
from .const import DOMAIN
5656
from .device_info import NestDeviceInfo, async_nest_devices_by_device_id
5757
from .events import EVENT_NAME_MAP, MEDIA_SOURCE_EVENT_TITLE_MAP
58+
from .types import NestConfigEntry
5859

5960
_LOGGER = logging.getLogger(__name__)
6061

@@ -80,7 +81,7 @@
8081

8182

8283
async def async_get_media_event_store(
83-
hass: HomeAssistant, subscriber: GoogleNestSubscriber
84+
hass: HomeAssistant, config_entry: NestConfigEntry, subscriber: GoogleNestSubscriber
8485
) -> EventMediaStore:
8586
"""Create the disk backed EventMediaStore."""
8687
media_path = pathlib.Path(hass.config.cache_path(DOMAIN, MEDIA_CACHE_PATH))
@@ -89,7 +90,7 @@ async def async_get_media_event_store(
8990
_prepare_media_cache_dir, media_path, legacy_media_path
9091
)
9192
store = Store[dict[str, Any]](hass, STORAGE_VERSION, STORAGE_KEY, private=True)
92-
return NestEventMediaStore(hass, subscriber, store, str(media_path))
93+
return NestEventMediaStore(hass, config_entry, subscriber, store, str(media_path))
9394

9495

9596
def _prepare_media_cache_dir(
@@ -138,12 +139,14 @@ class NestEventMediaStore(EventMediaStore):
138139
def __init__(
139140
self,
140141
hass: HomeAssistant,
142+
config_entry: NestConfigEntry,
141143
subscriber: GoogleNestSubscriber,
142144
store: Store[dict[str, Any]],
143145
media_path: str,
144146
) -> None:
145147
"""Initialize NestEventMediaStore."""
146148
self._hass = hass
149+
self._config_entry = config_entry
147150
self._subscriber = subscriber
148151
self._store = store
149152
self._media_path = media_path
@@ -284,8 +287,8 @@ async def _get_devices(self) -> Mapping[str, str]:
284287
device_manager = await self._subscriber.async_get_device_manager()
285288
devices = {}
286289
for device in device_manager.devices.values():
287-
if device_entry := device_registry.async_get_device(
288-
identifiers={(DOMAIN, device.name)}
290+
if device_entry := device_registry.async_get_device_by_identifier(
291+
(DOMAIN, device.name), self._config_entry.entry_id
289292
):
290293
devices[device.name] = device_entry.id
291294
return devices

0 commit comments

Comments
 (0)