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:
@@ -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")
|
||||
|
||||
@@ -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",
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user