diff --git a/homeassistant/components/trafikverket_weatherstation/config_flow.py b/homeassistant/components/trafikverket_weatherstation/config_flow.py index 44b8b124264..f079852be93 100644 --- a/homeassistant/components/trafikverket_weatherstation/config_flow.py +++ b/homeassistant/components/trafikverket_weatherstation/config_flow.py @@ -1,6 +1,8 @@ """Adds config flow for Trafikverket Weather integration.""" from __future__ import annotations +import json + import voluptuous as vol from homeassistant import config_entries @@ -10,18 +12,13 @@ import homeassistant.helpers.config_validation as cv from .const import CONF_STATION, DOMAIN from .sensor import SENSOR_TYPES -SENSOR_LIST: dict[str, str | None] = { - description.key: description.name for (description) in SENSOR_TYPES -} +SENSOR_LIST: set[str] = {description.key for (description) in SENSOR_TYPES} DATA_SCHEMA = vol.Schema( { vol.Required(CONF_NAME): cv.string, vol.Required(CONF_API_KEY): cv.string, vol.Required(CONF_STATION): cv.string, - vol.Required(CONF_MONITORED_CONDITIONS, default=[]): cv.multi_select( - SENSOR_LIST - ), } ) @@ -51,7 +48,7 @@ class TVWeatherConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): name = user_input[CONF_NAME] api_key = user_input[CONF_API_KEY] station = user_input[CONF_STATION] - conditions = user_input[CONF_MONITORED_CONDITIONS] + conditions = json.dumps(list(SENSOR_LIST)) return self.async_create_entry( title=name, diff --git a/tests/components/trafikverket_weatherstation/test_config_flow.py b/tests/components/trafikverket_weatherstation/test_config_flow.py index f46dc73e031..ecbd84f0eb4 100644 --- a/tests/components/trafikverket_weatherstation/test_config_flow.py +++ b/tests/components/trafikverket_weatherstation/test_config_flow.py @@ -1,12 +1,16 @@ """Test the Trafikverket weatherstation config flow.""" from __future__ import annotations +import json from unittest.mock import patch from homeassistant import config_entries -from homeassistant.const import CONF_API_KEY, CONF_MONITORED_CONDITIONS, CONF_NAME +from homeassistant.components.trafikverket_weatherstation.sensor import SENSOR_TYPES +from homeassistant.const import CONF_API_KEY, CONF_NAME from homeassistant.core import HomeAssistant +SENSOR_LIST: list[str | None] = {description.key for (description) in SENSOR_TYPES} + DOMAIN = "trafikverket_weatherstation" CONF_STATION = "station" @@ -30,7 +34,6 @@ async def test_form(hass: HomeAssistant) -> None: CONF_NAME: "Vallby Vasteras", CONF_API_KEY: "1234567890", CONF_STATION: "Vallby", - CONF_MONITORED_CONDITIONS: ["air_temp", "road_temp"], }, ) await hass.async_block_till_done() @@ -41,7 +44,7 @@ async def test_form(hass: HomeAssistant) -> None: "name": "Vallby Vasteras", "api_key": "1234567890", "station": "Vallby", - "monitored_conditions": ["air_temp", "road_temp"], + "monitored_conditions": json.dumps(list(SENSOR_LIST)), } assert len(mock_setup_entry.mock_calls) == 1 @@ -60,7 +63,6 @@ async def test_import_flow_success(hass: HomeAssistant) -> None: CONF_NAME: "Vallby Vasteras", CONF_API_KEY: "1234567890", CONF_STATION: "Vallby", - CONF_MONITORED_CONDITIONS: ["air_temp", "road_temp"], }, ) await hass.async_block_till_done() @@ -71,6 +73,6 @@ async def test_import_flow_success(hass: HomeAssistant) -> None: "name": "Vallby Vasteras", "api_key": "1234567890", "station": "Vallby", - "monitored_conditions": ["air_temp", "road_temp"], + "monitored_conditions": json.dumps(list(SENSOR_LIST)), } assert len(mock_setup_entry.mock_calls) == 1