Improve sensor type hints in integrations (#90031)
* Improve sensor type hints in integrations * Improve
This commit is contained in:
parent
4836404288
commit
0e1c76f81f
8 changed files with 12 additions and 11 deletions
|
@ -1,7 +1,7 @@
|
||||||
"""Support for Awair sensors."""
|
"""Support for Awair sensors."""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from typing import cast
|
from typing import Any, cast
|
||||||
|
|
||||||
from python_awair.air_data import AirData
|
from python_awair.air_data import AirData
|
||||||
from python_awair.devices import AwairBaseDevice, AwairLocalDevice
|
from python_awair.devices import AwairBaseDevice, AwairLocalDevice
|
||||||
|
@ -156,7 +156,7 @@ class AwairSensor(CoordinatorEntity[AwairDataUpdateCoordinator], SensorEntity):
|
||||||
return round(state, 2)
|
return round(state, 2)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def extra_state_attributes(self) -> dict:
|
def extra_state_attributes(self) -> dict[str, Any]:
|
||||||
"""Return the Awair Index alongside state attributes.
|
"""Return the Awair Index alongside state attributes.
|
||||||
|
|
||||||
The Awair Index is a subjective score ranging from 0-4 (inclusive) that
|
The Awair Index is a subjective score ranging from 0-4 (inclusive) that
|
||||||
|
@ -178,7 +178,7 @@ class AwairSensor(CoordinatorEntity[AwairDataUpdateCoordinator], SensorEntity):
|
||||||
https://docs.developer.getawair.com/?version=latest#awair-score-and-index
|
https://docs.developer.getawair.com/?version=latest#awair-score-and-index
|
||||||
"""
|
"""
|
||||||
sensor_type = self.entity_description.key
|
sensor_type = self.entity_description.key
|
||||||
attrs: dict = {}
|
attrs: dict[str, Any] = {}
|
||||||
if not self._air_data:
|
if not self._air_data:
|
||||||
return attrs
|
return attrs
|
||||||
if sensor_type in self._air_data.indices:
|
if sensor_type in self._air_data.indices:
|
||||||
|
|
|
@ -123,6 +123,6 @@ class EmonitorPowerSensor(CoordinatorEntity, SensorEntity):
|
||||||
return self._paired_attr(self.entity_description.key)
|
return self._paired_attr(self.entity_description.key)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def extra_state_attributes(self) -> dict:
|
def extra_state_attributes(self) -> dict[str, int]:
|
||||||
"""Return the device specific state attributes."""
|
"""Return the device specific state attributes."""
|
||||||
return {"channel": self.channel_number}
|
return {"channel": self.channel_number}
|
||||||
|
|
|
@ -183,7 +183,7 @@ class EnturPublicTransportSensor(SensorEntity):
|
||||||
return self._state
|
return self._state
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def extra_state_attributes(self) -> dict:
|
def extra_state_attributes(self) -> dict[str, str]:
|
||||||
"""Return the state attributes."""
|
"""Return the state attributes."""
|
||||||
self._attributes[ATTR_STOP_ID] = self._stop
|
self._attributes[ATTR_STOP_ID] = self._stop
|
||||||
return self._attributes
|
return self._attributes
|
||||||
|
|
|
@ -272,7 +272,7 @@ class FinTsHoldingsAccount(SensorEntity):
|
||||||
self._attr_native_value = sum(h.total_value for h in self._holdings)
|
self._attr_native_value = sum(h.total_value for h in self._holdings)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def extra_state_attributes(self) -> dict:
|
def extra_state_attributes(self) -> dict[str, Any]:
|
||||||
"""Additional attributes of the sensor.
|
"""Additional attributes of the sensor.
|
||||||
|
|
||||||
Lists each holding of the account with the current value.
|
Lists each holding of the account with the current value.
|
||||||
|
|
|
@ -568,7 +568,7 @@ class GTFSDepartureSensor(SensorEntity):
|
||||||
return self._available
|
return self._available
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def extra_state_attributes(self) -> dict:
|
def extra_state_attributes(self) -> dict[str, Any]:
|
||||||
"""Return the state attributes."""
|
"""Return the state attributes."""
|
||||||
return self._attributes
|
return self._attributes
|
||||||
|
|
||||||
|
|
|
@ -117,7 +117,7 @@ class StationPriceSensor(
|
||||||
return prices.get((self._station_id, self._fuel_type))
|
return prices.get((self._station_id, self._fuel_type))
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def extra_state_attributes(self) -> dict:
|
def extra_state_attributes(self) -> dict[str, int | str]:
|
||||||
"""Return the state attributes of the device."""
|
"""Return the state attributes of the device."""
|
||||||
return {
|
return {
|
||||||
ATTR_STATION_ID: self._station_id,
|
ATTR_STATION_ID: self._station_id,
|
||||||
|
|
|
@ -7,7 +7,7 @@ import contextlib
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
import logging
|
import logging
|
||||||
import statistics
|
import statistics
|
||||||
from typing import Any, Literal, cast
|
from typing import Any, cast
|
||||||
|
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
|
@ -410,7 +410,7 @@ class StatisticsSensor(SensorEntity):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def state_class(self) -> Literal[SensorStateClass.MEASUREMENT] | None:
|
def state_class(self) -> SensorStateClass | None:
|
||||||
"""Return the state class of this entity."""
|
"""Return the state class of this entity."""
|
||||||
if self._state_characteristic in STATS_NOT_A_NUMBER:
|
if self._state_characteristic in STATS_NOT_A_NUMBER:
|
||||||
return None
|
return None
|
||||||
|
|
|
@ -3,6 +3,7 @@ from __future__ import annotations
|
||||||
|
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
import logging
|
import logging
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
from WazeRouteCalculator import WazeRouteCalculator, WRCError
|
from WazeRouteCalculator import WazeRouteCalculator, WRCError
|
||||||
|
|
||||||
|
@ -112,7 +113,7 @@ class WazeTravelTime(SensorEntity):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def extra_state_attributes(self) -> dict | None:
|
def extra_state_attributes(self) -> dict[str, Any] | None:
|
||||||
"""Return the state attributes of the last update."""
|
"""Return the state attributes of the last update."""
|
||||||
if self._waze_data.duration is None:
|
if self._waze_data.duration is None:
|
||||||
return None
|
return None
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue