Improve upnp typing (#84652)

This commit is contained in:
Marc Mueller 2022-12-29 10:59:06 +01:00 committed by GitHub
parent 6261994fcf
commit bd9f03010f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 5 additions and 6 deletions

View file

@ -1,6 +1,5 @@
"""UPnP/IGD coordinator."""
from collections.abc import Mapping
from datetime import timedelta
from typing import Any
@ -35,7 +34,7 @@ class UpnpDataUpdateCoordinator(DataUpdateCoordinator):
update_interval=update_interval,
)
async def _async_update_data(self) -> Mapping[str, Any]:
async def _async_update_data(self) -> dict[str, Any]:
"""Update data."""
try:
return await self.device.async_get_data()

View file

@ -1,7 +1,6 @@
"""Home Assistant representation of an UPnP/IGD."""
from __future__ import annotations
from collections.abc import Mapping
from functools import partial
from ipaddress import ip_address
from typing import Any
@ -135,7 +134,7 @@ class Device:
"""Get string representation."""
return f"IGD Device: {self.name}/{self.udn}::{self.device_type}"
async def async_get_data(self) -> Mapping[str, Any]:
async def async_get_data(self) -> dict[str, Any]:
"""Get all data from device."""
_LOGGER.debug("Getting data for device: %s", self)
igd_state = await self._igd_device.async_get_traffic_and_status_data()

View file

@ -178,7 +178,8 @@ class UpnpSensor(UpnpEntity, SensorEntity):
@property
def native_value(self) -> str | None:
"""Return the state of the device."""
value = self.coordinator.data[self.entity_description.value_key]
if value is None:
if (key := self.entity_description.value_key) is None:
return None
if (value := self.coordinator.data[key]) is None:
return None
return format(value, self.entity_description.format)