mirror of
https://github.com/home-assistant/core
synced 2024-08-31 05:57:13 +02:00
![Abílio Costa](/assets/img/avatar_default.png)
* update ipma component for pyipma 2.0 * fix wind speed; refactor forecast * update requirements*.txt * fix tests; update CODEOWNERS; update pyipma to 2.0.1 * minor changes as suggested in PR * make lint happy * fix mocking coroutines * restore old unique id * fix station lat/lon; update pyipma version * add hourly forecast option to IPMA * add forecast tests * use for instead of lambda
58 lines
2.0 KiB
Python
58 lines
2.0 KiB
Python
"""Config flow to configure IPMA component."""
|
|
import voluptuous as vol
|
|
|
|
from homeassistant import config_entries
|
|
from homeassistant.const import CONF_LATITUDE, CONF_LONGITUDE, CONF_MODE, CONF_NAME
|
|
import homeassistant.helpers.config_validation as cv
|
|
|
|
from .const import DOMAIN, HOME_LOCATION_NAME
|
|
from .weather import FORECAST_MODE
|
|
|
|
|
|
@config_entries.HANDLERS.register(DOMAIN)
|
|
class IpmaFlowHandler(config_entries.ConfigFlow):
|
|
"""Config flow for IPMA component."""
|
|
|
|
VERSION = 1
|
|
CONNECTION_CLASS = config_entries.CONN_CLASS_CLOUD_POLL
|
|
|
|
def __init__(self):
|
|
"""Init IpmaFlowHandler."""
|
|
self._errors = {}
|
|
|
|
async def async_step_user(self, user_input=None):
|
|
"""Handle a flow initialized by the user."""
|
|
self._errors = {}
|
|
|
|
if user_input is not None:
|
|
if user_input[CONF_NAME] not in self.hass.config_entries.async_entries(
|
|
DOMAIN
|
|
):
|
|
return self.async_create_entry(
|
|
title=user_input[CONF_NAME], data=user_input
|
|
)
|
|
|
|
self._errors[CONF_NAME] = "name_exists"
|
|
|
|
# default location is set hass configuration
|
|
return await self._show_config_form(
|
|
name=HOME_LOCATION_NAME,
|
|
latitude=self.hass.config.latitude,
|
|
longitude=self.hass.config.longitude,
|
|
)
|
|
|
|
async def _show_config_form(self, name=None, latitude=None, longitude=None):
|
|
"""Show the configuration form to edit location data."""
|
|
return self.async_show_form(
|
|
step_id="user",
|
|
data_schema=vol.Schema(
|
|
{
|
|
vol.Required(CONF_NAME, default=name): str,
|
|
vol.Required(CONF_LATITUDE, default=latitude): cv.latitude,
|
|
vol.Required(CONF_LONGITUDE, default=longitude): cv.longitude,
|
|
vol.Required(CONF_MODE, default="daily"): vol.In(FORECAST_MODE),
|
|
}
|
|
),
|
|
errors=self._errors,
|
|
)
|