from __future__ import annotations from datetime import datetime from typing import Any import pytz from core.data_store import DATA_STORE from data.solar_conditions import SolarConditions class SolarConditionsProvider: """Generic solar conditions provider class. Subclasses of this query individual APIs for space weather and propagation data.""" def __init__(self, name: str, provider_config: dict[str, Any]) -> None: """Constructor""" self.name: str = name self.enabled: bool = provider_config.get("enabled", True) self.last_update_time: datetime = datetime.min.replace(tzinfo=pytz.UTC) self.status: str = "Not Started" if self.enabled else "Disabled" self._solar_conditions: SolarConditions = DATA_STORE.solar_conditions.get() def start(self) -> None: """Start the provider. This should return immediately after spawning threads to access the remote resources""" raise NotImplementedError("Subclasses must implement this method") def stop(self) -> None: """Stop any threads and prepare for application shutdown""" raise NotImplementedError("Subclasses must implement this method") def update_data(self, new_data: dict[str, Any] | None) -> None: """Update the solar conditions object with new data""" if new_data: for key, value in new_data.items(): if hasattr(self._solar_conditions, key): setattr(self._solar_conditions, key, value) self._solar_conditions.infer_descriptions() DATA_STORE.solar_conditions.store()