mirror of
https://github.com/home-assistant/core.git
synced 2026-08-24 10:13:52 -05:00
Add radar colour scale option to Environment Canada (#177338)
Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
This commit is contained in:
co-authored by
Joost Lekkerkerker
parent
1b074facf8
commit
e530a19a33
@@ -12,6 +12,7 @@ from homeassistant.helpers import config_validation as cv
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
|
||||
from .const import (
|
||||
CONF_RADAR_COLORS,
|
||||
CONF_RADAR_DURATION,
|
||||
CONF_RADAR_FPS,
|
||||
CONF_RADAR_LAYER,
|
||||
@@ -20,6 +21,7 @@ from .const import (
|
||||
CONF_RADAR_RADIUS,
|
||||
CONF_RADAR_TIMESTAMP,
|
||||
CONF_STATION,
|
||||
DEFAULT_RADAR_COLORS,
|
||||
DEFAULT_RADAR_DURATION,
|
||||
DEFAULT_RADAR_FPS,
|
||||
DEFAULT_RADAR_LAYER,
|
||||
@@ -81,6 +83,7 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ECConfigEntry) ->
|
||||
radius=int(options.get(CONF_RADAR_RADIUS, DEFAULT_RADAR_RADIUS)),
|
||||
loop_minutes=int(options.get(CONF_RADAR_DURATION, DEFAULT_RADAR_DURATION)),
|
||||
fps=int(options.get(CONF_RADAR_FPS, DEFAULT_RADAR_FPS)),
|
||||
colors=int(options.get(CONF_RADAR_COLORS, DEFAULT_RADAR_COLORS)),
|
||||
)
|
||||
radar_coordinator = ECDataUpdateCoordinator(
|
||||
hass, config_entry, radar_data, "radar", DEFAULT_RADAR_UPDATE_INTERVAL
|
||||
|
||||
@@ -30,6 +30,7 @@ from homeassistant.helpers.selector import (
|
||||
)
|
||||
|
||||
from .const import (
|
||||
CONF_RADAR_COLORS,
|
||||
CONF_RADAR_DURATION,
|
||||
CONF_RADAR_FPS,
|
||||
CONF_RADAR_LAYER,
|
||||
@@ -39,6 +40,7 @@ from .const import (
|
||||
CONF_RADAR_TIMESTAMP,
|
||||
CONF_STATION,
|
||||
CONF_TITLE,
|
||||
DEFAULT_RADAR_COLORS,
|
||||
DEFAULT_RADAR_DURATION,
|
||||
DEFAULT_RADAR_FPS,
|
||||
DEFAULT_RADAR_LAYER,
|
||||
@@ -47,6 +49,7 @@ from .const import (
|
||||
DEFAULT_RADAR_RADIUS,
|
||||
DEFAULT_RADAR_TIMESTAMP,
|
||||
DOMAIN,
|
||||
RADAR_COLOR_OPTIONS,
|
||||
RADAR_LAYERS,
|
||||
)
|
||||
|
||||
@@ -230,6 +233,15 @@ class OptionsFlowHandler(OptionsFlowWithReload):
|
||||
min=1, max=30, step=1, unit_of_measurement="fps"
|
||||
)
|
||||
),
|
||||
vol.Required(
|
||||
CONF_RADAR_COLORS,
|
||||
default=options.get(CONF_RADAR_COLORS, DEFAULT_RADAR_COLORS),
|
||||
): SelectSelector(
|
||||
SelectSelectorConfig(
|
||||
options=RADAR_COLOR_OPTIONS,
|
||||
translation_key="radar_colors",
|
||||
)
|
||||
),
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
@@ -14,8 +14,10 @@ CONF_RADAR_OPACITY = "radar_opacity"
|
||||
CONF_RADAR_RADIUS = "radar_radius"
|
||||
CONF_RADAR_DURATION = "radar_duration"
|
||||
CONF_RADAR_FPS = "radar_fps"
|
||||
CONF_RADAR_COLORS = "radar_colors"
|
||||
|
||||
RADAR_LAYERS = ["rain", "snow", "precip_type"]
|
||||
RADAR_COLOR_OPTIONS = ["8", "14"]
|
||||
|
||||
# Defaults preserve the radar behaviour from before the options flow existed:
|
||||
# the precipitation-type layer with the legend hidden.
|
||||
@@ -27,3 +29,6 @@ DEFAULT_RADAR_RADIUS = 200
|
||||
# 0 means use the full range of images Environment Canada reports as available.
|
||||
DEFAULT_RADAR_DURATION = 0
|
||||
DEFAULT_RADAR_FPS = 5
|
||||
# Colour count only affects the rain/snow layers; precip_type always uses the
|
||||
# WMS server's single default style.
|
||||
DEFAULT_RADAR_COLORS = "14"
|
||||
|
||||
@@ -121,6 +121,7 @@
|
||||
"step": {
|
||||
"init": {
|
||||
"data": {
|
||||
"radar_colors": "Colour scale",
|
||||
"radar_duration": "Loop duration",
|
||||
"radar_fps": "Loop frame rate",
|
||||
"radar_layer": "Radar type",
|
||||
@@ -130,6 +131,7 @@
|
||||
"radar_timestamp": "Show timestamp"
|
||||
},
|
||||
"data_description": {
|
||||
"radar_colors": "Number of colours in the rain/snow radar scale (has no effect on the precipitation type layer)",
|
||||
"radar_duration": "How far back the radar animation goes, in minutes (0 for the full available history)",
|
||||
"radar_fps": "Frame rate of the radar animation",
|
||||
"radar_opacity": "Opacity of the radar layer overlay (0-100)",
|
||||
@@ -140,6 +142,12 @@
|
||||
}
|
||||
},
|
||||
"selector": {
|
||||
"radar_colors": {
|
||||
"options": {
|
||||
"8": "8 colours",
|
||||
"14": "14 colours"
|
||||
}
|
||||
},
|
||||
"radar_layer": {
|
||||
"options": {
|
||||
"precip_type": "Precipitation type",
|
||||
|
||||
@@ -9,6 +9,7 @@ import pytest
|
||||
|
||||
from homeassistant import config_entries
|
||||
from homeassistant.components.environment_canada.const import (
|
||||
CONF_RADAR_COLORS,
|
||||
CONF_RADAR_DURATION,
|
||||
CONF_RADAR_FPS,
|
||||
CONF_RADAR_LAYER,
|
||||
@@ -17,6 +18,7 @@ from homeassistant.components.environment_canada.const import (
|
||||
CONF_RADAR_RADIUS,
|
||||
CONF_RADAR_TIMESTAMP,
|
||||
CONF_STATION,
|
||||
DEFAULT_RADAR_COLORS,
|
||||
DEFAULT_RADAR_DURATION,
|
||||
DEFAULT_RADAR_FPS,
|
||||
DEFAULT_RADAR_LAYER,
|
||||
@@ -252,6 +254,7 @@ async def test_options_flow_form(hass: HomeAssistant, ec_data: dict[str, Any]) -
|
||||
CONF_RADAR_RADIUS,
|
||||
CONF_RADAR_DURATION,
|
||||
CONF_RADAR_FPS,
|
||||
CONF_RADAR_COLORS,
|
||||
}
|
||||
|
||||
|
||||
@@ -269,6 +272,7 @@ async def test_options_flow_save(hass: HomeAssistant, ec_data: dict[str, Any]) -
|
||||
CONF_RADAR_RADIUS: 100,
|
||||
CONF_RADAR_DURATION: 30,
|
||||
CONF_RADAR_FPS: 10,
|
||||
CONF_RADAR_COLORS: "8",
|
||||
}
|
||||
with patch(
|
||||
"homeassistant.components.environment_canada.async_setup_entry",
|
||||
@@ -296,6 +300,7 @@ async def test_options_flow_prefills_saved_options(
|
||||
CONF_RADAR_RADIUS: 300,
|
||||
CONF_RADAR_DURATION: 60,
|
||||
CONF_RADAR_FPS: 15,
|
||||
CONF_RADAR_COLORS: "8",
|
||||
}
|
||||
config_entry = await init_integration(hass, ec_data, options=saved_options)
|
||||
|
||||
@@ -309,6 +314,7 @@ async def test_options_flow_prefills_saved_options(
|
||||
assert defaults[CONF_RADAR_RADIUS] == 300
|
||||
assert defaults[CONF_RADAR_DURATION] == 60
|
||||
assert defaults[CONF_RADAR_FPS] == 15
|
||||
assert defaults[CONF_RADAR_COLORS] == "8"
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
@@ -324,6 +330,7 @@ async def test_options_flow_prefills_saved_options(
|
||||
"radius": DEFAULT_RADAR_RADIUS,
|
||||
"loop_minutes": DEFAULT_RADAR_DURATION,
|
||||
"fps": DEFAULT_RADAR_FPS,
|
||||
"colors": int(DEFAULT_RADAR_COLORS),
|
||||
},
|
||||
id="defaults",
|
||||
),
|
||||
@@ -336,6 +343,7 @@ async def test_options_flow_prefills_saved_options(
|
||||
CONF_RADAR_RADIUS: 150.0,
|
||||
CONF_RADAR_DURATION: 30.0,
|
||||
CONF_RADAR_FPS: 10.0,
|
||||
CONF_RADAR_COLORS: "8",
|
||||
},
|
||||
{
|
||||
"layer": "snow",
|
||||
@@ -345,6 +353,7 @@ async def test_options_flow_prefills_saved_options(
|
||||
"radius": 150,
|
||||
"loop_minutes": 30,
|
||||
"fps": 10,
|
||||
"colors": 8,
|
||||
},
|
||||
id="custom",
|
||||
),
|
||||
@@ -373,3 +382,5 @@ async def test_ecmap_built_from_options(
|
||||
assert isinstance(kwargs["loop_minutes"], int)
|
||||
assert kwargs["fps"] == expected["fps"]
|
||||
assert isinstance(kwargs["fps"], int)
|
||||
assert kwargs["colors"] == expected["colors"]
|
||||
assert isinstance(kwargs["colors"], int)
|
||||
|
||||
Reference in New Issue
Block a user