From fad3a4e168ad2e1f1d98fec3db0eaf321950e7bf Mon Sep 17 00:00:00 2001 From: Joost Lekkerkerker Date: Sun, 28 May 2023 02:58:04 +0200 Subject: [PATCH] Improve OpenSky typing (#93666) * Add types to OpenSky * Update .strict-typing * Add types to OpenSky --- .strict-typing | 1 + homeassistant/components/opensky/sensor.py | 16 +++++++++------- mypy.ini | 10 ++++++++++ 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/.strict-typing b/.strict-typing index 47f01c6cae8..801827df6dc 100644 --- a/.strict-typing +++ b/.strict-typing @@ -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.* diff --git a/homeassistant/components/opensky/sensor.py b/homeassistant/components/opensky/sensor.py index f422eb150a0..f3704f8d547 100644 --- a/homeassistant/components/opensky/sensor.py +++ b/homeassistant/components/opensky/sensor.py @@ -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" diff --git a/mypy.ini b/mypy.ini index 5e7d27586d1..8628353ef6a 100644 --- a/mypy.ini +++ b/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