Remove deprecated YAML configuration from Luftdaten (#61748)

This commit is contained in:
Franck Nijhof 2021-12-14 09:21:12 +01:00 committed by GitHub
parent 4a1f49852a
commit de45144750
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 9 additions and 123 deletions

View File

@ -5,7 +5,6 @@ import logging
from luftdaten import Luftdaten from luftdaten import Luftdaten
from luftdaten.exceptions import LuftdatenError from luftdaten.exceptions import LuftdatenError
import voluptuous as vol
from homeassistant.components.sensor import SensorDeviceClass, SensorEntityDescription from homeassistant.components.sensor import SensorDeviceClass, SensorEntityDescription
from homeassistant.config_entries import SOURCE_IMPORT from homeassistant.config_entries import SOURCE_IMPORT
@ -14,7 +13,6 @@ from homeassistant.const import (
CONF_MONITORED_CONDITIONS, CONF_MONITORED_CONDITIONS,
CONF_SCAN_INTERVAL, CONF_SCAN_INTERVAL,
CONF_SENSORS, CONF_SENSORS,
CONF_SHOW_ON_MAP,
PERCENTAGE, PERCENTAGE,
PRESSURE_PA, PRESSURE_PA,
TEMP_CELSIUS, TEMP_CELSIUS,
@ -26,7 +24,7 @@ import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.dispatcher import async_dispatcher_send from homeassistant.helpers.dispatcher import async_dispatcher_send
from homeassistant.helpers.event import async_track_time_interval from homeassistant.helpers.event import async_track_time_interval
from .config_flow import configured_sensors, duplicate_stations from .config_flow import duplicate_stations
from .const import CONF_SENSOR_ID, DEFAULT_SCAN_INTERVAL, DOMAIN from .const import CONF_SENSOR_ID, DEFAULT_SCAN_INTERVAL, DOMAIN
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
@ -90,32 +88,7 @@ SENSOR_TYPES: tuple[SensorEntityDescription, ...] = (
) )
SENSOR_KEYS: list[str] = [desc.key for desc in SENSOR_TYPES] SENSOR_KEYS: list[str] = [desc.key for desc in SENSOR_TYPES]
SENSOR_SCHEMA = vol.Schema( CONFIG_SCHEMA = cv.removed(DOMAIN, raise_if_present=False)
{
vol.Optional(CONF_MONITORED_CONDITIONS, default=SENSOR_KEYS): vol.All(
cv.ensure_list, [vol.In(SENSOR_KEYS)]
)
}
)
CONFIG_SCHEMA = vol.Schema(
vol.All(
cv.deprecated(DOMAIN),
{
DOMAIN: vol.Schema(
{
vol.Required(CONF_SENSOR_ID): cv.positive_int,
vol.Optional(CONF_SENSORS, default={}): SENSOR_SCHEMA,
vol.Optional(CONF_SHOW_ON_MAP, default=False): cv.boolean,
vol.Optional(
CONF_SCAN_INTERVAL, default=DEFAULT_SCAN_INTERVAL
): cv.time_period,
}
)
},
),
extra=vol.ALLOW_EXTRA,
)
@callback @callback
@ -125,38 +98,15 @@ def _async_fixup_sensor_id(hass, config_entry, sensor_id):
) )
async def async_setup(hass, config):
"""Set up the Luftdaten component."""
hass.data[DOMAIN] = {}
hass.data[DOMAIN][DATA_LUFTDATEN_CLIENT] = {}
hass.data[DOMAIN][DATA_LUFTDATEN_LISTENER] = {}
if DOMAIN not in config:
return True
conf = config[DOMAIN]
station_id = conf[CONF_SENSOR_ID]
if station_id not in configured_sensors(hass):
hass.async_create_task(
hass.config_entries.flow.async_init(
DOMAIN,
context={"source": SOURCE_IMPORT},
data={
CONF_SENSORS: conf[CONF_SENSORS],
CONF_SENSOR_ID: conf[CONF_SENSOR_ID],
CONF_SHOW_ON_MAP: conf[CONF_SHOW_ON_MAP],
},
)
)
hass.data[DOMAIN][CONF_SCAN_INTERVAL] = conf[CONF_SCAN_INTERVAL]
return True
async def async_setup_entry(hass, config_entry): async def async_setup_entry(hass, config_entry):
"""Set up Luftdaten as config entry.""" """Set up Luftdaten as config entry."""
hass.data.setdefault(
DOMAIN,
{
DATA_LUFTDATEN_CLIENT: {},
DATA_LUFTDATEN_LISTENER: {},
},
)
if not isinstance(config_entry.data[CONF_SENSOR_ID], int): if not isinstance(config_entry.data[CONF_SENSOR_ID], int):
_async_fixup_sensor_id(hass, config_entry, config_entry.data[CONF_SENSOR_ID]) _async_fixup_sensor_id(hass, config_entry, config_entry.data[CONF_SENSOR_ID])

