mirror of
https://github.com/home-assistant/core.git
synced 2025-07-27 23:27:37 +00:00
Fix ADR 0003 issues in trafikverket_weatherstation (#60664)
* Fix ADR 0003 issues * Remove commented code
This commit is contained in:
parent
28ebd13d75
commit
51ebfade52
@ -1,6 +1,8 @@
|
|||||||
"""Adds config flow for Trafikverket Weather integration."""
|
"""Adds config flow for Trafikverket Weather integration."""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import json
|
||||||
|
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant import config_entries
|
from homeassistant import config_entries
|
||||||
@ -10,18 +12,13 @@ import homeassistant.helpers.config_validation as cv
|
|||||||
from .const import CONF_STATION, DOMAIN
|
from .const import CONF_STATION, DOMAIN
|
||||||
from .sensor import SENSOR_TYPES
|
from .sensor import SENSOR_TYPES
|
||||||
|
|
||||||
SENSOR_LIST: dict[str, str | None] = {
|
SENSOR_LIST: set[str] = {description.key for (description) in SENSOR_TYPES}
|
||||||
description.key: description.name for (description) in SENSOR_TYPES
|
|
||||||
}
|
|
||||||
|
|
||||||
DATA_SCHEMA = vol.Schema(
|
DATA_SCHEMA = vol.Schema(
|
||||||
{
|
{
|
||||||
vol.Required(CONF_NAME): cv.string,
|
vol.Required(CONF_NAME): cv.string,
|
||||||
vol.Required(CONF_API_KEY): cv.string,
|
vol.Required(CONF_API_KEY): cv.string,
|
||||||
vol.Required(CONF_STATION): 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]
|
name = user_input[CONF_NAME]
|
||||||
api_key = user_input[CONF_API_KEY]
|
api_key = user_input[CONF_API_KEY]
|
||||||
station = user_input[CONF_STATION]
|
station = user_input[CONF_STATION]
|
||||||
conditions = user_input[CONF_MONITORED_CONDITIONS]
|
conditions = json.dumps(list(SENSOR_LIST))
|
||||||
|
|
||||||
return self.async_create_entry(
|
return self.async_create_entry(
|
||||||
title=name,
|
title=name,
|
||||||
|
@ -1,12 +1,16 @@
|
|||||||
"""Test the Trafikverket weatherstation config flow."""
|
"""Test the Trafikverket weatherstation config flow."""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import json
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
from homeassistant import config_entries
|
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
|
from homeassistant.core import HomeAssistant
|
||||||
|
|
||||||
|
SENSOR_LIST: list[str | None] = {description.key for (description) in SENSOR_TYPES}
|
||||||
|
|
||||||
DOMAIN = "trafikverket_weatherstation"
|
DOMAIN = "trafikverket_weatherstation"
|
||||||
CONF_STATION = "station"
|
CONF_STATION = "station"
|
||||||
|
|
||||||
@ -30,7 +34,6 @@ async def test_form(hass: HomeAssistant) -> None:
|
|||||||
CONF_NAME: "Vallby Vasteras",
|
CONF_NAME: "Vallby Vasteras",
|
||||||
CONF_API_KEY: "1234567890",
|
CONF_API_KEY: "1234567890",
|
||||||
CONF_STATION: "Vallby",
|
CONF_STATION: "Vallby",
|
||||||
CONF_MONITORED_CONDITIONS: ["air_temp", "road_temp"],
|
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
@ -41,7 +44,7 @@ async def test_form(hass: HomeAssistant) -> None:
|
|||||||
"name": "Vallby Vasteras",
|
"name": "Vallby Vasteras",
|
||||||
"api_key": "1234567890",
|
"api_key": "1234567890",
|
||||||
"station": "Vallby",
|
"station": "Vallby",
|
||||||
"monitored_conditions": ["air_temp", "road_temp"],
|
"monitored_conditions": json.dumps(list(SENSOR_LIST)),
|
||||||
}
|
}
|
||||||
assert len(mock_setup_entry.mock_calls) == 1
|
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_NAME: "Vallby Vasteras",
|
||||||
CONF_API_KEY: "1234567890",
|
CONF_API_KEY: "1234567890",
|
||||||
CONF_STATION: "Vallby",
|
CONF_STATION: "Vallby",
|
||||||
CONF_MONITORED_CONDITIONS: ["air_temp", "road_temp"],
|
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
@ -71,6 +73,6 @@ async def test_import_flow_success(hass: HomeAssistant) -> None:
|
|||||||
"name": "Vallby Vasteras",
|
"name": "Vallby Vasteras",
|
||||||
"api_key": "1234567890",
|
"api_key": "1234567890",
|
||||||
"station": "Vallby",
|
"station": "Vallby",
|
||||||
"monitored_conditions": ["air_temp", "road_temp"],
|
"monitored_conditions": json.dumps(list(SENSOR_LIST)),
|
||||||
}
|
}
|
||||||
assert len(mock_setup_entry.mock_calls) == 1
|
assert len(mock_setup_entry.mock_calls) == 1
|
||||||
|
Loading…
x
Reference in New Issue
Block a user