mirror of
https://github.com/home-assistant/core.git
synced 2025-07-25 14:17:45 +00:00
Vodafone Station typing (#129143)
This commit is contained in:
parent
61e2283146
commit
dd63ed7e69
@ -5,7 +5,7 @@ from __future__ import annotations
|
|||||||
from collections.abc import Callable
|
from collections.abc import Callable
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from typing import Any, Final
|
from typing import Final
|
||||||
|
|
||||||
from homeassistant.components.sensor import (
|
from homeassistant.components.sensor import (
|
||||||
SensorDeviceClass,
|
SensorDeviceClass,
|
||||||
@ -16,7 +16,6 @@ from homeassistant.config_entries import ConfigEntry
|
|||||||
from homeassistant.const import PERCENTAGE, EntityCategory, UnitOfDataRate
|
from homeassistant.const import PERCENTAGE, EntityCategory, UnitOfDataRate
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
from homeassistant.helpers.typing import StateType
|
|
||||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||||
|
|
||||||
from .const import _LOGGER, DOMAIN, LINE_TYPES
|
from .const import _LOGGER, DOMAIN, LINE_TYPES
|
||||||
@ -30,19 +29,22 @@ UPTIME_DEVIATION = 30
|
|||||||
class VodafoneStationEntityDescription(SensorEntityDescription):
|
class VodafoneStationEntityDescription(SensorEntityDescription):
|
||||||
"""Vodafone Station entity description."""
|
"""Vodafone Station entity description."""
|
||||||
|
|
||||||
value: Callable[[Any, Any, Any], Any] = (
|
value: Callable[
|
||||||
lambda coordinator, last_value, key: coordinator.data.sensors[key]
|
[VodafoneStationRouter, str | datetime | float | None, str],
|
||||||
)
|
str | datetime | float | None,
|
||||||
|
] = lambda coordinator, last_value, key: coordinator.data.sensors[key]
|
||||||
is_suitable: Callable[[dict], bool] = lambda val: True
|
is_suitable: Callable[[dict], bool] = lambda val: True
|
||||||
|
|
||||||
|
|
||||||
def _calculate_uptime(
|
def _calculate_uptime(
|
||||||
coordinator: VodafoneStationRouter,
|
coordinator: VodafoneStationRouter,
|
||||||
last_value: datetime | None,
|
last_value: str | datetime | float | None,
|
||||||
key: str,
|
key: str,
|
||||||
) -> datetime:
|
) -> datetime:
|
||||||
"""Calculate device uptime."""
|
"""Calculate device uptime."""
|
||||||
|
|
||||||
|
assert isinstance(last_value, datetime)
|
||||||
|
|
||||||
delta_uptime = coordinator.api.convert_uptime(coordinator.data.sensors[key])
|
delta_uptime = coordinator.api.convert_uptime(coordinator.data.sensors[key])
|
||||||
|
|
||||||
if (
|
if (
|
||||||
@ -56,7 +58,7 @@ def _calculate_uptime(
|
|||||||
|
|
||||||
def _line_connection(
|
def _line_connection(
|
||||||
coordinator: VodafoneStationRouter,
|
coordinator: VodafoneStationRouter,
|
||||||
last_value: str | None,
|
last_value: str | datetime | float | None,
|
||||||
key: str,
|
key: str,
|
||||||
) -> str | None:
|
) -> str | None:
|
||||||
"""Identify line type."""
|
"""Identify line type."""
|
||||||
@ -199,10 +201,10 @@ class VodafoneStationSensorEntity(
|
|||||||
self.entity_description = description
|
self.entity_description = description
|
||||||
self._attr_device_info = coordinator.device_info
|
self._attr_device_info = coordinator.device_info
|
||||||
self._attr_unique_id = f"{coordinator.serial_number}_{description.key}"
|
self._attr_unique_id = f"{coordinator.serial_number}_{description.key}"
|
||||||
self._old_state = None
|
self._old_state: str | datetime | float | None = None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def native_value(self) -> StateType:
|
def native_value(self) -> str | datetime | float | None:
|
||||||
"""Sensor value."""
|
"""Sensor value."""
|
||||||
self._old_state = self.entity_description.value(
|
self._old_state = self.entity_description.value(
|
||||||
self.coordinator, self._old_state, self.entity_description.key
|
self.coordinator, self._old_state, self.entity_description.key
|
||||||
|
Loading…
x
Reference in New Issue
Block a user