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
|
@property
|
||||||
def device_name(self) -> str:
|
def device_name(self) -> str | None:
|
||||||
"""Return the name of the physical device that includes the sensor."""
|
"""Return the name of the physical device that includes the sensor."""
|
||||||
if InfoTrait.NAME in self._device.traits:
|
if InfoTrait.NAME in self._device.traits:
|
||||||
trait: InfoTrait = self._device.traits[InfoTrait.NAME]
|
trait: InfoTrait = self._device.traits[InfoTrait.NAME]
|
||||||
|
@ -56,11 +56,9 @@ class NestDeviceInfo:
|
||||||
return self.device_model
|
return self.device_model
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def device_model(self) -> str:
|
def device_model(self) -> str | None:
|
||||||
"""Return device model information."""
|
"""Return device model information."""
|
||||||
# The API intentionally returns minimal information about specific
|
# The API intentionally returns minimal information about specific
|
||||||
# devices, instead relying on traits, but we can infer a generic model
|
# devices, instead relying on traits, but we can infer a generic model
|
||||||
# name based on the type
|
# name based on the type
|
||||||
if self._device.type in DEVICE_TYPE_MAP:
|
return DEVICE_TYPE_MAP.get(self._device.type)
|
||||||
return DEVICE_TYPE_MAP[self._device.type]
|
|
||||||
return "Unknown"
|
|
||||||
|
|
|
@ -9,6 +9,7 @@ from nest.nest import APIError, AuthorizationError
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant import config_entries
|
from homeassistant import config_entries
|
||||||
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
CONF_CLIENT_ID,
|
CONF_CLIENT_ID,
|
||||||
CONF_CLIENT_SECRET,
|
CONF_CLIENT_SECRET,
|
||||||
|
@ -17,7 +18,7 @@ from homeassistant.const import (
|
||||||
EVENT_HOMEASSISTANT_START,
|
EVENT_HOMEASSISTANT_START,
|
||||||
EVENT_HOMEASSISTANT_STOP,
|
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 import config_validation as cv
|
||||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect, dispatcher_send
|
from homeassistant.helpers.dispatcher import async_dispatcher_connect, dispatcher_send
|
||||||
from homeassistant.helpers.entity import Entity
|
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")
|
_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."""
|
"""Set up Nest components using the legacy nest API."""
|
||||||
if DOMAIN not in config:
|
if DOMAIN not in config:
|
||||||
return True
|
return True
|
||||||
|
@ -122,7 +123,7 @@ async def async_setup_legacy(hass, config) -> bool:
|
||||||
return True
|
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."""
|
"""Set up Nest from legacy config entry."""
|
||||||
|
|
||||||
nest = Nest(access_token=entry.data["tokens"]["access_token"])
|
nest = Nest(access_token=entry.data["tokens"]["access_token"])
|
||||||
|
|
|
@ -686,10 +686,10 @@ class SynologyDSMDeviceEntity(SynologyDSMBaseEntity):
|
||||||
"""Initialize the Synology DSM disk or volume entity."""
|
"""Initialize the Synology DSM disk or volume entity."""
|
||||||
super().__init__(api, entity_type, entity_info, coordinator)
|
super().__init__(api, entity_type, entity_info, coordinator)
|
||||||
self._device_id = device_id
|
self._device_id = device_id
|
||||||
self._device_name = None
|
self._device_name: str | None = None
|
||||||
self._device_manufacturer = None
|
self._device_manufacturer: str | None = None
|
||||||
self._device_model = None
|
self._device_model: str | None = None
|
||||||
self._device_firmware = None
|
self._device_firmware: str | None = None
|
||||||
self._device_type = None
|
self._device_type = None
|
||||||
|
|
||||||
if "volume" in entity_type:
|
if "volume" in entity_type:
|
||||||
|
@ -730,8 +730,8 @@ class SynologyDSMDeviceEntity(SynologyDSMBaseEntity):
|
||||||
(DOMAIN, f"{self._api.information.serial}_{self._device_id}")
|
(DOMAIN, f"{self._api.information.serial}_{self._device_id}")
|
||||||
},
|
},
|
||||||
"name": f"Synology NAS ({self._device_name} - {self._device_type})",
|
"name": f"Synology NAS ({self._device_name} - {self._device_type})",
|
||||||
"manufacturer": self._device_manufacturer, # type: ignore[typeddict-item]
|
"manufacturer": self._device_manufacturer,
|
||||||
"model": self._device_model, # type: ignore[typeddict-item]
|
"model": self._device_model,
|
||||||
"sw_version": self._device_firmware, # type: ignore[typeddict-item]
|
"sw_version": self._device_firmware,
|
||||||
"via_device": (DOMAIN, self._api.information.serial),
|
"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):
|
class DeviceInfo(TypedDict, total=False):
|
||||||
"""Entity device information for device registry."""
|
"""Entity device information for device registry."""
|
||||||
|
|
||||||
name: str
|
name: str | None
|
||||||
connections: set[tuple[str, str]]
|
connections: set[tuple[str, str]]
|
||||||
identifiers: set[tuple[str, str]]
|
identifiers: set[tuple[str, str]]
|
||||||
manufacturer: str
|
manufacturer: str | None
|
||||||
model: str
|
model: str | None
|
||||||
suggested_area: str
|
suggested_area: str | None
|
||||||
sw_version: str
|
sw_version: str | None
|
||||||
via_device: tuple[str, str]
|
via_device: tuple[str, str]
|
||||||
entry_type: str | None
|
entry_type: str | None
|
||||||
default_name: str
|
default_name: str
|
||||||
|
|
|
@ -93,11 +93,11 @@ def test_device_invalid_type():
|
||||||
|
|
||||||
device_info = NestDeviceInfo(device)
|
device_info = NestDeviceInfo(device)
|
||||||
assert device_info.device_name == "My Doorbell"
|
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_brand == "Google Nest"
|
||||||
assert device_info.device_info == {
|
assert device_info.device_info == {
|
||||||
"identifiers": {("nest", "some-device-id")},
|
"identifiers": {("nest", "some-device-id")},
|
||||||
"name": "My Doorbell",
|
"name": "My Doorbell",
|
||||||
"manufacturer": "Google Nest",
|
"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_registry = dr.async_get(hass)
|
||||||
device = device_registry.async_get(entry.device_id)
|
device = device_registry.async_get(entry.device_id)
|
||||||
assert device.name == "My Sensor"
|
assert device.name == "My Sensor"
|
||||||
assert device.model == "Unknown"
|
assert device.model is None
|
||||||
assert device.identifiers == {("nest", "some-device-id")}
|
assert device.identifiers == {("nest", "some-device-id")}
|
||||||
|
|
Loading…
Reference in New Issue