From 5a706cd769faf812ec88ae5eb76aadecb185ffad Mon Sep 17 00:00:00 2001 From: Manu Date: Mon, 26 Oct 2026 08:41:41 +0100 Subject: [PATCH] Use `LocationSelector` in `nws` integration (#188654) --- homeassistant/components/nws/__init__.py | 29 +++++-- homeassistant/components/nws/config_flow.py | 60 +++++++++------ homeassistant/components/nws/strings.json | 5 +- homeassistant/components/nws/weather.py | 5 +- tests/components/nws/const.py | 7 +- .../nws/snapshots/test_diagnostics.ambr | 6 +- tests/components/nws/test_config_flow.py | 52 +++++++------ tests/components/nws/test_diagnostics.py | 1 + tests/components/nws/test_init.py | 76 ++++++++++++++++--- tests/components/nws/test_sensor.py | 3 + tests/components/nws/test_weather.py | 15 ++++ 11 files changed, 187 insertions(+), 72 deletions(-) diff --git a/homeassistant/components/nws/__init__.py b/homeassistant/components/nws/__init__.py index 70b253372e9b..5857800bb7d8 100644 --- a/homeassistant/components/nws/__init__.py +++ b/homeassistant/components/nws/__init__.py @@ -8,7 +8,13 @@ import logging from pynws import NwsNoDataError, SimpleNWS, call_with_retry from homeassistant.config_entries import ConfigEntry -from homeassistant.const import CONF_API_KEY, CONF_LATITUDE, CONF_LONGITUDE, Platform +from homeassistant.const import ( + CONF_API_KEY, + CONF_LATITUDE, + CONF_LOCATION, + CONF_LONGITUDE, + Platform, +) from homeassistant.core import Event, EventStateChangedData, HomeAssistant, callback from homeassistant.exceptions import ConfigEntryError, ConfigEntryNotReady from homeassistant.helpers import ( @@ -59,7 +65,7 @@ def get_base_unique_id(entry: ConfigEntry) -> str: """Return base unique id from config entry.""" if entry.data.get(CONF_LOCATION_ENTITY): return entry.entry_id - return base_unique_id(entry.data[CONF_LATITUDE], entry.data[CONF_LONGITUDE]) + return base_unique_id(**entry.data[CONF_LOCATION]) @dataclass @@ -114,8 +120,8 @@ async def async_setup_entry(hass: HomeAssistant, entry: NWSConfigEntry) -> None: longitude = coordinates.longitude station = None else: - latitude = entry.data[CONF_LATITUDE] - longitude = entry.data[CONF_LONGITUDE] + latitude = entry.data[CONF_LOCATION][CONF_LATITUDE] + longitude = entry.data[CONF_LOCATION][CONF_LONGITUDE] station = entry.data[CONF_STATION] client_session = async_get_clientsession(hass) @@ -285,10 +291,23 @@ def device_info(entry: ConfigEntry, nws_data: NWSData) -> DeviceInfo: if nws_data.location_entity_id: name = f"NWS: {nws_data.location_entity_id}" else: - name = f"NWS: {entry.data[CONF_LATITUDE]}, {entry.data[CONF_LONGITUDE]}" + location = entry.data[CONF_LOCATION] + name = f"NWS: {location[CONF_LATITUDE]}, {location[CONF_LONGITUDE]}" return DeviceInfo( entry_type=DeviceEntryType.SERVICE, identifiers={(DOMAIN, uid)}, manufacturer="National Weather Service", name=name, ) + + +async def async_migrate_entry(hass: HomeAssistant, entry: NWSConfigEntry) -> None: + """Migrate config entry.""" + + if entry.version < 2: + data = dict(entry.data) + long = data.pop(CONF_LONGITUDE, None) + lat = data.pop(CONF_LATITUDE, None) + if lat is not None and long is not None: + data[CONF_LOCATION] = {CONF_LATITUDE: lat, CONF_LONGITUDE: long} + hass.config_entries.async_update_entry(entry, data=data, version=2) diff --git a/homeassistant/components/nws/config_flow.py b/homeassistant/components/nws/config_flow.py index 720a57b55e02..1616b1a51695 100644 --- a/homeassistant/components/nws/config_flow.py +++ b/homeassistant/components/nws/config_flow.py @@ -8,13 +8,23 @@ import probatio from pynws import SimpleNWS from homeassistant.config_entries import ConfigFlow, ConfigFlowResult -from homeassistant.const import CONF_API_KEY, CONF_LATITUDE, CONF_LONGITUDE +from homeassistant.const import ( + CONF_API_KEY, + CONF_LATITUDE, + CONF_LOCATION, + CONF_LONGITUDE, +) from homeassistant.core import HomeAssistant from homeassistant.exceptions import HomeAssistantError -from homeassistant.helpers import config_validation as cv, entity_registry as er +from homeassistant.helpers import entity_registry as er from homeassistant.helpers.aiohttp_client import async_get_clientsession from homeassistant.helpers.location import get_state_coordinates -from homeassistant.helpers.selector import EntitySelector, EntitySelectorConfig +from homeassistant.helpers.selector import ( + EntitySelector, + EntitySelectorConfig, + LocationSelector, + LocationSelectorConfig, +) from . import base_unique_id from .const import CONF_LOCATION_ENTITY, CONF_STATION, DOMAIN @@ -27,8 +37,8 @@ async def validate_input(hass: HomeAssistant, data: dict[str, Any]) -> dict[str, Data has the keys from DATA_SCHEMA with values provided by the user. """ - latitude = data[CONF_LATITUDE] - longitude = data[CONF_LONGITUDE] + latitude = data[CONF_LOCATION][CONF_LATITUDE] + longitude = data[CONF_LOCATION][CONF_LONGITUDE] api_key = data[CONF_API_KEY] station = data.get(CONF_STATION) @@ -48,7 +58,7 @@ async def validate_input(hass: HomeAssistant, data: dict[str, Any]) -> dict[str, class NWSConfigFlow(ConfigFlow, domain=DOMAIN): """Handle a config flow for National Weather Service (NWS).""" - VERSION = 1 + VERSION = 2 @override async def async_step_user( @@ -66,9 +76,7 @@ class NWSConfigFlow(ConfigFlow, domain=DOMAIN): """Handle the specific location configuration step.""" errors: dict[str, str] = {} if user_input is not None: - await self.async_set_unique_id( - base_unique_id(user_input[CONF_LATITUDE], user_input[CONF_LONGITUDE]) - ) + await self.async_set_unique_id(base_unique_id(**user_input[CONF_LOCATION])) self._abort_if_unique_id_configured() try: info = await validate_input(self.hass, user_input) @@ -80,17 +88,23 @@ class NWSConfigFlow(ConfigFlow, domain=DOMAIN): _LOGGER.exception("Unexpected exception") errors["base"] = "unknown" - data_schema = probatio.Schema( - { - probatio.Required(probatio.Secret(CONF_API_KEY)): str, - probatio.Required( - CONF_LATITUDE, default=self.hass.config.latitude - ): cv.latitude, - probatio.Required( - CONF_LONGITUDE, default=self.hass.config.longitude - ): cv.longitude, - probatio.Optional(CONF_STATION): str, - } + data_schema = self.add_suggested_values_to_schema( + probatio.Schema( + { + probatio.Required(probatio.Secret(CONF_API_KEY)): str, + probatio.Required(CONF_LOCATION): LocationSelector( + LocationSelectorConfig(radius=False) + ), + probatio.Optional(CONF_STATION): str, + } + ), + user_input + or { + CONF_LOCATION: { + CONF_LATITUDE: self.hass.config.latitude, + CONF_LONGITUDE: self.hass.config.longitude, + } + }, ) return self.async_show_form( @@ -131,8 +145,10 @@ class NWSConfigFlow(ConfigFlow, domain=DOMAIN): self.hass, { CONF_API_KEY: user_input[CONF_API_KEY], - CONF_LATITUDE: coordinates.latitude, - CONF_LONGITUDE: coordinates.longitude, + CONF_LOCATION: { + CONF_LATITUDE: coordinates.latitude, + CONF_LONGITUDE: coordinates.longitude, + }, }, ) return self.async_create_entry(title=location_entity, data=data) diff --git a/homeassistant/components/nws/strings.json b/homeassistant/components/nws/strings.json index a8135ac8183c..af97199a8ed4 100644 --- a/homeassistant/components/nws/strings.json +++ b/homeassistant/components/nws/strings.json @@ -25,11 +25,10 @@ "location": { "data": { "api_key": "[%key:common::config_flow::data::api_key%]", - "latitude": "[%key:common::config_flow::data::latitude%]", - "longitude": "[%key:common::config_flow::data::longitude%]", + "location": "[%key:common::config_flow::data::location%]", "station": "METAR station code" }, - "description": "If a METAR station code is not specified, the latitude and longitude will be used to find the closest station. For now, the API key can be anything. It is recommended to use a valid email address.", + "description": "If a METAR station code is not specified, the specified location will be used to find the closest station. For now, the API key can be anything. It is recommended to use a valid email address.", "title": "Set up a specific location" }, "user": { diff --git a/homeassistant/components/nws/weather.py b/homeassistant/components/nws/weather.py index f01055359e8b..28d2354d6ec1 100644 --- a/homeassistant/components/nws/weather.py +++ b/homeassistant/components/nws/weather.py @@ -24,8 +24,7 @@ from homeassistant.components.weather import ( ) from homeassistant.config_entries import ConfigEntry from homeassistant.const import ( - CONF_LATITUDE, - CONF_LONGITUDE, + CONF_LOCATION, UnitOfLength, UnitOfPressure, UnitOfSpeed, @@ -94,7 +93,7 @@ async def async_setup_entry( entity_id := entity_registry.async_get_entity_id( WEATHER_DOMAIN, DOMAIN, - f"{base_unique_id(entry.data[CONF_LATITUDE], entry.data[CONF_LONGITUDE])}_{HOURLY}", + f"{base_unique_id(**entry.data[CONF_LOCATION])}_{HOURLY}", ) ): entity_registry.async_remove(entity_id) diff --git a/tests/components/nws/const.py b/tests/components/nws/const.py index fb00d67d9ff2..4bfa58a0cfae 100644 --- a/tests/components/nws/const.py +++ b/tests/components/nws/const.py @@ -21,6 +21,7 @@ from homeassistant.components.weather import ( from homeassistant.const import ( CONF_API_KEY, CONF_LATITUDE, + CONF_LOCATION, CONF_LONGITUDE, UnitOfLength, UnitOfPressure, @@ -36,8 +37,10 @@ from homeassistant.util.unit_conversion import ( NWS_CONFIG = { CONF_API_KEY: "test", - CONF_LATITUDE: 35, - CONF_LONGITUDE: -75, + CONF_LOCATION: { + CONF_LATITUDE: 35, + CONF_LONGITUDE: -75, + }, CONF_STATION: "ABC", } diff --git a/tests/components/nws/snapshots/test_diagnostics.ambr b/tests/components/nws/snapshots/test_diagnostics.ambr index f8bd82a35c42..be85e0f2e18c 100644 --- a/tests/components/nws/snapshots/test_diagnostics.ambr +++ b/tests/components/nws/snapshots/test_diagnostics.ambr @@ -59,8 +59,10 @@ ]), 'info': dict({ 'api_key': '**REDACTED**', - 'latitude': '**REDACTED**', - 'longitude': '**REDACTED**', + 'location': dict({ + 'latitude': '**REDACTED**', + 'longitude': '**REDACTED**', + }), 'station': '**REDACTED**', }), 'observation': dict({ diff --git a/tests/components/nws/test_config_flow.py b/tests/components/nws/test_config_flow.py index de781b7561d5..80705fbfc412 100644 --- a/tests/components/nws/test_config_flow.py +++ b/tests/components/nws/test_config_flow.py @@ -4,6 +4,7 @@ from unittest.mock import AsyncMock, MagicMock import aiohttp import pytest +from pytest_homeassistant.common import MockConfigEntry from homeassistant import config_entries from homeassistant.components.nws.const import ( @@ -12,7 +13,14 @@ from homeassistant.components.nws.const import ( DOMAIN, ) from homeassistant.config_entries import ConfigFlowResult -from homeassistant.const import ATTR_LATITUDE, ATTR_LONGITUDE, CONF_API_KEY +from homeassistant.const import ( + ATTR_LATITUDE, + ATTR_LONGITUDE, + CONF_API_KEY, + CONF_LATITUDE, + CONF_LOCATION, + CONF_LONGITUDE, +) from homeassistant.core import HomeAssistant from homeassistant.data_entry_flow import FlowResultType from homeassistant.helpers import entity_registry as er @@ -52,7 +60,8 @@ async def test_form_location( assert result2["errors"] == {} result3 = await hass.config_entries.flow.async_configure( - result["flow_id"], {CONF_API_KEY: "test"} + result["flow_id"], + {CONF_API_KEY: "test", CONF_LOCATION: {CONF_LATITUDE: 35, CONF_LONGITUDE: -90}}, ) await hass.async_block_till_done() @@ -60,8 +69,7 @@ async def test_form_location( assert result3["title"] == "ABC" assert result3["data"] == { CONF_API_KEY: "test", - "latitude": 35, - "longitude": -90, + CONF_LOCATION: {CONF_LATITUDE: 35, CONF_LONGITUDE: -90}, CONF_STATION: "ABC", } assert result3["result"].unique_id == "35.0_-90.0" @@ -83,7 +91,7 @@ async def test_form_location_cannot_connect( result2 = await hass.config_entries.flow.async_configure( result["flow_id"], - {CONF_API_KEY: "test"}, + {CONF_API_KEY: "test", CONF_LOCATION: {CONF_LATITUDE: 35, CONF_LONGITUDE: -90}}, ) assert result2["type"] is FlowResultType.FORM @@ -92,7 +100,7 @@ async def test_form_location_cannot_connect( mock_instance.set_station.side_effect = None result3 = await hass.config_entries.flow.async_configure( result["flow_id"], - {CONF_API_KEY: "test"}, + {CONF_API_KEY: "test", CONF_LOCATION: {CONF_LATITUDE: 35, CONF_LONGITUDE: -90}}, ) assert result3["type"] is FlowResultType.CREATE_ENTRY @@ -112,7 +120,7 @@ async def test_form_location_unknown_error( result2 = await hass.config_entries.flow.async_configure( result["flow_id"], - {CONF_API_KEY: "test"}, + {CONF_API_KEY: "test", CONF_LOCATION: {CONF_LATITUDE: 35, CONF_LONGITUDE: -90}}, ) assert result2["type"] is FlowResultType.FORM @@ -121,7 +129,7 @@ async def test_form_location_unknown_error( mock_instance.set_station.side_effect = None result3 = await hass.config_entries.flow.async_configure( result["flow_id"], - {CONF_API_KEY: "test"}, + {CONF_API_KEY: "test", CONF_LOCATION: {CONF_LATITUDE: 35, CONF_LONGITUDE: -90}}, ) assert result3["type"] is FlowResultType.CREATE_ENTRY @@ -130,22 +138,18 @@ async def test_form_location_already_configured( hass: HomeAssistant, mock_simple_nws_config, mock_setup_entry: AsyncMock ) -> None: """Test we handle duplicate location entries.""" - result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": config_entries.SOURCE_USER} - ) - await _select_menu_option(hass, result["flow_id"], "location") - result2 = await hass.config_entries.flow.async_configure( - result["flow_id"], - {CONF_API_KEY: "test"}, - ) - await hass.async_block_till_done() - - assert result2["type"] is FlowResultType.CREATE_ENTRY - assert result2["result"].unique_id == "32.87336_-117.22743" - assert len(mock_setup_entry.mock_calls) == 1 - - mock_setup_entry.reset_mock() + MockConfigEntry( + domain=DOMAIN, + title="ABC", + data={ + CONF_API_KEY: "test", + CONF_LOCATION: {CONF_LATITUDE: 35, CONF_LONGITUDE: -90}, + CONF_STATION: "ABC", + }, + unique_id="35.0_-90.0", + version=2, + ).add_to_hass(hass) result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": config_entries.SOURCE_USER} @@ -154,7 +158,7 @@ async def test_form_location_already_configured( result2 = await hass.config_entries.flow.async_configure( result["flow_id"], - {CONF_API_KEY: "test"}, + {CONF_API_KEY: "test", CONF_LOCATION: {CONF_LATITUDE: 35, CONF_LONGITUDE: -90}}, ) await hass.async_block_till_done() diff --git a/tests/components/nws/test_diagnostics.py b/tests/components/nws/test_diagnostics.py index f55b529654dd..ba2e15a7a2ac 100644 --- a/tests/components/nws/test_diagnostics.py +++ b/tests/components/nws/test_diagnostics.py @@ -22,6 +22,7 @@ async def test_entry_diagnostics( entry = MockConfigEntry( domain=nws.DOMAIN, data=NWS_CONFIG, + version=2, ) entry.add_to_hass(hass) await hass.config_entries.async_setup(entry.entry_id) diff --git a/tests/components/nws/test_init.py b/tests/components/nws/test_init.py index 30b346bbcdb8..6a68fbba7b04 100644 --- a/tests/components/nws/test_init.py +++ b/tests/components/nws/test_init.py @@ -9,11 +9,18 @@ from pytest_homeassistant.common import MockConfigEntry, async_fire_time_changed from homeassistant.components.nws.const import ( CONF_LOCATION_ENTITY, + CONF_STATION, DEFAULT_SCAN_INTERVAL, DOMAIN, ) from homeassistant.config_entries import ConfigEntryState -from homeassistant.const import ATTR_LATITUDE, ATTR_LONGITUDE, CONF_API_KEY +from homeassistant.const import ( + ATTR_LATITUDE, + ATTR_LONGITUDE, + CONF_API_KEY, + CONF_LATITUDE, + CONF_LONGITUDE, +) from homeassistant.core import HomeAssistant from homeassistant.helpers import entity_registry as er @@ -39,6 +46,7 @@ async def test_unload_entry(hass: HomeAssistant, mock_simple_nws) -> None: entry = MockConfigEntry( domain=DOMAIN, data=NWS_CONFIG, + version=2, ) entry.add_to_hass(hass) @@ -65,7 +73,9 @@ async def test_setup_with_location_entity( {ATTR_LATITUDE: 40.0, ATTR_LONGITUDE: -80.0}, ) - config_entry = MockConfigEntry(domain=DOMAIN, data=location_entity_config["config"]) + config_entry = MockConfigEntry( + domain=DOMAIN, data=location_entity_config["config"], version=2 + ) config_entry.add_to_hass(hass) await hass.config_entries.async_setup(config_entry.entry_id) @@ -91,7 +101,9 @@ async def test_setup_with_location_entity_auto_station( {ATTR_LATITUDE: 40.0, ATTR_LONGITUDE: -80.0}, ) - config_entry = MockConfigEntry(domain=DOMAIN, data=location_entity_config["config"]) + config_entry = MockConfigEntry( + domain=DOMAIN, data=location_entity_config["config"], version=2 + ) config_entry.add_to_hass(hass) await hass.config_entries.async_setup(config_entry.entry_id) @@ -106,7 +118,9 @@ async def test_setup_with_location_entity_unavailable( hass: HomeAssistant, mock_simple_nws, location_entity_config: dict ) -> None: """Test setup raises ConfigEntryNotReady when entity is unavailable.""" - config_entry = MockConfigEntry(domain=DOMAIN, data=location_entity_config["config"]) + config_entry = MockConfigEntry( + domain=DOMAIN, data=location_entity_config["config"], version=2 + ) config_entry.add_to_hass(hass) await hass.config_entries.async_setup(config_entry.entry_id) @@ -126,6 +140,7 @@ async def test_setup_with_location_entity_not_in_registry( CONF_API_KEY: "test", CONF_LOCATION_ENTITY: "nonexistent_registry_id", }, + version=2, ) config_entry.add_to_hass(hass) @@ -152,6 +167,7 @@ async def test_setup_with_location_entity_disabled( CONF_API_KEY: "test", CONF_LOCATION_ENTITY: entry.id, }, + version=2, ) config_entry.add_to_hass(hass) @@ -173,7 +189,9 @@ async def test_location_change_updates_coordinates( {ATTR_LATITUDE: 40.0, ATTR_LONGITUDE: -80.0}, ) - config_entry = MockConfigEntry(domain=DOMAIN, data=location_entity_config["config"]) + config_entry = MockConfigEntry( + domain=DOMAIN, data=location_entity_config["config"], version=2 + ) config_entry.add_to_hass(hass) await hass.config_entries.async_setup(config_entry.entry_id) @@ -216,7 +234,9 @@ async def test_location_change_does_not_log_coordinates( {ATTR_LATITUDE: 40.0, ATTR_LONGITUDE: -80.0}, ) - config_entry = MockConfigEntry(domain=DOMAIN, data=location_entity_config["config"]) + config_entry = MockConfigEntry( + domain=DOMAIN, data=location_entity_config["config"], version=2 + ) config_entry.add_to_hass(hass) await hass.config_entries.async_setup(config_entry.entry_id) @@ -246,7 +266,9 @@ async def test_location_change_resets_api_success_time( {ATTR_LATITUDE: 40.0, ATTR_LONGITUDE: -80.0}, ) - config_entry = MockConfigEntry(domain=DOMAIN, data=location_entity_config["config"]) + config_entry = MockConfigEntry( + domain=DOMAIN, data=location_entity_config["config"], version=2 + ) config_entry.add_to_hass(hass) await hass.config_entries.async_setup(config_entry.entry_id) @@ -291,7 +313,9 @@ async def test_no_update_without_significant_move( {ATTR_LATITUDE: 40.0, ATTR_LONGITUDE: -80.0}, ) - config_entry = MockConfigEntry(domain=DOMAIN, data=location_entity_config["config"]) + config_entry = MockConfigEntry( + domain=DOMAIN, data=location_entity_config["config"], version=2 + ) config_entry.add_to_hass(hass) await hass.config_entries.async_setup(config_entry.entry_id) @@ -325,7 +349,9 @@ async def test_listener_filters_jitter( {ATTR_LATITUDE: 40.0, ATTR_LONGITUDE: -80.0}, ) - config_entry = MockConfigEntry(domain=DOMAIN, data=location_entity_config["config"]) + config_entry = MockConfigEntry( + domain=DOMAIN, data=location_entity_config["config"], version=2 + ) config_entry.add_to_hass(hass) await hass.config_entries.async_setup(config_entry.entry_id) @@ -356,7 +382,9 @@ async def test_location_entity_becomes_unavailable_no_update( {ATTR_LATITUDE: 40.0, ATTR_LONGITUDE: -80.0}, ) - config_entry = MockConfigEntry(domain=DOMAIN, data=location_entity_config["config"]) + config_entry = MockConfigEntry( + domain=DOMAIN, data=location_entity_config["config"], version=2 + ) config_entry.add_to_hass(hass) await hass.config_entries.async_setup(config_entry.entry_id) @@ -385,6 +413,7 @@ async def _setup_tracked_entity( config_entry = MockConfigEntry( domain=DOMAIN, data={CONF_API_KEY: "test", CONF_LOCATION_ENTITY: entry.id}, + version=2, ) config_entry.add_to_hass(hass) @@ -436,7 +465,9 @@ async def test_unload_with_location_entity( {ATTR_LATITUDE: 40.0, ATTR_LONGITUDE: -80.0}, ) - config_entry = MockConfigEntry(domain=DOMAIN, data=location_entity_config["config"]) + config_entry = MockConfigEntry( + domain=DOMAIN, data=location_entity_config["config"], version=2 + ) config_entry.add_to_hass(hass) await hass.config_entries.async_setup(config_entry.entry_id) @@ -448,3 +479,26 @@ async def test_unload_with_location_entity( await hass.async_block_till_done() assert config_entry.state is ConfigEntryState.NOT_LOADED + + +async def test_migrate_entry(hass: HomeAssistant, mock_simple_nws) -> None: + """Test entry migration.""" + entry = MockConfigEntry( + domain=DOMAIN, + data={ + CONF_API_KEY: "test", + CONF_LATITUDE: 35, + CONF_LONGITUDE: -75, + CONF_STATION: "ABC", + }, + version=1, + ) + entry.add_to_hass(hass) + + await hass.config_entries.async_setup(entry.entry_id) + await hass.async_block_till_done() + + assert entry.state is ConfigEntryState.LOADED + + assert entry.version == 2 + assert entry.data == NWS_CONFIG diff --git a/tests/components/nws/test_sensor.py b/tests/components/nws/test_sensor.py index 3f503725a308..a4af4877cc18 100644 --- a/tests/components/nws/test_sensor.py +++ b/tests/components/nws/test_sensor.py @@ -62,6 +62,7 @@ async def test_imperial_metric( entry = MockConfigEntry( domain=DOMAIN, data=NWS_CONFIG, + version=2, ) entry.add_to_hass(hass) await hass.config_entries.async_setup(entry.entry_id) @@ -112,6 +113,7 @@ async def test_pressure_sensors_use_atmospheric_pressure( entry = MockConfigEntry( domain=DOMAIN, data=NWS_CONFIG, + version=2, ) entry.add_to_hass(hass) await hass.config_entries.async_setup(entry.entry_id) @@ -152,6 +154,7 @@ async def test_none_values( entry = MockConfigEntry( domain=DOMAIN, data=NWS_CONFIG, + version=2, ) entry.add_to_hass(hass) await hass.config_entries.async_setup(entry.entry_id) diff --git a/tests/components/nws/test_weather.py b/tests/components/nws/test_weather.py index 756b8f84190d..626df0245aa7 100644 --- a/tests/components/nws/test_weather.py +++ b/tests/components/nws/test_weather.py @@ -67,6 +67,7 @@ async def test_imperial_metric( entry = MockConfigEntry( domain=nws.DOMAIN, data=NWS_CONFIG, + version=2, ) entry.add_to_hass(hass) await hass.config_entries.async_setup(entry.entry_id) @@ -90,6 +91,7 @@ async def test_night_clear(hass: HomeAssistant, mock_simple_nws, no_sensor) -> N entry = MockConfigEntry( domain=nws.DOMAIN, data=NWS_CONFIG, + version=2, ) entry.add_to_hass(hass) await hass.config_entries.async_setup(entry.entry_id) @@ -108,6 +110,7 @@ async def test_none_values(hass: HomeAssistant, mock_simple_nws, no_sensor) -> N entry = MockConfigEntry( domain=nws.DOMAIN, data=NWS_CONFIG, + version=2, ) entry.add_to_hass(hass) await hass.config_entries.async_setup(entry.entry_id) @@ -133,6 +136,7 @@ async def test_data_caching_error_observation( entry = MockConfigEntry( domain=nws.DOMAIN, data=NWS_CONFIG, + version=2, ) entry.add_to_hass(hass) await hass.config_entries.async_setup(entry.entry_id) @@ -177,6 +181,7 @@ async def test_no_data_error_observation( entry = MockConfigEntry( domain=nws.DOMAIN, data=NWS_CONFIG, + version=2, ) entry.add_to_hass(hass) await hass.config_entries.async_setup(entry.entry_id) @@ -195,6 +200,7 @@ async def test_no_data_error_forecast( entry = MockConfigEntry( domain=nws.DOMAIN, data=NWS_CONFIG, + version=2, ) entry.add_to_hass(hass) await hass.config_entries.async_setup(entry.entry_id) @@ -215,6 +221,7 @@ async def test_no_data_error_forecast_hourly( entry = MockConfigEntry( domain=nws.DOMAIN, data=NWS_CONFIG, + version=2, ) entry.add_to_hass(hass) await hass.config_entries.async_setup(entry.entry_id) @@ -235,6 +242,7 @@ async def test_none(hass: HomeAssistant, mock_simple_nws, no_sensor) -> None: entry = MockConfigEntry( domain=nws.DOMAIN, data=NWS_CONFIG, + version=2, ) entry.add_to_hass(hass) await hass.config_entries.async_setup(entry.entry_id) @@ -275,6 +283,7 @@ async def test_entity_refresh(hass: HomeAssistant, mock_simple_nws, no_sensor) - entry = MockConfigEntry( domain=nws.DOMAIN, data=NWS_CONFIG, + version=2, ) entry.add_to_hass(hass) await hass.config_entries.async_setup(entry.entry_id) @@ -306,6 +315,7 @@ async def test_error_observation( entry = MockConfigEntry( domain=nws.DOMAIN, data=NWS_CONFIG, + version=2, ) entry.add_to_hass(hass) await hass.config_entries.async_setup(entry.entry_id) @@ -325,6 +335,7 @@ async def test_new_config_entry( entry = MockConfigEntry( domain=nws.DOMAIN, data=NWS_CONFIG, + version=2, ) entry.add_to_hass(hass) @@ -356,6 +367,7 @@ async def test_forecast_service( entry = MockConfigEntry( domain=nws.DOMAIN, data=NWS_CONFIG, + version=2, ) entry.add_to_hass(hass) @@ -475,6 +487,7 @@ async def test_forecast_subscription( entry = MockConfigEntry( domain=nws.DOMAIN, data=NWS_CONFIG, + version=2, ) entry.add_to_hass(hass) @@ -579,6 +592,7 @@ async def test_detailed_forecast_service( entry = MockConfigEntry( domain=nws.DOMAIN, data=NWS_CONFIG, + version=2, ) entry.add_to_hass(hass) @@ -620,6 +634,7 @@ async def test_detailed_forecast_service_no_data( entry = MockConfigEntry( domain=nws.DOMAIN, data=NWS_CONFIG, + version=2, ) entry.add_to_hass(hass)