mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 16:57:53 +00:00
Remove deprecated yaml config from environment canada (#61839)
This commit is contained in:
parent
867cbeedb9
commit
4e2195baa1
@ -5,7 +5,6 @@ import xml.etree.ElementTree as et
|
||||
|
||||
from env_canada import ECRadar, ECWeather, ec_exc
|
||||
|
||||
from homeassistant.config_entries import SOURCE_IMPORT
|
||||
from homeassistant.const import CONF_LATITUDE, CONF_LONGITUDE, Platform
|
||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
|
||||
|
||||
@ -63,32 +62,6 @@ async def async_unload_entry(hass, config_entry):
|
||||
return unload_ok
|
||||
|
||||
|
||||
def trigger_import(hass, config):
|
||||
"""Trigger a import of YAML config into a config_entry."""
|
||||
_LOGGER.warning(
|
||||
"Environment Canada YAML configuration is deprecated; your YAML configuration "
|
||||
"has been imported into the UI and can be safely removed"
|
||||
)
|
||||
if not config.get(CONF_LANGUAGE):
|
||||
config[CONF_LANGUAGE] = "English"
|
||||
|
||||
data = {}
|
||||
for key in (
|
||||
CONF_STATION,
|
||||
CONF_LATITUDE,
|
||||
CONF_LONGITUDE,
|
||||
CONF_LANGUAGE,
|
||||
):
|
||||
if config.get(key):
|
||||
data[key] = config[key]
|
||||
|
||||
hass.async_create_task(
|
||||
hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": SOURCE_IMPORT}, data=data
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
class ECDataUpdateCoordinator(DataUpdateCoordinator):
|
||||
"""Class to manage fetching EC data."""
|
||||
|
||||
|
@ -1,40 +1,10 @@
|
||||
"""Support for the Environment Canada radar imagery."""
|
||||
from __future__ import annotations
|
||||
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.camera import PLATFORM_SCHEMA, Camera
|
||||
from homeassistant.const import CONF_LATITUDE, CONF_LONGITUDE, CONF_NAME
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.components.camera import Camera
|
||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||
|
||||
from . import trigger_import
|
||||
from .const import ATTR_OBSERVATION_TIME, CONF_STATION, DOMAIN
|
||||
|
||||
CONF_LOOP = "loop"
|
||||
CONF_PRECIP_TYPE = "precip_type"
|
||||
|
||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
||||
{
|
||||
vol.Optional(CONF_LOOP, default=True): cv.boolean,
|
||||
vol.Optional(CONF_NAME): cv.string,
|
||||
vol.Optional(CONF_STATION): cv.matches_regex(r"^C[A-Z]{4}$|^[A-Z]{3}$"),
|
||||
vol.Inclusive(CONF_LATITUDE, "latlon"): cv.latitude,
|
||||
vol.Inclusive(CONF_LONGITUDE, "latlon"): cv.longitude,
|
||||
vol.Optional(CONF_PRECIP_TYPE): vol.In(["RAIN", "SNOW"]),
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
|
||||
"""Set up the Environment Canada camera."""
|
||||
lat = config.get(CONF_LATITUDE, hass.config.latitude)
|
||||
lon = config.get(CONF_LONGITUDE, hass.config.longitude)
|
||||
|
||||
config[CONF_LATITUDE] = lat
|
||||
config[CONF_LONGITUDE] = lon
|
||||
|
||||
trigger_import(hass, config)
|
||||
from .const import ATTR_OBSERVATION_TIME, DOMAIN
|
||||
|
||||
|
||||
async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||
|
@ -94,7 +94,3 @@ class EnvironmentCanadaConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
return self.async_show_form(
|
||||
step_id="user", data_schema=data_schema, errors=errors
|
||||
)
|
||||
|
||||
async def async_step_import(self, import_data):
|
||||
"""Import entry from configuration.yaml."""
|
||||
return await self.async_step_user(import_data)
|
||||
|
@ -4,28 +4,11 @@ import re
|
||||
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.sensor import (
|
||||
PLATFORM_SCHEMA,
|
||||
SensorDeviceClass,
|
||||
SensorEntity,
|
||||
)
|
||||
from homeassistant.const import (
|
||||
ATTR_LOCATION,
|
||||
CONF_LATITUDE,
|
||||
CONF_LONGITUDE,
|
||||
TEMP_CELSIUS,
|
||||
)
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.components.sensor import SensorDeviceClass, SensorEntity
|
||||
from homeassistant.const import ATTR_LOCATION, TEMP_CELSIUS
|
||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||
|
||||
from . import trigger_import
|
||||
from .const import (
|
||||
ATTR_OBSERVATION_TIME,
|
||||
ATTR_STATION,
|
||||
CONF_LANGUAGE,
|
||||
CONF_STATION,
|
||||
DOMAIN,
|
||||
)
|
||||
from .const import ATTR_OBSERVATION_TIME, ATTR_STATION, DOMAIN
|
||||
|
||||
ATTR_TIME = "alert time"
|
||||
|
||||
@ -41,21 +24,6 @@ def validate_station(station):
|
||||
return station
|
||||
|
||||
|
||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
||||
{
|
||||
vol.Required(CONF_LANGUAGE, default="english"): vol.In(["english", "french"]),
|
||||
vol.Optional(CONF_STATION): validate_station,
|
||||
vol.Inclusive(CONF_LATITUDE, "latlon"): cv.latitude,
|
||||
vol.Inclusive(CONF_LONGITUDE, "latlon"): cv.longitude,
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
|
||||
"""Set up the Environment Canada sensor."""
|
||||
trigger_import(hass, config)
|
||||
|
||||
|
||||
async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||
"""Add a weather entity from a config_entry."""
|
||||
coordinator = hass.data[DOMAIN][config_entry.entry_id]["weather_coordinator"]
|
||||
|
@ -24,18 +24,13 @@ from homeassistant.components.weather import (
|
||||
ATTR_FORECAST_TEMP,
|
||||
ATTR_FORECAST_TEMP_LOW,
|
||||
ATTR_FORECAST_TIME,
|
||||
PLATFORM_SCHEMA,
|
||||
WeatherEntity,
|
||||
)
|
||||
from homeassistant.const import CONF_LATITUDE, CONF_LONGITUDE, CONF_NAME, TEMP_CELSIUS
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.const import TEMP_CELSIUS
|
||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||
from homeassistant.util import dt
|
||||
|
||||
from . import trigger_import
|
||||
from .const import CONF_STATION, DOMAIN
|
||||
|
||||
CONF_FORECAST = "forecast"
|
||||
from .const import DOMAIN
|
||||
|
||||
|
||||
def validate_station(station):
|
||||
@ -47,16 +42,6 @@ def validate_station(station):
|
||||
return station
|
||||
|
||||
|
||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
||||
{
|
||||
vol.Optional(CONF_NAME): cv.string,
|
||||
vol.Optional(CONF_STATION): validate_station,
|
||||
vol.Inclusive(CONF_LATITUDE, "latlon"): cv.latitude,
|
||||
vol.Inclusive(CONF_LONGITUDE, "latlon"): cv.longitude,
|
||||
vol.Optional(CONF_FORECAST, default="daily"): vol.In(["daily", "hourly"]),
|
||||
}
|
||||
)
|
||||
|
||||
# Icon codes from http://dd.weatheroffice.ec.gc.ca/citypage_weather/
|
||||
# docs/current_conditions_icon_code_descriptions_e.csv
|
||||
ICON_CONDITION_MAP = {
|
||||
@ -75,11 +60,6 @@ ICON_CONDITION_MAP = {
|
||||
}
|
||||
|
||||
|
||||
async def async_setup_platform(hass, config, async_add_entries, discovery_info=None):
|
||||
"""Set up the Environment Canada weather."""
|
||||
trigger_import(hass, config)
|
||||
|
||||
|
||||
async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||
"""Add a weather entity from a config_entry."""
|
||||
coordinator = hass.data[DOMAIN][config_entry.entry_id]["weather_coordinator"]
|
||||
|
@ -11,7 +11,6 @@ from homeassistant.components.environment_canada.const import (
|
||||
CONF_STATION,
|
||||
DOMAIN,
|
||||
)
|
||||
from homeassistant.config_entries import SOURCE_IMPORT
|
||||
from homeassistant.const import CONF_LATITUDE, CONF_LONGITUDE
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
@ -123,25 +122,8 @@ async def test_exception_handling(hass, error):
|
||||
assert result["errors"] == {"base": base_error}
|
||||
|
||||
|
||||
async def test_import_station_not_specified(hass):
|
||||
"""Test that the import step works."""
|
||||
with mocked_ec(), patch(
|
||||
"homeassistant.components.environment_canada.async_setup_entry",
|
||||
return_value=True,
|
||||
):
|
||||
fake_config = dict(FAKE_CONFIG)
|
||||
del fake_config[CONF_STATION]
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": SOURCE_IMPORT}, data=fake_config
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
|
||||
assert result["data"] == FAKE_CONFIG
|
||||
assert result["title"] == FAKE_TITLE
|
||||
|
||||
|
||||
async def test_import_lat_lon_not_specified(hass):
|
||||
"""Test that the import step works."""
|
||||
async def test_lat_lon_not_specified(hass):
|
||||
"""Test that the import step works when coordinates are not specified."""
|
||||
with mocked_ec(), patch(
|
||||
"homeassistant.components.environment_canada.async_setup_entry",
|
||||
return_value=True,
|
||||
@ -150,29 +132,9 @@ async def test_import_lat_lon_not_specified(hass):
|
||||
del fake_config[CONF_LATITUDE]
|
||||
del fake_config[CONF_LONGITUDE]
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": SOURCE_IMPORT}, data=fake_config
|
||||
DOMAIN, context={"source": config_entries.SOURCE_USER}, data=fake_config
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
|
||||
assert result["data"] == FAKE_CONFIG
|
||||
assert result["title"] == FAKE_TITLE
|
||||
|
||||
|
||||
async def test_async_step_import(hass):
|
||||
"""Test that the import step works."""
|
||||
with mocked_ec(), patch(
|
||||
"homeassistant.components.environment_canada.async_setup_entry",
|
||||
return_value=True,
|
||||
):
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": SOURCE_IMPORT}, data=FAKE_CONFIG
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
|
||||
assert result["data"] == FAKE_CONFIG
|
||||
assert result["title"] == FAKE_TITLE
|
||||
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": SOURCE_IMPORT}, data=FAKE_CONFIG
|
||||
)
|
||||
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
|
||||
|
Loading…
x
Reference in New Issue
Block a user