Improve upnp
typing (#84652)
This commit is contained in:
parent
6261994fcf
commit
bd9f03010f
3 changed files with 5 additions and 6 deletions
|
@ -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()
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Add table
Reference in a new issue