Update DeviceInfo static types (#54276)
* Update nest static types from aditional PR feedback Update nest and device helper static types based on post-merge discussion in PR #53475 * Remove unused type: ignore in synology * Remove check for None device type Remove check for None device type in order to reduce untested code as this is a case not allowed by the nest python library.pull/54304/head
parent
1373755444
commit
160bd74bae
|
@ -40,7 +40,7 @@ class NestDeviceInfo:
|
|||
)
|
||||
|
||||
@property
|
||||
def device_name(self) -> str:
|
||||
def device_name(self) -> str | None:
|
||||
"""Return the name of the physical device that includes the sensor."""
|
||||
if InfoTrait.NAME in self._device.traits:
|
||||
trait: InfoTrait = self._device.traits[InfoTrait.NAME]
|
||||
|
@ -56,11 +56,9 @@ class NestDeviceInfo:
|
|||
return self.device_model
|
||||
|
||||
@property
|
||||
def device_model(self) -> str:
|
||||
def device_model(self) -> str | None:
|
||||
"""Return device model information."""
|
||||
# The API intentionally returns minimal information about specific
|
||||
# devices, instead relying on traits, but we can infer a generic model
|
||||
# name based on the type
|
||||
if self._device.type in DEVICE_TYPE_MAP:
|
||||
return DEVICE_TYPE_MAP[self._device.type]
|
||||
return "Unknown"
|
||||
return DEVICE_TYPE_MAP.get(self._device.type)
|
||||
|
|
|
@ -9,6 +9,7 @@ from nest.nest import APIError, AuthorizationError
|
|||
import voluptuous as vol
|
||||
|
||||
from homeassistant import config_entries
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import (
|
||||
CONF_CLIENT_ID,
|
||||
CONF_CLIENT_SECRET,
|
||||
|
@ -17,7 +18,7 @@ from homeassistant.const import (
|
|||
EVENT_HOMEASSISTANT_START,
|
||||
EVENT_HOMEASSISTANT_STOP,
|
||||
)
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers import config_validation as cv
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect, dispatcher_send
|
||||
from homeassistant.helpers.entity import Entity
|
||||
|
@ -96,7 +97,7 @@ def nest_update_event_broker(hass, nest):
|
|||
_LOGGER.debug("Stop listening for nest.update_event")
|
||||
|
||||
|
||||
async def async_setup_legacy(hass, config) -> bool:
|
||||
async def async_setup_legacy(hass: HomeAssistant, config: dict) -> bool:
|
||||
"""Set up Nest components using the legacy nest API."""
|
||||
if DOMAIN not in config:
|
||||
return True
|
||||
|
@ -122,7 +123,7 @@ async def async_setup_legacy(hass, config) -> bool:
|
|||
return True
|
||||
|
||||
|
||||
async def async_setup_legacy_entry(hass, entry) -> bool:
|
||||
async def async_setup_legacy_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
"""Set up Nest from legacy config entry."""
|
||||
|
||||
nest = Nest(access_token=entry.data["tokens"]["access_token"])
|
||||
|
|
|
@ -686,10 +686,10 @@ class SynologyDSMDeviceEntity(SynologyDSMBaseEntity):
|
|||
"""Initialize the Synology DSM disk or volume entity."""
|
||||
super().__init__(api, entity_type, entity_info, coordinator)
|
||||
self._device_id = device_id
|
||||
self._device_name = None
|
||||
self._device_manufacturer = None
|
||||
self._device_model = None
|
||||
self._device_firmware = None
|
||||
self._device_name: str | None = None
|
||||
self._device_manufacturer: str | None = None
|
||||
self._device_model: str | None = None
|
||||
self._device_firmware: str | None = None
|
||||
self._device_type = None
|
||||
|
||||
if "volume" in entity_type:
|
||||
|
@ -730,8 +730,8 @@ class SynologyDSMDeviceEntity(SynologyDSMBaseEntity):
|
|||
(DOMAIN, f"{self._api.information.serial}_{self._device_id}")
|
||||
},
|
||||
"name": f"Synology NAS ({self._device_name} - {self._device_type})",
|
||||
"manufacturer": self._device_manufacturer, # type: ignore[typeddict-item]
|
||||
"model": self._device_model, # type: ignore[typeddict-item]
|
||||
"sw_version": self._device_firmware, # type: ignore[typeddict-item]
|
||||
"manufacturer": self._device_manufacturer,
|
||||
"model": self._device_model,
|
||||
"sw_version": self._device_firmware,
|
||||
"via_device": (DOMAIN, self._api.information.serial),
|
||||
}
|
||||
|
|
|
@ -165,13 +165,13 @@ def get_unit_of_measurement(hass: HomeAssistant, entity_id: str) -> str | None:
|
|||
class DeviceInfo(TypedDict, total=False):
|
||||
"""Entity device information for device registry."""
|
||||
|
||||
name: str
|
||||
name: str | None
|
||||
connections: set[tuple[str, str]]
|
||||
identifiers: set[tuple[str, str]]
|
||||
manufacturer: str
|
||||
model: str
|
||||
suggested_area: str
|
||||
sw_version: str
|
||||
manufacturer: str | None
|
||||
model: str | None
|
||||
suggested_area: str | None
|
||||
sw_version: str | None
|
||||
via_device: tuple[str, str]
|
||||
entry_type: str | None
|
||||
default_name: str
|
||||
|
|
|
@ -93,11 +93,11 @@ def test_device_invalid_type():
|
|||
|
||||
device_info = NestDeviceInfo(device)
|
||||
assert device_info.device_name == "My Doorbell"
|
||||
assert device_info.device_model == "Unknown"
|
||||
assert device_info.device_model is None
|
||||
assert device_info.device_brand == "Google Nest"
|
||||
assert device_info.device_info == {
|
||||
"identifiers": {("nest", "some-device-id")},
|
||||
"name": "My Doorbell",
|
||||
"manufacturer": "Google Nest",
|
||||
"model": "Unknown",
|
||||
"model": None,
|
||||
}
|
||||
|
|
|
@ -208,5 +208,5 @@ async def test_device_with_unknown_type(hass):
|
|||
device_registry = dr.async_get(hass)
|
||||
device = device_registry.async_get(entry.device_id)
|
||||
assert device.name == "My Sensor"
|
||||
assert device.model == "Unknown"
|
||||
assert device.model is None
|
||||
assert device.identifiers == {("nest", "some-device-id")}
|
||||
|
|
Loading…
Reference in New Issue