mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 16:57:53 +00:00
Improve OpenSky typing (#93666)
* Add types to OpenSky * Update .strict-typing * Add types to OpenSky
This commit is contained in:
parent
5f5951e71c
commit
fad3a4e168
@ -236,6 +236,7 @@ homeassistant.components.oncue.*
|
||||
homeassistant.components.onewire.*
|
||||
homeassistant.components.open_meteo.*
|
||||
homeassistant.components.openexchangerates.*
|
||||
homeassistant.components.opensky.*
|
||||
homeassistant.components.openuv.*
|
||||
homeassistant.components.otbr.*
|
||||
homeassistant.components.overkiz.*
|
||||
|
@ -3,7 +3,7 @@ from __future__ import annotations
|
||||
|
||||
from datetime import timedelta
|
||||
|
||||
from python_opensky import BoundingBox, OpenSky
|
||||
from python_opensky import BoundingBox, OpenSky, StateVector
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity
|
||||
@ -120,16 +120,18 @@ class OpenSkySensor(SensorEntity):
|
||||
self._bounding_box = bounding_box
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
def name(self) -> str:
|
||||
"""Return the name of the sensor."""
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def native_value(self):
|
||||
def native_value(self) -> int:
|
||||
"""Return the state of the sensor."""
|
||||
return self._state
|
||||
|
||||
def _handle_boundary(self, flights, event, metadata):
|
||||
def _handle_boundary(
|
||||
self, flights: set[str], event: str, metadata: dict[str, StateVector]
|
||||
) -> None:
|
||||
"""Handle flights crossing region boundary."""
|
||||
for flight in flights:
|
||||
if flight in metadata:
|
||||
@ -157,7 +159,7 @@ class OpenSkySensor(SensorEntity):
|
||||
async def async_update(self) -> None:
|
||||
"""Update device state."""
|
||||
currently_tracked = set()
|
||||
flight_metadata = {}
|
||||
flight_metadata: dict[str, StateVector] = {}
|
||||
response = await self._opensky.get_states(bounding_box=self._bounding_box)
|
||||
for flight in response.states:
|
||||
if not flight.callsign:
|
||||
@ -187,11 +189,11 @@ class OpenSkySensor(SensorEntity):
|
||||
self._previously_tracked = currently_tracked
|
||||
|
||||
@property
|
||||
def native_unit_of_measurement(self):
|
||||
def native_unit_of_measurement(self) -> str:
|
||||
"""Return the unit of measurement."""
|
||||
return "flights"
|
||||
|
||||
@property
|
||||
def icon(self):
|
||||
def icon(self) -> str:
|
||||
"""Return the icon."""
|
||||
return "mdi:airplane"
|
||||
|
10
mypy.ini
10
mypy.ini
@ -2122,6 +2122,16 @@ disallow_untyped_defs = true
|
||||
warn_return_any = true
|
||||
warn_unreachable = true
|
||||
|
||||
[mypy-homeassistant.components.opensky.*]
|
||||
check_untyped_defs = true
|
||||
disallow_incomplete_defs = true
|
||||
disallow_subclassing_any = true
|
||||
disallow_untyped_calls = true
|
||||
disallow_untyped_decorators = true
|
||||
disallow_untyped_defs = true
|
||||
warn_return_any = true
|
||||
warn_unreachable = true
|
||||
|
||||
[mypy-homeassistant.components.openuv.*]
|
||||
check_untyped_defs = true
|
||||
disallow_incomplete_defs = true
|
||||
|
Loading…
x
Reference in New Issue
Block a user