1
0
mirror of https://github.com/home-assistant/core.git synced 2026-02-14 23:28:42 +00:00

Append ID to flood monitoring station name in EAFM (#161794)

This commit is contained in:
Michael Jones
2026-01-28 22:18:35 +00:00
committed by GitHub
parent 1b16b24550
commit 493e8c1a22
2 changed files with 13 additions and 6 deletions

View File

@@ -41,13 +41,20 @@ class UKFloodsFlowHandler(ConfigFlow, domain=DOMAIN):
self.stations = {}
for station in stations:
label = station["label"]
rloId = station["RLOIid"]
# API annoyingly sometimes returns a list and some times returns a string
# E.g. L3121 has a label of ['Scurf Dyke', 'Scurf Dyke Dyke Level']
if isinstance(label, list):
label = label[-1]
self.stations[label] = station["stationReference"]
# Similar for RLOIid
# E.g. 0018 has an RLOIid of ['10427', '9154']
if isinstance(rloId, list):
rloId = rloId[-1]
fullName = label + " - " + rloId
self.stations[fullName] = station["stationReference"]
if not self.stations:
return self.async_abort(reason="no_stations")

View File

@@ -26,7 +26,7 @@ async def test_flow_no_discovered_stations(
async def test_flow_invalid_station(hass: HomeAssistant, mock_get_stations) -> None:
"""Test config flow errors on invalid station."""
mock_get_stations.return_value = [
{"label": "My station", "stationReference": "L12345"}
{"label": "My station", "stationReference": "L12345", "RLOIid": "R12345"}
]
result = await hass.config_entries.flow.async_init(
@@ -45,10 +45,10 @@ async def test_flow_works(
) -> None:
"""Test config flow discovers no station."""
mock_get_stations.return_value = [
{"label": "My station", "stationReference": "L12345"}
{"label": "My station", "stationReference": "L12345", "RLOIid": "R12345"}
]
mock_get_station.return_value = [
{"label": "My station", "stationReference": "L12345"}
{"label": "My station", "stationReference": "L12345", "RLOIid": "R12345"}
]
result = await hass.config_entries.flow.async_init(
@@ -58,11 +58,11 @@ async def test_flow_works(
with patch("homeassistant.components.eafm.async_setup_entry", return_value=True):
result = await hass.config_entries.flow.async_configure(
result["flow_id"], user_input={"station": "My station"}
result["flow_id"], user_input={"station": "My station - R12345"}
)
assert result["type"] is FlowResultType.CREATE_ENTRY
assert result["title"] == "My station"
assert result["title"] == "My station - R12345"
assert result["data"] == {
"station": "L12345",
}