Improve sensor type hints in integrations (#90031)

* Improve sensor type hints in integrations

* Improve
This commit is contained in:
epenet 2023-03-21 11:39:42 +01:00 committed by GitHub
parent 4836404288
commit 0e1c76f81f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 12 additions and 11 deletions

View file

@ -1,7 +1,7 @@
"""Support for Awair sensors."""
from __future__ import annotations
from typing import cast
from typing import Any, cast
from python_awair.air_data import AirData
from python_awair.devices import AwairBaseDevice, AwairLocalDevice
@ -156,7 +156,7 @@ class AwairSensor(CoordinatorEntity[AwairDataUpdateCoordinator], SensorEntity):
return round(state, 2)
@property
def extra_state_attributes(self) -> dict:
def extra_state_attributes(self) -> dict[str, Any]:
"""Return the Awair Index alongside state attributes.
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
"""
sensor_type = self.entity_description.key
attrs: dict = {}
attrs: dict[str, Any] = {}
if not self._air_data:
return attrs
if sensor_type in self._air_data.indices:

View file

@ -123,6 +123,6 @@ class EmonitorPowerSensor(CoordinatorEntity, SensorEntity):
return self._paired_attr(self.entity_description.key)
@property
def extra_state_attributes(self) -> dict:
def extra_state_attributes(self) -> dict[str, int]:
"""Return the device specific state attributes."""
return {"channel": self.channel_number}

View file

@ -183,7 +183,7 @@ class EnturPublicTransportSensor(SensorEntity):
return self._state
@property
def extra_state_attributes(self) -> dict:
def extra_state_attributes(self) -> dict[str, str]:
"""Return the state attributes."""
self._attributes[ATTR_STOP_ID] = self._stop
return self._attributes

View file

@ -272,7 +272,7 @@ class FinTsHoldingsAccount(SensorEntity):
self._attr_native_value = sum(h.total_value for h in self._holdings)
@property
def extra_state_attributes(self) -> dict:
def extra_state_attributes(self) -> dict[str, Any]:
"""Additional attributes of the sensor.
Lists each holding of the account with the current value.

View file

@ -568,7 +568,7 @@ class GTFSDepartureSensor(SensorEntity):
return self._available
@property
def extra_state_attributes(self) -> dict:
def extra_state_attributes(self) -> dict[str, Any]:
"""Return the state attributes."""
return self._attributes

View file

@ -117,7 +117,7 @@ class StationPriceSensor(
return prices.get((self._station_id, self._fuel_type))
@property
def extra_state_attributes(self) -> dict:
def extra_state_attributes(self) -> dict[str, int | str]:
"""Return the state attributes of the device."""
return {
ATTR_STATION_ID: self._station_id,

View file

@ -7,7 +7,7 @@ import contextlib
from datetime import datetime, timedelta
import logging
import statistics
from typing import Any, Literal, cast
from typing import Any, cast
import voluptuous as vol
@ -410,7 +410,7 @@ class StatisticsSensor(SensorEntity):
return None
@property
def state_class(self) -> Literal[SensorStateClass.MEASUREMENT] | None:
def state_class(self) -> SensorStateClass | None:
"""Return the state class of this entity."""
if self._state_characteristic in STATS_NOT_A_NUMBER:
return None

View file

@ -3,6 +3,7 @@ from __future__ import annotations
from datetime import timedelta
import logging
from typing import Any
from WazeRouteCalculator import WazeRouteCalculator, WRCError
@ -112,7 +113,7 @@ class WazeTravelTime(SensorEntity):
return None
@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."""
if self._waze_data.duration is None:
return None