diff --git a/homeassistant/components/nest/device_info.py b/homeassistant/components/nest/device_info.py index 6278547f216..383c6d22258 100644 --- a/homeassistant/components/nest/device_info.py +++ b/homeassistant/components/nest/device_info.py @@ -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) diff --git a/homeassistant/components/nest/legacy/__init__.py b/homeassistant/components/nest/legacy/__init__.py index 04f7b1ac663..76ecf16b67b 100644 --- a/homeassistant/components/nest/legacy/__init__.py +++ b/homeassistant/components/nest/legacy/__init__.py @@ -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"]) diff --git a/homeassistant/components/synology_dsm/__init__.py b/homeassistant/components/synology_dsm/__init__.py index a9ca7b4c48d..0bc88b683b7 100644 --- a/homeassistant/components/synology_dsm/__init__.py +++ b/homeassistant/components/synology_dsm/__init__.py @@ -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), } diff --git a/homeassistant/helpers/entity.py b/homeassistant/helpers/entity.py index 6383de15b4a..131460baa93 100644 --- a/homeassistant/helpers/entity.py +++ b/homeassistant/helpers/entity.py @@ -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 diff --git a/tests/components/nest/device_info_test.py b/tests/components/nest/device_info_test.py index a0c6973c1d6..90b70f61d15 100644 --- a/tests/components/nest/device_info_test.py +++ b/tests/components/nest/device_info_test.py @@ -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, } diff --git a/tests/components/nest/sensor_sdm_test.py b/tests/components/nest/sensor_sdm_test.py index cc18e8cd3ae..dfdfd58d546 100644 --- a/tests/components/nest/sensor_sdm_test.py +++ b/tests/components/nest/sensor_sdm_test.py @@ -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")}