From c37e2680306478d5bd485734017b6ca649a266bc Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Mon, 1 Jan 2024 20:14:00 +0100 Subject: [PATCH] Enable strict typing for aprs (#106824) --- .strict-typing | 1 + homeassistant/components/aprs/device_tracker.py | 17 +++++++++-------- mypy.ini | 10 ++++++++++ 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/.strict-typing b/.strict-typing index 9eb9d318457..81400b5688f 100644 --- a/.strict-typing +++ b/.strict-typing @@ -69,6 +69,7 @@ homeassistant.components.anova.* homeassistant.components.anthemav.* homeassistant.components.apcupsd.* homeassistant.components.apprise.* +homeassistant.components.aprs.* homeassistant.components.aqualogic.* homeassistant.components.aranet.* homeassistant.components.aseko_pool_live.* diff --git a/homeassistant/components/aprs/device_tracker.py b/homeassistant/components/aprs/device_tracker.py index b1467a6d2e4..8b952f88c7c 100644 --- a/homeassistant/components/aprs/device_tracker.py +++ b/homeassistant/components/aprs/device_tracker.py @@ -3,6 +3,7 @@ from __future__ import annotations import logging import threading +from typing import Any import aprslib from aprslib import ConnectionError as AprsConnectionError, LoginError @@ -23,7 +24,7 @@ from homeassistant.const import ( CONF_USERNAME, EVENT_HOMEASSISTANT_STOP, ) -from homeassistant.core import HomeAssistant +from homeassistant.core import Event, HomeAssistant import homeassistant.helpers.config_validation as cv from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType from homeassistant.util import slugify @@ -66,7 +67,7 @@ def make_filter(callsigns: list) -> str: return " ".join(f"b/{sign.upper()}" for sign in callsigns) -def gps_accuracy(gps, posambiguity: int) -> int: +def gps_accuracy(gps: tuple[float, float], posambiguity: int) -> int: """Calculate the GPS accuracy based on APRS posambiguity.""" pos_a_map = {0: 0, 1: 1 / 600, 2: 1 / 60, 3: 1 / 6, 4: 1} @@ -74,7 +75,7 @@ def gps_accuracy(gps, posambiguity: int) -> int: degrees = pos_a_map[posambiguity] gps2 = (gps[0], gps[1] + degrees) - dist_m = geopy.distance.distance(gps, gps2).m + dist_m: float = geopy.distance.distance(gps, gps2).m accuracy = round(dist_m) else: @@ -100,7 +101,7 @@ def setup_scanner( timeout = config[CONF_TIMEOUT] aprs_listener = AprsListenerThread(callsign, password, host, server_filter, see) - def aprs_disconnect(event): + def aprs_disconnect(event: Event) -> None: """Stop the APRS connection.""" aprs_listener.stop() @@ -145,13 +146,13 @@ class AprsListenerThread(threading.Thread): self.callsign, passwd=password, host=self.host, port=FILTER_PORT ) - def start_complete(self, success: bool, message: str): + def start_complete(self, success: bool, message: str) -> None: """Complete startup process.""" self.start_message = message self.start_success = success self.start_event.set() - def run(self): + def run(self) -> None: """Connect to APRS and listen for data.""" self.ais.set_filter(self.server_filter) @@ -171,11 +172,11 @@ class AprsListenerThread(threading.Thread): "Closing connection to %s with callsign %s", self.host, self.callsign ) - def stop(self): + def stop(self) -> None: """Close the connection to the APRS network.""" self.ais.close() - def rx_msg(self, msg: dict): + def rx_msg(self, msg: dict[str, Any]) -> None: """Receive message and process if position.""" _LOGGER.debug("APRS message received: %s", str(msg)) if msg[ATTR_FORMAT] in MSG_FORMATS: diff --git a/mypy.ini b/mypy.ini index 06d9f21df42..4b8fa484b06 100644 --- a/mypy.ini +++ b/mypy.ini @@ -450,6 +450,16 @@ disallow_untyped_defs = true warn_return_any = true warn_unreachable = true +[mypy-homeassistant.components.aprs.*] +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.aqualogic.*] check_untyped_defs = true disallow_incomplete_defs = true