mirror of
https://github.com/jdejaegh/irm-kmi-api.git
synced 2025-06-27 04:05:56 +02:00
Reformat code + add type hints
This commit is contained in:
parent
af40cba92d
commit
9641b4219b
3 changed files with 17 additions and 7 deletions
|
@ -37,10 +37,13 @@ class Forecast(TypedDict, total=False):
|
|||
|
||||
|
||||
class IrmKmiConditionEvol(Enum):
|
||||
"""Possible state for evolution between weather conditions"""
|
||||
|
||||
ONE_WAY = 'one_way'
|
||||
TWO_WAYS = 'two_ways'
|
||||
STABLE = 'stable'
|
||||
|
||||
|
||||
|
||||
class IrmKmiRadarStyle(Enum):
|
||||
"""Possible style for the rain radar"""
|
||||
|
||||
|
@ -49,6 +52,7 @@ class IrmKmiRadarStyle(Enum):
|
|||
OPTION_STYLE_YELLOW_RED = 'yellow_red_style'
|
||||
OPTION_STYLE_SATELLITE = 'satellite_style'
|
||||
|
||||
|
||||
class IrmKmiPollenNames(Enum):
|
||||
"""Pollens names from the API"""
|
||||
|
||||
|
@ -72,6 +76,7 @@ class IrmKmiPollenLevels(Enum):
|
|||
RED = 'red'
|
||||
PURPLE = 'purple'
|
||||
|
||||
|
||||
class IrmKmiForecast(Forecast, total=False):
|
||||
"""Forecast class with additional attributes for IRM KMI"""
|
||||
|
||||
|
@ -84,6 +89,7 @@ class IrmKmiForecast(Forecast, total=False):
|
|||
|
||||
class CurrentWeatherData(TypedDict, total=False):
|
||||
"""Class to hold the currently observable weather at a given location"""
|
||||
|
||||
condition: str | None
|
||||
temperature: float | None
|
||||
wind_speed: float | None
|
||||
|
@ -95,6 +101,7 @@ class CurrentWeatherData(TypedDict, total=False):
|
|||
|
||||
class WarningData(TypedDict, total=False):
|
||||
"""Holds data about a specific warning"""
|
||||
|
||||
slug: str
|
||||
id: int
|
||||
level: int
|
||||
|
@ -106,6 +113,7 @@ class WarningData(TypedDict, total=False):
|
|||
|
||||
class IrmKmiRadarForecast(Forecast):
|
||||
"""Forecast class to handle rain forecast from the IRM KMI rain radar"""
|
||||
|
||||
rain_forecast_max: float
|
||||
rain_forecast_min: float
|
||||
might_rain: bool
|
||||
|
@ -114,6 +122,7 @@ class IrmKmiRadarForecast(Forecast):
|
|||
|
||||
class AnimationFrameData(TypedDict, total=False):
|
||||
"""Holds one single frame of the radar camera, along with the timestamp of the frame"""
|
||||
|
||||
time: datetime | None
|
||||
image: bytes | str | None
|
||||
value: float | None
|
||||
|
@ -124,6 +133,7 @@ class AnimationFrameData(TypedDict, total=False):
|
|||
|
||||
class RadarAnimationData(TypedDict, total=False):
|
||||
"""Holds frames and additional data for the animation to be rendered"""
|
||||
|
||||
sequence: List[AnimationFrameData] | None
|
||||
most_recent_image_idx: int | None
|
||||
hint: str | None
|
||||
|
|
|
@ -39,11 +39,11 @@ class PollenParser:
|
|||
|
||||
elements: List[ET.Element] = self._extract_elements(root)
|
||||
|
||||
pollens = {e.attrib.get('x', None): self._get_elem_text(e).lower()
|
||||
for e in elements if 'tspan' in e.tag and str(self._get_elem_text(e)).lower() in IrmKmiPollenNames}
|
||||
pollens = {e.attrib.get('x', None): self._get_txt(e).lower()
|
||||
for e in elements if 'tspan' in e.tag and str(self._get_txt(e)).lower() in IrmKmiPollenNames}
|
||||
|
||||
pollen_levels = {e.attrib.get('x', None): POLLEN_LEVEL_TO_COLOR[self._get_elem_text(e)]
|
||||
for e in elements if 'tspan' in e.tag and self._get_elem_text(e) in POLLEN_LEVEL_TO_COLOR}
|
||||
pollen_levels = {e.attrib.get('x', None): POLLEN_LEVEL_TO_COLOR[self._get_txt(e)]
|
||||
for e in elements if 'tspan' in e.tag and self._get_txt(e) in POLLEN_LEVEL_TO_COLOR}
|
||||
|
||||
level_dots = {e.attrib.get('cx', None) for e in elements if 'circle' in e.tag}
|
||||
|
||||
|
@ -112,7 +112,7 @@ class PollenParser:
|
|||
return elements
|
||||
|
||||
@staticmethod
|
||||
def _get_elem_text(e) -> str | None:
|
||||
def _get_txt(e) -> str | None:
|
||||
if e.text is not None:
|
||||
return e.text.strip()
|
||||
return None
|
||||
|
|
|
@ -149,7 +149,7 @@ class RainGraph:
|
|||
"""
|
||||
return self._animation_data.get('hint', '')
|
||||
|
||||
async def _download_clouds(self, idx=None):
|
||||
async def _download_clouds(self, idx: int | None = None):
|
||||
"""
|
||||
Download cloud images and save the result in the internal state.
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue