mirror of
https://github.com/jdejaegh/irm-kmi-api.git
synced 2025-06-26 20:05:40 +02:00
Breaking: radar style is now an enum
This commit is contained in:
parent
7407cd3b58
commit
2bcbb35262
5 changed files with 35 additions and 34 deletions
|
@ -18,7 +18,7 @@ from .const import MAP_WARNING_ID_TO_SLUG as SLUG_MAP, WWEVOL_TO_ENUM_MAP
|
|||
from .const import STYLE_TO_PARAM_MAP, WEEKDAYS
|
||||
from .data import (AnimationFrameData, CurrentWeatherData, Forecast,
|
||||
IrmKmiForecast, IrmKmiRadarForecast, RadarAnimationData,
|
||||
WarningData)
|
||||
WarningData, IrmKmiRadarStyle)
|
||||
from .pollen import PollenParser
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
@ -444,7 +444,7 @@ class IrmKmiApiClientHa(IrmKmiApiClient):
|
|||
|
||||
return forecasts
|
||||
|
||||
def get_animation_data(self, tz: ZoneInfo, lang: str, style: str, dark_mode: bool) -> RadarAnimationData:
|
||||
def get_animation_data(self, tz: ZoneInfo, lang: str, style: IrmKmiRadarStyle, dark_mode: bool) -> RadarAnimationData:
|
||||
"""
|
||||
Get all the image URLs and create the radar animation data object.
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
from typing import Final
|
||||
|
||||
from irm_kmi_api.data import IrmKmiConditionEvol
|
||||
from irm_kmi_api.data import IrmKmiConditionEvol, IrmKmiRadarStyle
|
||||
|
||||
# TODO enum as well for those three values?
|
||||
POLLEN_NAMES: Final = {'Alder', 'Ash', 'Birch', 'Grasses', 'Hazel', 'Mugwort', 'Oak'}
|
||||
|
@ -8,16 +8,11 @@ POLLEN_LEVEL_TO_COLOR = {'null': 'green', 'low': 'yellow', 'moderate': 'orange',
|
|||
'active': 'active'}
|
||||
WEEKDAYS = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']
|
||||
|
||||
# TODO move those to an Enum
|
||||
OPTION_STYLE_STD: Final = 'standard_style'
|
||||
OPTION_STYLE_CONTRAST: Final = 'contrast_style'
|
||||
OPTION_STYLE_YELLOW_RED: Final = 'yellow_red_style'
|
||||
OPTION_STYLE_SATELLITE: Final = 'satellite_style'
|
||||
STYLE_TO_PARAM_MAP: Final = {
|
||||
OPTION_STYLE_STD: 1,
|
||||
OPTION_STYLE_CONTRAST: 2,
|
||||
OPTION_STYLE_YELLOW_RED: 3,
|
||||
OPTION_STYLE_SATELLITE: 4
|
||||
IrmKmiRadarStyle.OPTION_STYLE_STD: 1,
|
||||
IrmKmiRadarStyle.OPTION_STYLE_CONTRAST: 2,
|
||||
IrmKmiRadarStyle.OPTION_STYLE_YELLOW_RED: 3,
|
||||
IrmKmiRadarStyle.OPTION_STYLE_SATELLITE: 4
|
||||
}
|
||||
|
||||
MAP_WARNING_ID_TO_SLUG: Final = {
|
||||
|
|
|
@ -40,6 +40,14 @@ class IrmKmiConditionEvol(Enum):
|
|||
ONE_WAY = 'one_way'
|
||||
TWO_WAYS = 'two_ways'
|
||||
STABLE = 'stable'
|
||||
|
||||
class IrmKmiRadarStyle(Enum):
|
||||
"""Possible style for the rain radar"""
|
||||
|
||||
OPTION_STYLE_STD = 'standard_style'
|
||||
OPTION_STYLE_CONTRAST = 'contrast_style'
|
||||
OPTION_STYLE_YELLOW_RED = 'yellow_red_style'
|
||||
OPTION_STYLE_SATELLITE = 'satellite_style'
|
||||
|
||||
class IrmKmiForecast(Forecast, total=False):
|
||||
"""Forecast class with additional attributes for IRM KMI"""
|
||||
|
|
|
@ -12,8 +12,7 @@ from svgwrite.animate import Animate
|
|||
from svgwrite.container import FONT_TEMPLATE
|
||||
|
||||
from .api import IrmKmiApiClient, IrmKmiApiError
|
||||
from .const import OPTION_STYLE_SATELLITE
|
||||
from .data import AnimationFrameData, RadarAnimationData
|
||||
from .data import AnimationFrameData, RadarAnimationData, IrmKmiRadarStyle
|
||||
from .resources import be_black, be_satellite, be_white, nl, roboto
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
@ -25,7 +24,7 @@ class RainGraph:
|
|||
def __init__(self,
|
||||
animation_data: RadarAnimationData,
|
||||
country: str,
|
||||
style: str,
|
||||
style: IrmKmiRadarStyle,
|
||||
dark_mode: bool = False,
|
||||
tz: datetime.tzinfo = None,
|
||||
svg_width: float = 640,
|
||||
|
@ -432,7 +431,7 @@ class RainGraph:
|
|||
def _get_background_png_b64(self) -> str:
|
||||
if self._country == 'NL':
|
||||
return nl.nl_b64
|
||||
elif self._style == OPTION_STYLE_SATELLITE:
|
||||
elif self._style == IrmKmiRadarStyle.OPTION_STYLE_SATELLITE:
|
||||
return be_satellite.be_satelitte_b64
|
||||
elif self._dark_mode:
|
||||
return be_black.be_black_b64
|
||||
|
|
|
@ -7,8 +7,7 @@ from unittest.mock import MagicMock, AsyncMock
|
|||
from zoneinfo import ZoneInfo
|
||||
|
||||
from irm_kmi_api.api import IrmKmiApiClientHa
|
||||
from irm_kmi_api.const import OPTION_STYLE_SATELLITE
|
||||
from irm_kmi_api.data import AnimationFrameData, RadarAnimationData
|
||||
from irm_kmi_api.data import AnimationFrameData, RadarAnimationData, IrmKmiRadarStyle
|
||||
from irm_kmi_api.rain_graph import RainGraph
|
||||
from tests.conftest import load_fixture
|
||||
|
||||
|
@ -45,7 +44,7 @@ async def test_svg_frame_setup():
|
|||
rain_graph = RainGraph(
|
||||
animation_data=data,
|
||||
country='BE',
|
||||
style='STD',
|
||||
style=IrmKmiRadarStyle.OPTION_STYLE_STD,
|
||||
)
|
||||
|
||||
await rain_graph._draw_svg_frame()
|
||||
|
@ -65,7 +64,7 @@ def test_svg_hint():
|
|||
rain_graph = RainGraph(
|
||||
animation_data=data,
|
||||
country='BE',
|
||||
style='STD',
|
||||
style=IrmKmiRadarStyle.OPTION_STYLE_STD,
|
||||
)
|
||||
|
||||
rain_graph._write_hint()
|
||||
|
@ -81,7 +80,7 @@ def test_svg_time_bars():
|
|||
tz = datetime.UTC,
|
||||
animation_data=data,
|
||||
country='BE',
|
||||
style='STD',
|
||||
style=IrmKmiRadarStyle.OPTION_STYLE_STD,
|
||||
)
|
||||
|
||||
rain_graph._draw_hour_bars()
|
||||
|
@ -100,7 +99,7 @@ def test_draw_chances_path():
|
|||
rain_graph = RainGraph(
|
||||
animation_data=data,
|
||||
country='BE',
|
||||
style='STD',
|
||||
style=IrmKmiRadarStyle.OPTION_STYLE_STD,
|
||||
)
|
||||
|
||||
rain_graph._draw_chances_path()
|
||||
|
@ -118,7 +117,7 @@ def test_draw_data_line():
|
|||
rain_graph = RainGraph(
|
||||
animation_data=data,
|
||||
country='BE',
|
||||
style='STD',
|
||||
style=IrmKmiRadarStyle.OPTION_STYLE_STD,
|
||||
)
|
||||
|
||||
rain_graph._draw_data_line()
|
||||
|
@ -136,7 +135,7 @@ async def test_insert_background():
|
|||
rain_graph = RainGraph(
|
||||
animation_data=data,
|
||||
country='BE',
|
||||
style='STD',
|
||||
style=IrmKmiRadarStyle.OPTION_STYLE_STD,
|
||||
)
|
||||
|
||||
await rain_graph._insert_background()
|
||||
|
@ -159,7 +158,7 @@ def test_draw_current_frame_line_moving():
|
|||
rain_graph = RainGraph(
|
||||
animation_data=data,
|
||||
country='BE',
|
||||
style='STD',
|
||||
style=IrmKmiRadarStyle.OPTION_STYLE_STD,
|
||||
)
|
||||
|
||||
rain_graph._draw_current_fame_line()
|
||||
|
@ -187,7 +186,7 @@ def test_draw_current_frame_line_index():
|
|||
rain_graph = RainGraph(
|
||||
animation_data=data,
|
||||
country='BE',
|
||||
style='STD',
|
||||
style=IrmKmiRadarStyle.OPTION_STYLE_STD,
|
||||
)
|
||||
|
||||
rain_graph._draw_current_fame_line(0)
|
||||
|
@ -216,7 +215,7 @@ def test_draw_description_text():
|
|||
tz=datetime.UTC,
|
||||
animation_data=data,
|
||||
country='BE',
|
||||
style='STD',
|
||||
style=IrmKmiRadarStyle.OPTION_STYLE_STD,
|
||||
)
|
||||
|
||||
rain_graph._draw_description_text()
|
||||
|
@ -243,7 +242,7 @@ def test_draw_cloud_layer():
|
|||
rain_graph = RainGraph(
|
||||
animation_data=data,
|
||||
country='BE',
|
||||
style='STD',
|
||||
style=IrmKmiRadarStyle.OPTION_STYLE_STD,
|
||||
)
|
||||
|
||||
rain_graph._insert_cloud_layer()
|
||||
|
@ -263,7 +262,7 @@ async def test_draw_location_layer():
|
|||
rain_graph = RainGraph(
|
||||
animation_data=data,
|
||||
country='BE',
|
||||
style='STD',
|
||||
style=IrmKmiRadarStyle.OPTION_STYLE_STD,
|
||||
)
|
||||
|
||||
await rain_graph._draw_location()
|
||||
|
@ -281,7 +280,7 @@ def test_get_animation_data():
|
|||
|
||||
tz = ZoneInfo('Europe/Brussels')
|
||||
lang = 'en'
|
||||
style = OPTION_STYLE_SATELLITE
|
||||
style = IrmKmiRadarStyle.OPTION_STYLE_SATELLITE
|
||||
dark_mode = False
|
||||
|
||||
api._api_data = json.loads(load_fixture("forecast.json"))
|
||||
|
@ -306,7 +305,7 @@ async def test_download_single_cloud():
|
|||
rain_graph = RainGraph(
|
||||
animation_data=data,
|
||||
country='BE',
|
||||
style='STD',
|
||||
style=IrmKmiRadarStyle.OPTION_STYLE_STD,
|
||||
)
|
||||
|
||||
rain_graph._api_client = MagicMock()
|
||||
|
@ -324,7 +323,7 @@ async def test_download_many_clouds():
|
|||
rain_graph = RainGraph(
|
||||
animation_data=data,
|
||||
country='BE',
|
||||
style='STD',
|
||||
style=IrmKmiRadarStyle.OPTION_STYLE_STD,
|
||||
)
|
||||
|
||||
rain_graph._api_client = MagicMock()
|
||||
|
@ -339,11 +338,11 @@ def test_can_build_rain_graph_with_empty_sequence():
|
|||
|
||||
RainGraph(
|
||||
RadarAnimationData(sequence=None),
|
||||
'en', 'style'
|
||||
'BE', IrmKmiRadarStyle.OPTION_STYLE_STD
|
||||
)
|
||||
|
||||
RainGraph(
|
||||
RadarAnimationData(sequence=[]),
|
||||
'en', 'style'
|
||||
'BE', IrmKmiRadarStyle.OPTION_STYLE_STD
|
||||
)
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue