Improve OpenSky typing (#93666)

* Add types to OpenSky

* Update .strict-typing

* Add types to OpenSky
This commit is contained in:
Joost Lekkerkerker 2023-05-28 02:58:04 +02:00 committed by GitHub
parent 5f5951e71c
commit fad3a4e168
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 7 deletions

View File

@ -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.*

View File

@ -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"

View File

@ -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