mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 16:57:53 +00:00
Remove deprecated YAML configuration from Buienradar (#52939)
This commit is contained in:
parent
db97fd3d5b
commit
a5cdc0157b
@ -1,46 +1,17 @@
|
||||
"""The buienradar integration."""
|
||||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
|
||||
from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry
|
||||
from homeassistant.const import CONF_LATITUDE, CONF_LONGITUDE, CONF_NAME
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import entity_registry
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
|
||||
from .const import (
|
||||
CONF_COUNTRY,
|
||||
CONF_DELTA,
|
||||
CONF_DIMENSION,
|
||||
CONF_TIMEFRAME,
|
||||
DEFAULT_COUNTRY,
|
||||
DEFAULT_DELTA,
|
||||
DEFAULT_DIMENSION,
|
||||
DEFAULT_TIMEFRAME,
|
||||
DOMAIN,
|
||||
)
|
||||
from .const import DOMAIN
|
||||
|
||||
PLATFORMS = ["camera", "sensor", "weather"]
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||
"""Set up the buienradar component."""
|
||||
hass.data.setdefault(DOMAIN, {})
|
||||
|
||||
weather_configs = _filter_domain_configs(config, "weather", DOMAIN)
|
||||
sensor_configs = _filter_domain_configs(config, "sensor", DOMAIN)
|
||||
camera_configs = _filter_domain_configs(config, "camera", DOMAIN)
|
||||
|
||||
_import_configs(hass, weather_configs, sensor_configs, camera_configs)
|
||||
|
||||
return True
|
||||
|
||||
|
||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
"""Set up buienradar from a config entry."""
|
||||
hass.data.setdefault(DOMAIN, {})
|
||||
hass.config_entries.async_setup_platforms(entry, PLATFORMS)
|
||||
entry.async_on_unload(entry.add_update_listener(async_update_options))
|
||||
return True
|
||||
@ -56,86 +27,3 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
async def async_update_options(hass: HomeAssistant, config_entry: ConfigEntry) -> None:
|
||||
"""Update options."""
|
||||
await hass.config_entries.async_reload(config_entry.entry_id)
|
||||
|
||||
|
||||
def _import_configs(
|
||||
hass: HomeAssistant,
|
||||
weather_configs: list[ConfigType],
|
||||
sensor_configs: list[ConfigType],
|
||||
camera_configs: list[ConfigType],
|
||||
) -> None:
|
||||
camera_config = {}
|
||||
if camera_configs:
|
||||
camera_config = camera_configs[0]
|
||||
|
||||
for config in sensor_configs:
|
||||
# Remove weather configurations which share lat/lon with sensor configurations
|
||||
matching_weather_config = None
|
||||
latitude = config.get(CONF_LATITUDE, hass.config.latitude)
|
||||
longitude = config.get(CONF_LONGITUDE, hass.config.longitude)
|
||||
for weather_config in weather_configs:
|
||||
weather_latitude = config.get(CONF_LATITUDE, hass.config.latitude)
|
||||
weather_longitude = config.get(CONF_LONGITUDE, hass.config.longitude)
|
||||
if latitude == weather_latitude and longitude == weather_longitude:
|
||||
matching_weather_config = weather_config
|
||||
break
|
||||
|
||||
if matching_weather_config is not None:
|
||||
weather_configs.remove(matching_weather_config)
|
||||
|
||||
configs = weather_configs + sensor_configs
|
||||
|
||||
if not configs and camera_configs:
|
||||
config = {
|
||||
CONF_LATITUDE: hass.config.latitude,
|
||||
CONF_LONGITUDE: hass.config.longitude,
|
||||
}
|
||||
configs.append(config)
|
||||
|
||||
if configs:
|
||||
_try_update_unique_id(hass, configs[0], camera_config)
|
||||
|
||||
for config in configs:
|
||||
data = {
|
||||
CONF_LATITUDE: config.get(CONF_LATITUDE, hass.config.latitude),
|
||||
CONF_LONGITUDE: config.get(CONF_LONGITUDE, hass.config.longitude),
|
||||
CONF_TIMEFRAME: config.get(CONF_TIMEFRAME, DEFAULT_TIMEFRAME),
|
||||
CONF_COUNTRY: camera_config.get(CONF_COUNTRY, DEFAULT_COUNTRY),
|
||||
CONF_DELTA: camera_config.get(CONF_DELTA, DEFAULT_DELTA),
|
||||
CONF_NAME: config.get(CONF_NAME, "Buienradar"),
|
||||
}
|
||||
|
||||
hass.async_create_task(
|
||||
hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": SOURCE_IMPORT},
|
||||
data=data,
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
def _try_update_unique_id(
|
||||
hass: HomeAssistant, config: ConfigType, camera_config: ConfigType
|
||||
) -> None:
|
||||
dimension = camera_config.get(CONF_DIMENSION, DEFAULT_DIMENSION)
|
||||
country = camera_config.get(CONF_COUNTRY, DEFAULT_COUNTRY)
|
||||
|
||||
registry = entity_registry.async_get(hass)
|
||||
entity_id = registry.async_get_entity_id("camera", DOMAIN, f"{dimension}_{country}")
|
||||
|
||||
if entity_id is not None:
|
||||
latitude = config[CONF_LATITUDE]
|
||||
longitude = config[CONF_LONGITUDE]
|
||||
|
||||
new_unique_id = f"{latitude:2.6f}{longitude:2.6f}"
|
||||
registry.async_update_entity(entity_id, new_unique_id=new_unique_id)
|
||||
|
||||
|
||||
def _filter_domain_configs(
|
||||
config: ConfigType, domain: str, platform: str
|
||||
) -> list[ConfigType]:
|
||||
configs = []
|
||||
for entry in config:
|
||||
if entry.startswith(domain):
|
||||
configs += [x for x in config[entry] if x["platform"] == platform]
|
||||
return configs
|
||||
|
@ -8,11 +8,10 @@ import logging
|
||||
import aiohttp
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.camera import PLATFORM_SCHEMA, Camera
|
||||
from homeassistant.components.camera import Camera
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import CONF_LATITUDE, CONF_LONGITUDE, CONF_NAME
|
||||
from homeassistant.const import CONF_LATITUDE, CONF_LONGITUDE
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import config_validation as cv
|
||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.util import dt as dt_util
|
||||
@ -20,7 +19,6 @@ from homeassistant.util import dt as dt_util
|
||||
from .const import (
|
||||
CONF_COUNTRY,
|
||||
CONF_DELTA,
|
||||
CONF_DIMENSION,
|
||||
DEFAULT_COUNTRY,
|
||||
DEFAULT_DELTA,
|
||||
DEFAULT_DIMENSION,
|
||||
@ -34,26 +32,6 @@ DIM_RANGE = vol.All(vol.Coerce(int), vol.Range(min=120, max=700))
|
||||
# Multiple choice for available Radar Map URL
|
||||
SUPPORTED_COUNTRY_CODES = ["NL", "BE"]
|
||||
|
||||
PLATFORM_SCHEMA = vol.All(
|
||||
PLATFORM_SCHEMA.extend(
|
||||
{
|
||||
vol.Optional(CONF_DIMENSION, default=512): DIM_RANGE,
|
||||
vol.Optional(CONF_DELTA, default=600.0): cv.positive_float,
|
||||
vol.Optional(CONF_NAME, default="Buienradar loop"): cv.string,
|
||||
vol.Optional(CONF_COUNTRY, default="NL"): vol.All(
|
||||
vol.Coerce(str), vol.In(SUPPORTED_COUNTRY_CODES)
|
||||
),
|
||||
}
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
|
||||
"""Set up buienradar camera platform."""
|
||||
_LOGGER.warning(
|
||||
"Platform configuration is deprecated, will be removed in a future release"
|
||||
)
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
|
||||
|
@ -1,7 +1,6 @@
|
||||
"""Config flow for buienradar integration."""
|
||||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
from typing import Any
|
||||
|
||||
import voluptuous as vol
|
||||
@ -24,8 +23,6 @@ from .const import (
|
||||
SUPPORTED_COUNTRY_CODES,
|
||||
)
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class BuienradarFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
"""Handle a config flow for buienradar."""
|
||||
@ -70,18 +67,6 @@ class BuienradarFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
errors={},
|
||||
)
|
||||
|
||||
async def async_step_import(self, import_input: dict[str, Any]) -> FlowResult:
|
||||
"""Import a config entry."""
|
||||
latitude = import_input[CONF_LATITUDE]
|
||||
longitude = import_input[CONF_LONGITUDE]
|
||||
|
||||
await self.async_set_unique_id(f"{latitude}-{longitude}")
|
||||
self._abort_if_unique_id_configured()
|
||||
|
||||
return self.async_create_entry(
|
||||
title=f"{latitude},{longitude}", data=import_input
|
||||
)
|
||||
|
||||
|
||||
class BuienradarOptionFlowHandler(config_entries.OptionsFlow):
|
||||
"""Handle options."""
|
||||
|
@ -7,15 +7,10 @@ DEFAULT_TIMEFRAME = 60
|
||||
DEFAULT_DIMENSION = 700
|
||||
DEFAULT_DELTA = 600
|
||||
|
||||
CONF_DIMENSION = "dimension"
|
||||
CONF_DELTA = "delta"
|
||||
CONF_COUNTRY = "country_code"
|
||||
CONF_TIMEFRAME = "timeframe"
|
||||
|
||||
"""Range according to the docs"""
|
||||
CAMERA_DIM_MIN = 120
|
||||
CAMERA_DIM_MAX = 700
|
||||
|
||||
SUPPORTED_COUNTRY_CODES = ["NL", "BE"]
|
||||
DEFAULT_COUNTRY = "NL"
|
||||
|
||||
|
@ -18,15 +18,13 @@ from buienradar.constants import (
|
||||
WINDGUST,
|
||||
WINDSPEED,
|
||||
)
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity
|
||||
from homeassistant.components.sensor import SensorEntity
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import (
|
||||
ATTR_ATTRIBUTION,
|
||||
CONF_LATITUDE,
|
||||
CONF_LONGITUDE,
|
||||
CONF_MONITORED_CONDITIONS,
|
||||
CONF_NAME,
|
||||
DEGREE,
|
||||
DEVICE_CLASS_TEMPERATURE,
|
||||
@ -40,7 +38,6 @@ from homeassistant.const import (
|
||||
TEMP_CELSIUS,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.util import dt as dt_util
|
||||
|
||||
@ -317,31 +314,6 @@ SENSOR_TYPES = {
|
||||
"symbol_5d": ["Symbol 5d", None, None, None],
|
||||
}
|
||||
|
||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
||||
{
|
||||
vol.Optional(
|
||||
CONF_MONITORED_CONDITIONS, default=["symbol", "temperature"]
|
||||
): vol.All(cv.ensure_list, vol.Length(min=1), [vol.In(SENSOR_TYPES.keys())]),
|
||||
vol.Inclusive(
|
||||
CONF_LATITUDE, "coordinates", "Latitude and longitude must exist together"
|
||||
): cv.latitude,
|
||||
vol.Inclusive(
|
||||
CONF_LONGITUDE, "coordinates", "Latitude and longitude must exist together"
|
||||
): cv.longitude,
|
||||
vol.Optional(CONF_TIMEFRAME, default=DEFAULT_TIMEFRAME): vol.All(
|
||||
vol.Coerce(int), vol.Range(min=5, max=120)
|
||||
),
|
||||
vol.Optional(CONF_NAME, default="br"): cv.string,
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
|
||||
"""Set up buienradar sensor platform."""
|
||||
_LOGGER.warning(
|
||||
"Platform configuration is deprecated, will be removed in a future release"
|
||||
)
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
|
||||
|
@ -11,7 +11,6 @@ from buienradar.constants import (
|
||||
WINDAZIMUTH,
|
||||
WINDSPEED,
|
||||
)
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.weather import (
|
||||
ATTR_CONDITION_CLOUDY,
|
||||
@ -35,13 +34,11 @@ from homeassistant.components.weather import (
|
||||
ATTR_FORECAST_TIME,
|
||||
ATTR_FORECAST_WIND_BEARING,
|
||||
ATTR_FORECAST_WIND_SPEED,
|
||||
PLATFORM_SCHEMA,
|
||||
WeatherEntity,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import CONF_LATITUDE, CONF_LONGITUDE, CONF_NAME, TEMP_CELSIUS
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import config_validation as cv
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
# Reuse data and API logic from the sensor implementation
|
||||
@ -76,22 +73,6 @@ CONDITION_CLASSES = {
|
||||
ATTR_CONDITION_EXCEPTIONAL: (),
|
||||
}
|
||||
|
||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
||||
{
|
||||
vol.Optional(CONF_NAME): cv.string,
|
||||
vol.Optional(CONF_LATITUDE): cv.latitude,
|
||||
vol.Optional(CONF_LONGITUDE): cv.longitude,
|
||||
vol.Optional(CONF_FORECAST, default=True): cv.boolean,
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
|
||||
"""Set up buienradar weather platform."""
|
||||
_LOGGER.warning(
|
||||
"Platform configuration is deprecated, will be removed in a future release"
|
||||
)
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
|
||||
|
@ -66,34 +66,6 @@ async def test_config_flow_already_configured_weather(hass):
|
||||
assert result["reason"] == "already_configured"
|
||||
|
||||
|
||||
async def test_import_camera(hass):
|
||||
"""Test import of camera."""
|
||||
with patch(
|
||||
"homeassistant.components.buienradar.async_setup_entry", return_value=True
|
||||
):
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": config_entries.SOURCE_IMPORT},
|
||||
data={CONF_LATITUDE: TEST_LATITUDE, CONF_LONGITUDE: TEST_LONGITUDE},
|
||||
)
|
||||
|
||||
assert result["type"] == "create_entry"
|
||||
assert result["title"] == f"{TEST_LATITUDE},{TEST_LONGITUDE}"
|
||||
assert result["data"] == {
|
||||
CONF_LATITUDE: TEST_LATITUDE,
|
||||
CONF_LONGITUDE: TEST_LONGITUDE,
|
||||
}
|
||||
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": config_entries.SOURCE_IMPORT},
|
||||
data={CONF_LATITUDE: TEST_LATITUDE, CONF_LONGITUDE: TEST_LONGITUDE},
|
||||
)
|
||||
|
||||
assert result["type"] == "abort"
|
||||
assert result["reason"] == "already_configured"
|
||||
|
||||
|
||||
async def test_options_flow(hass):
|
||||
"""Test options flow."""
|
||||
entry = MockConfigEntry(
|
||||
|
@ -1,11 +1,7 @@
|
||||
"""Tests for the buienradar component."""
|
||||
from unittest.mock import patch
|
||||
|
||||
from homeassistant import setup
|
||||
from homeassistant.components.buienradar.const import DOMAIN
|
||||
from homeassistant.config_entries import ConfigEntryState
|
||||
from homeassistant.const import CONF_LATITUDE, CONF_LONGITUDE
|
||||
from homeassistant.helpers.entity_registry import async_get_registry
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
@ -13,91 +9,6 @@ TEST_LATITUDE = 51.5288504
|
||||
TEST_LONGITUDE = 5.4002156
|
||||
|
||||
|
||||
async def test_import_all(hass):
|
||||
"""Test import of all platforms."""
|
||||
config = {
|
||||
"weather 1": [{"platform": "buienradar", "name": "test1"}],
|
||||
"sensor 1": [{"platform": "buienradar", "timeframe": 30, "name": "test2"}],
|
||||
"camera 1": [
|
||||
{
|
||||
"platform": "buienradar",
|
||||
"country_code": "BE",
|
||||
"delta": 300,
|
||||
"name": "test3",
|
||||
}
|
||||
],
|
||||
}
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.buienradar.async_setup_entry", return_value=True
|
||||
):
|
||||
await setup.async_setup_component(hass, DOMAIN, config)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
conf_entries = hass.config_entries.async_entries(DOMAIN)
|
||||
|
||||
assert len(conf_entries) == 1
|
||||
|
||||
entry = conf_entries[0]
|
||||
|
||||
assert entry.state is ConfigEntryState.LOADED
|
||||
assert entry.data == {
|
||||
"latitude": hass.config.latitude,
|
||||
"longitude": hass.config.longitude,
|
||||
"timeframe": 30,
|
||||
"country_code": "BE",
|
||||
"delta": 300,
|
||||
"name": "test2",
|
||||
}
|
||||
|
||||
|
||||
async def test_import_camera(hass):
|
||||
"""Test import of camera platform."""
|
||||
entity_registry = await async_get_registry(hass)
|
||||
entity_registry.async_get_or_create(
|
||||
domain="camera",
|
||||
platform="buienradar",
|
||||
unique_id="512_NL",
|
||||
original_name="test_name",
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
config = {
|
||||
"camera 1": [{"platform": "buienradar", "country_code": "NL", "dimension": 512}]
|
||||
}
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.buienradar.async_setup_entry", return_value=True
|
||||
):
|
||||
await setup.async_setup_component(hass, DOMAIN, config)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
conf_entries = hass.config_entries.async_entries(DOMAIN)
|
||||
|
||||
assert len(conf_entries) == 1
|
||||
|
||||
entry = conf_entries[0]
|
||||
|
||||
assert entry.state is ConfigEntryState.LOADED
|
||||
assert entry.data == {
|
||||
"latitude": hass.config.latitude,
|
||||
"longitude": hass.config.longitude,
|
||||
"timeframe": 60,
|
||||
"country_code": "NL",
|
||||
"delta": 600,
|
||||
"name": "Buienradar",
|
||||
}
|
||||
|
||||
entity_id = entity_registry.async_get_entity_id(
|
||||
"camera",
|
||||
"buienradar",
|
||||
f"{hass.config.latitude:2.6f}{hass.config.longitude:2.6f}",
|
||||
)
|
||||
assert entity_id
|
||||
entity = entity_registry.async_get(entity_id)
|
||||
assert entity.original_name == "test_name"
|
||||
|
||||
|
||||
async def test_load_unload(aioclient_mock, hass):
|
||||
"""Test options flow."""
|
||||
entry = MockConfigEntry(
|
||||
|
Loading…
x
Reference in New Issue
Block a user