View File

@ -53,10 +53,6 @@ class LuftDatenFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
step_id="user", data_schema=vol.Schema(data_schema), errors=errors or {} step_id="user", data_schema=vol.Schema(data_schema), errors=errors or {}
) )
async def async_step_import(self, import_config):
"""Import a config entry from configuration.yaml."""
return await self.async_step_user(import_config)
async def async_step_user(self, user_input=None): async def async_step_user(self, user_input=None):
"""Handle the start of the config flow.""" """Handle the start of the config flow."""

View File

@ -59,27 +59,6 @@ async def test_show_form(hass):
assert result["step_id"] == "user" assert result["step_id"] == "user"
async def test_step_import(hass):
"""Test that the import step works."""
conf = {CONF_SENSOR_ID: "12345abcde", CONF_SHOW_ON_MAP: False}
flow = config_flow.LuftDatenFlowHandler()
flow.hass = hass
with patch("luftdaten.Luftdaten.get_data", return_value=True), patch(
"luftdaten.Luftdaten.validate_sensor", return_value=True
):
result = await flow.async_step_import(import_config=conf)
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
assert result["title"] == "12345abcde"
assert result["data"] == {
CONF_SENSOR_ID: "12345abcde",
CONF_SHOW_ON_MAP: False,
CONF_SCAN_INTERVAL: 600,
}
async def test_step_user(hass): async def test_step_user(hass):
"""Test that the user step works.""" """Test that the user step works."""
conf = { conf = {

View File

@ -1,39 +0,0 @@
"""Test the Luftdaten component setup."""
from unittest.mock import patch
from homeassistant.components import luftdaten
from homeassistant.components.luftdaten.const import CONF_SENSOR_ID, DOMAIN
from homeassistant.const import CONF_SCAN_INTERVAL, CONF_SHOW_ON_MAP
from homeassistant.setup import async_setup_component
async def test_config_with_sensor_passed_to_config_entry(hass):
"""Test that configured options for a sensor are loaded."""
conf = {
CONF_SENSOR_ID: "12345abcde",
CONF_SHOW_ON_MAP: False,
CONF_SCAN_INTERVAL: 600,
}
with patch.object(
hass.config_entries.flow, "async_init"
) as mock_config_entries, patch.object(
luftdaten, "configured_sensors", return_value=[]
):
assert await async_setup_component(hass, DOMAIN, conf) is True
assert len(mock_config_entries.flow.mock_calls) == 0
async def test_config_already_registered_not_passed_to_config_entry(hass):
"""Test that an already registered sensor does not initiate an import."""
conf = {CONF_SENSOR_ID: "12345abcde"}
with patch.object(
hass.config_entries.flow, "async_init"
) as mock_config_entries, patch.object(
luftdaten, "configured_sensors", return_value=["12345abcde"]
):
assert await async_setup_component(hass, DOMAIN, conf) is True
assert len(mock_config_entries.flow.mock_calls) == 0