Cleanup nest async methods that do not need to actually await (#72170)
Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>
This commit is contained in:
parent
d459a5c66e
commit
775be354a6
9 changed files with 43 additions and 97 deletions
|
@ -25,6 +25,7 @@ import os
|
|||
|
||||
from google_nest_sdm.camera_traits import CameraClipPreviewTrait, CameraEventImageTrait
|
||||
from google_nest_sdm.device import Device
|
||||
from google_nest_sdm.device_manager import DeviceManager
|
||||
from google_nest_sdm.event import EventImageType, ImageEventBase
|
||||
from google_nest_sdm.event_media import (
|
||||
ClipPreviewSession,
|
||||
|
@ -50,13 +51,13 @@ from homeassistant.components.media_source.models import (
|
|||
MediaSourceItem,
|
||||
PlayMedia,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers import device_registry as dr
|
||||
from homeassistant.helpers.storage import Store
|
||||
from homeassistant.helpers.template import DATE_STR_FORMAT
|
||||
from homeassistant.util import dt as dt_util
|
||||
|
||||
from .const import DATA_SUBSCRIBER, DOMAIN
|
||||
from .const import DATA_DEVICE_MANAGER, DOMAIN
|
||||
from .device_info import NestDeviceInfo
|
||||
from .events import EVENT_NAME_MAP, MEDIA_SOURCE_EVENT_TITLE_MAP
|
||||
|
||||
|
@ -267,13 +268,13 @@ async def async_get_media_source(hass: HomeAssistant) -> MediaSource:
|
|||
return NestMediaSource(hass)
|
||||
|
||||
|
||||
async def get_media_source_devices(hass: HomeAssistant) -> Mapping[str, Device]:
|
||||
@callback
|
||||
def async_get_media_source_devices(hass: HomeAssistant) -> Mapping[str, Device]:
|
||||
"""Return a mapping of device id to eligible Nest event media devices."""
|
||||
if DATA_SUBSCRIBER not in hass.data[DOMAIN]:
|
||||
if DATA_DEVICE_MANAGER not in hass.data[DOMAIN]:
|
||||
# Integration unloaded, or is legacy nest integration
|
||||
return {}
|
||||
subscriber = hass.data[DOMAIN][DATA_SUBSCRIBER]
|
||||
device_manager = await subscriber.async_get_device_manager()
|
||||
device_manager: DeviceManager = hass.data[DOMAIN][DATA_DEVICE_MANAGER]
|
||||
device_registry = dr.async_get(hass)
|
||||
devices = {}
|
||||
for device in device_manager.devices.values():
|
||||
|
@ -339,7 +340,7 @@ class NestMediaSource(MediaSource):
|
|||
media_id: MediaId | None = parse_media_id(item.identifier)
|
||||
if not media_id:
|
||||
raise Unresolvable("No identifier specified for MediaSourceItem")
|
||||
devices = await self.devices()
|
||||
devices = async_get_media_source_devices(self.hass)
|
||||
if not (device := devices.get(media_id.device_id)):
|
||||
raise Unresolvable(
|
||||
"Unable to find device with identifier: %s" % item.identifier
|
||||
|
@ -376,7 +377,7 @@ class NestMediaSource(MediaSource):
|
|||
_LOGGER.debug(
|
||||
"Browsing media for identifier=%s, media_id=%s", item.identifier, media_id
|
||||
)
|
||||
devices = await self.devices()
|
||||
devices = async_get_media_source_devices(self.hass)
|
||||
if media_id is None:
|
||||
# Browse the root and return child devices
|
||||
browse_root = _browse_root()
|
||||
|
@ -443,10 +444,6 @@ class NestMediaSource(MediaSource):
|
|||
)
|
||||
return _browse_image_event(media_id, device, single_image)
|
||||
|
||||
async def devices(self) -> Mapping[str, Device]:
|
||||
"""Return all event media related devices."""
|
||||
return await get_media_source_devices(self.hass)
|
||||
|
||||
|
||||
async def _async_get_clip_preview_sessions(
|
||||
device: Device,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue