1 """Library for extracting device specific information common to entities."""
3 from __future__
import annotations
5 from collections.abc
import Mapping
7 from google_nest_sdm.device
import Device
8 from google_nest_sdm.device_traits
import ConnectivityTrait, InfoTrait
14 from .const
import CONNECTIVITY_TRAIT_OFFLINE, DATA_DEVICE_MANAGER, DOMAIN
16 DEVICE_TYPE_MAP: dict[str, str] = {
17 "sdm.devices.types.CAMERA":
"Camera",
18 "sdm.devices.types.DISPLAY":
"Display",
19 "sdm.devices.types.DOORBELL":
"Doorbell",
20 "sdm.devices.types.THERMOSTAT":
"Thermostat",
25 """Provide device info from the SDM device, shared across platforms."""
27 device_brand =
"Google Nest"
30 """Initialize the DeviceInfo."""
35 """Return device availability."""
36 if ConnectivityTrait.NAME
in self.
_device_device.traits:
37 trait: ConnectivityTrait = self.
_device_device.traits[ConnectivityTrait.NAME]
38 if trait.status == CONNECTIVITY_TRAIT_OFFLINE:
44 """Return device specific attributes."""
47 identifiers={(DOMAIN, self.
_device_device.name)},
56 """Return the name of the physical device that includes the sensor."""
57 if InfoTrait.NAME
in self.
_device_device.traits:
58 trait: InfoTrait = self.
_device_device.traits[InfoTrait.NAME]
60 return str(trait.custom_name)
68 """Return device model information."""
69 return DEVICE_TYPE_MAP.get(self.
_device_device.type)
if self.
_device_device.type
else None
73 """Return device suggested area based on the Google Home room."""
74 if parent_relations := self.
_device_device.parent_relations:
75 items = sorted(parent_relations.items())
76 names = [name
for _, name
in items]
77 return " ".join(names)
83 """Return a mapping of all nest devices for all config entries."""
85 for entry_id
in hass.data[DOMAIN]:
86 if not (device_manager := hass.data[DOMAIN][entry_id].
get(DATA_DEVICE_MANAGER)):
89 {device.name: device
for device
in device_manager.devices.values()}
96 """Return a mapping of all nest devices by home assistant device id, for all config entries."""
97 device_registry = dr.async_get(hass)
100 if device_entry := device_registry.async_get_device(
101 identifiers={(DOMAIN, nest_device_id)}
103 devices[device_entry.id] = device
str|None device_name(self)
str|None device_model(self)
None __init__(self, Device device)
str|None suggested_area(self)
DeviceInfo device_info(self)
web.Response get(self, web.Request request, str config_key)
Mapping[str, Device] async_nest_devices(HomeAssistant hass)
Mapping[str, Device] async_nest_devices_by_device_id(HomeAssistant hass)