Remove deprecated zamg YAML config (#86113)
This commit is contained in:
parent
1c2510bfb3
commit
cc74fcbda7
4 changed files with 8 additions and 268 deletions
|
@ -5,13 +5,11 @@ from typing import Any
|
|||
|
||||
import voluptuous as vol
|
||||
from zamg import ZamgData
|
||||
from zamg.exceptions import ZamgApiError, ZamgNoDataError, ZamgStationNotFoundError
|
||||
from zamg.exceptions import ZamgApiError, ZamgNoDataError
|
||||
|
||||
from homeassistant import config_entries
|
||||
from homeassistant.const import CONF_LATITUDE, CONF_LONGITUDE
|
||||
from homeassistant.data_entry_flow import FlowResult
|
||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||
from homeassistant.helpers.issue_registry import IssueSeverity, async_create_issue
|
||||
|
||||
from .const import CONF_STATION_ID, DOMAIN, LOGGER
|
||||
|
||||
|
@ -73,56 +71,3 @@ class ZamgConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||
title=self._client.get_station_name,
|
||||
data={CONF_STATION_ID: station_id},
|
||||
)
|
||||
|
||||
async def async_step_import(self, config: dict[str, Any]) -> FlowResult:
|
||||
"""Handle ZAMG configuration import."""
|
||||
station_id = config.get(CONF_STATION_ID)
|
||||
# create issue every time after restart
|
||||
# parameter is_persistent seems not working
|
||||
async_create_issue(
|
||||
self.hass,
|
||||
DOMAIN,
|
||||
"deprecated_yaml",
|
||||
breaks_in_ha_version="2023.1.0",
|
||||
is_fixable=False,
|
||||
severity=IssueSeverity.WARNING,
|
||||
translation_key="deprecated_yaml",
|
||||
)
|
||||
|
||||
if self._client is None:
|
||||
self._client = ZamgData()
|
||||
self._client.session = async_get_clientsession(self.hass)
|
||||
|
||||
try:
|
||||
if station_id not in await self._client.zamg_stations():
|
||||
LOGGER.warning(
|
||||
(
|
||||
"Configured station_id %s could not be found at zamg, trying to"
|
||||
" add nearest weather station instead"
|
||||
),
|
||||
station_id,
|
||||
)
|
||||
latitude = config.get(CONF_LATITUDE) or self.hass.config.latitude
|
||||
longitude = config.get(CONF_LONGITUDE) or self.hass.config.longitude
|
||||
station_id = await self._client.closest_station(latitude, longitude)
|
||||
|
||||
# Check if already configured
|
||||
await self.async_set_unique_id(station_id)
|
||||
self._abort_if_unique_id_configured()
|
||||
|
||||
LOGGER.debug(
|
||||
"importing zamg station from configuration.yaml: station_id = %s",
|
||||
station_id,
|
||||
)
|
||||
except (ZamgApiError) as err:
|
||||
LOGGER.error("Config_flow import: Received error from ZAMG: %s", err)
|
||||
return self.async_abort(reason="cannot_connect")
|
||||
except (ZamgStationNotFoundError) as err:
|
||||
LOGGER.error("Config_flow import: Received error from ZAMG: %s", err)
|
||||
return self.async_abort(reason="station_not_found")
|
||||
|
||||
return await self.async_step_user(
|
||||
user_input={
|
||||
CONF_STATION_ID: station_id,
|
||||
}
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue