Fix ADR 0003 issues in trafikverket_weatherstation (#60664)

* Fix ADR 0003 issues

* Remove commented code
This commit is contained in:
G Johansson 2021-11-30 22:54:10 +01:00 committed by GitHub
parent 28ebd13d75
commit 51ebfade52
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 12 deletions

View file

@ -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,

View file

@ -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