diff --git a/homeassistant/components/environment_canada/strings.json b/homeassistant/components/environment_canada/strings.json index b0b04f73879ed0..3e58f15e0fe73d 100644 --- a/homeassistant/components/environment_canada/strings.json +++ b/homeassistant/components/environment_canada/strings.json @@ -2,12 +2,12 @@ "config": { "step": { "user": { - "title": "Environment Canada: weather location and language", - "description": "Either a station ID or latitude/longitude must be specified. The default latitude/longitude used are the values configured in your Home Assistant installation. The closest weather station to the coordinates will be used if specifying coordinates. If a station code is used it must follow the format: PP/code, where PP is the two-letter province and code is the station ID. The list of station IDs can be found here: https://dd.weather.gc.ca/citypage_weather/docs/site_list_towns_en.csv. Weather information can be retrieved in either English or French.", + "title": "Environment Canada: Location and language", + "description": "You can specify a location using either a station code or latitude/longitude coordinates.\n\nDefault behavior: If no station code is entered, the system uses the latitude/longitude values configured in your Home Assistant installation.\n\nStation code format: Station codes follow the format \"s0000123\" or simply \"123\".\n\nFind station codes at https://dd.weather.gc.ca/today/citypage_weather/docs/site_list_towns_en.csv.", "data": { "latitude": "[%key:common::config_flow::data::latitude%]", "longitude": "[%key:common::config_flow::data::longitude%]", - "station": "Weather station ID", + "station": "Station code", "language": "Weather information language" } } @@ -16,7 +16,7 @@ "already_configured": "[%key:common::config_flow::abort::already_configured_service%]" }, "error": { - "bad_station_id": "Station ID is invalid, missing, or not found in the station ID database", + "bad_station_id": "Station code is invalid, missing, or not found in the station code database", "cannot_connect": "[%key:common::config_flow::error::cannot_connect%]", "error_response": "Response from Environment Canada in error", "too_many_attempts": "Connections to Environment Canada are rate limited; Try again in 60 seconds", diff --git a/homeassistant/components/wyoming/config_flow.py b/homeassistant/components/wyoming/config_flow.py index 41e7b9cf1e6d80..bbc7676aab4d4d 100644 --- a/homeassistant/components/wyoming/config_flow.py +++ b/homeassistant/components/wyoming/config_flow.py @@ -70,17 +70,13 @@ async def async_step_hassio( self._abort_if_unique_id_configured() uri = urlparse(discovery_info.config["uri"]) - for entry in self._async_current_entries(include_ignore=True): - if ( - entry.data[CONF_HOST] == uri.hostname - and entry.data[CONF_PORT] == uri.port - ): - return self.async_update_reload_and_abort( - entry, - unique_id=discovery_info.uuid, - reload_even_if_entry_is_unchanged=False, - reason="already_configured", - ) + for entry in self._iter_entries(uri.hostname, uri.port): + return self.async_update_reload_and_abort( + entry, + unique_id=discovery_info.uuid, + reload_even_if_entry_is_unchanged=False, + reason="already_configured", + ) self._hassio_discovery = discovery_info self.context.update( @@ -139,12 +135,8 @@ async def async_step_zeroconf( self.context["title_placeholders"] = {"name": self._name} - for entry in self._async_current_entries(include_ignore=True): - if ( - entry.data[CONF_HOST] == service.host - and entry.data[CONF_PORT] == service.port - and entry.source != SOURCE_HASSIO - ): + for entry in self._iter_entries(service.host, service.port): + if entry.source != SOURCE_HASSIO: return self.async_update_reload_and_abort( entry, unique_id=unique_id, @@ -176,3 +168,9 @@ async def async_step_zeroconf_confirm( CONF_PORT: self._service.port, }, ) + + def _iter_entries(self, host: str, port: int): + """Yield entries with matching host/port.""" + for entry in self._async_current_entries(include_ignore=True): + if entry.data.get(CONF_HOST) == host and entry.data.get(CONF_PORT) == port: + yield entry diff --git a/tests/components/wyoming/test_config_flow.py b/tests/components/wyoming/test_config_flow.py index 30faa2dd441f54..d9841d9a914740 100644 --- a/tests/components/wyoming/test_config_flow.py +++ b/tests/components/wyoming/test_config_flow.py @@ -324,3 +324,32 @@ async def test_zeroconf_discovery_already_configured( assert result.get("type") is FlowResultType.ABORT assert entry.unique_id == "test_zeroconf_name._wyoming._tcp.local._Test Satellite" + + +async def test_bad_config_entry(hass: HomeAssistant) -> None: + """Test we can continue if a config entry is missing info.""" + entry = MockConfigEntry( + domain=DOMAIN, + data={}, # no host/port + ) + entry.add_to_hass(hass) + + # hassio + result = await hass.config_entries.flow.async_init( + DOMAIN, + data=ADDON_DISCOVERY, + context={"source": config_entries.SOURCE_HASSIO}, + ) + assert result.get("type") is FlowResultType.FORM + + # zeroconf + with patch( + "homeassistant.components.wyoming.data.load_wyoming_info", + return_value=SATELLITE_INFO, + ): + result = await hass.config_entries.flow.async_init( + DOMAIN, + data=ZEROCONF_DISCOVERY, + context={"source": config_entries.SOURCE_ZEROCONF}, + ) + assert result.get("type") is FlowResultType.FORM