From 493e8c1a22f7cac1283674e494bef414dd13b9a8 Mon Sep 17 00:00:00 2001 From: Michael Jones Date: Wed, 28 Jan 2026 22:18:35 +0000 Subject: [PATCH] Append ID to flood monitoring station name in EAFM (#161794) --- homeassistant/components/eafm/config_flow.py | 9 ++++++++- tests/components/eafm/test_config_flow.py | 10 +++++----- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/homeassistant/components/eafm/config_flow.py b/homeassistant/components/eafm/config_flow.py index 6be1066575f..1b446ea62f3 100644 --- a/homeassistant/components/eafm/config_flow.py +++ b/homeassistant/components/eafm/config_flow.py @@ -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") diff --git a/tests/components/eafm/test_config_flow.py b/tests/components/eafm/test_config_flow.py index 9773a8b619e..1379b49d55e 100644 --- a/tests/components/eafm/test_config_flow.py +++ b/tests/components/eafm/test_config_flow.py @@ -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", }