Autogenerated type safety parameterisation of all methods

This commit is contained in:
Ian Renton
2026-09-20 20:02:19 +01:00
parent 6037e742cc
commit 324dd1414b
132 changed files with 1228 additions and 706 deletions
+11 -7
View File
@@ -1,7 +1,11 @@
from __future__ import annotations
import logging
from typing import Any
from xml.etree import ElementTree
import pytz
import requests
from dateutil import parser as dateutil_parser
from dateutil import tz as dateutil_tz
@@ -19,10 +23,10 @@ class HamQSL(HTTPSolarConditionsProvider):
"""Solar conditions provider using the HamQSL.com XML API (https://www.hamqsl.com/solarxml.php).
Provides solar flux index, geomagnetic indices, and HF/VHF propagation condition summaries."""
def __init__(self, provider_config):
def __init__(self, provider_config: dict[str, Any]) -> None:
super().__init__("HamQSL", provider_config, URL, POLL_INTERVAL)
def _http_response_to_solar_conditions(self, http_response):
def _http_response_to_solar_conditions(self, http_response: requests.Response) -> dict[str, Any] | None:
root = ElementTree.fromstring(http_response.text)
sd = root.find("solardata")
if sd is None:
@@ -31,27 +35,27 @@ class HamQSL(HTTPSolarConditionsProvider):
# Some error checking functions in case the data is janky.
def text(tag, default=None):
def text(tag: str, default: str | None = None) -> str | None:
if sd is None:
logger.warning("HamQSL solar conditions API returned unexpected XML structure")
return default
el = sd.find(tag)
return el.text.strip() if el is not None and el.text else default
def float_val(tag, default=None):
def float_val(tag: str, default: float | None = None) -> float | None:
try:
return float(text(tag))
except (ValueError, TypeError):
return default
def int_val(tag, default=None):
def int_val(tag: str, default: int | None = None) -> int | None:
try:
return int(text(tag))
except (ValueError, TypeError):
return default
# Process HF band conditions
hf_conditions = {}
hf_conditions: dict[str, str] = {}
calc = sd.find("calculatedconditions")
if calc is not None:
for band_el in calc.findall("band"):
@@ -62,7 +66,7 @@ class HamQSL(HTTPSolarConditionsProvider):
hf_conditions[f"{name}-{time}"] = condition
# Process VHF propagation conditions
vhf_map = {}
vhf_map: dict[tuple[str | None, str | None], str | None] = {}
vhf = sd.find("calculatedvhfconditions")
if vhf is not None:
for ph_el in vhf.findall("phenomenon"):