-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove YAML config and setup UI config
- Loading branch information
Showing
8 changed files
with
267 additions
and
149 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,39 @@ | ||
"""Integration for IRM KMI weather""" | ||
|
||
from homeassistant.components.weather import Forecast | ||
class IrmKmiForecast(Forecast): | ||
"""Forecast class with additional attributes for IRM KMI""" | ||
text_fr: str | None | ||
text_nl: str | None | ||
# File inspired from https://github.com/ludeeus/integration_blueprint | ||
|
||
from homeassistant.config_entries import ConfigEntry | ||
from homeassistant.core import HomeAssistant | ||
from homeassistant.const import CONF_ZONE | ||
|
||
from .const import DOMAIN, PLATFORMS | ||
from .coordinator import IrmKmiCoordinator | ||
from .weather import IrmKmiWeather | ||
|
||
|
||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: | ||
"""Set up this integration using UI.""" | ||
hass.data.setdefault(DOMAIN, {}) | ||
|
||
hass.data[DOMAIN][entry.entry_id] = coordinator = IrmKmiCoordinator(hass, entry.data[CONF_ZONE]) | ||
|
||
# https://developers.home-assistant.io/docs/integration_fetching_data#coordinated-single-api-poll-for-data-for-all-entities | ||
await coordinator.async_config_entry_first_refresh() | ||
|
||
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS) | ||
entry.async_on_unload(entry.add_update_listener(async_reload_entry)) | ||
|
||
return True | ||
|
||
|
||
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: | ||
"""Handle removal of an entry.""" | ||
if unloaded := await hass.config_entries.async_unload_platforms(entry, PLATFORMS): | ||
hass.data[DOMAIN].pop(entry.entry_id) | ||
return unloaded | ||
|
||
|
||
async def async_reload_entry(hass: HomeAssistant, entry: ConfigEntry) -> None: | ||
"""Reload config entry.""" | ||
await async_unload_entry(hass, entry) | ||
await async_setup_entry(hass, entry) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import logging | ||
import voluptuous as vol | ||
|
||
from homeassistant.components.zone import DOMAIN as ZONE_DOMAIN | ||
from homeassistant.config_entries import ConfigFlow | ||
from homeassistant.const import CONF_ZONE | ||
from homeassistant.data_entry_flow import FlowResult | ||
from homeassistant.helpers.selector import EntitySelector, EntitySelectorConfig | ||
|
||
from .const import DOMAIN | ||
|
||
_LOGGER = logging.getLogger(__name__) | ||
|
||
|
||
class IrmKmiConfigFlow(ConfigFlow, domain=DOMAIN): | ||
VERSION = 1 | ||
|
||
async def async_step_user(self, user_input: dict | None = None) -> FlowResult: | ||
|
||
if user_input is not None: | ||
_LOGGER.debug(f"Provided config user is: {user_input}") | ||
|
||
await self.async_set_unique_id(user_input[CONF_ZONE]) | ||
self._abort_if_unique_id_configured() | ||
|
||
state = self.hass.states.get(user_input[CONF_ZONE]) | ||
return self.async_create_entry( | ||
title=state.name if state else "IRM KMI", | ||
data={CONF_ZONE: user_input[CONF_ZONE]}, | ||
) | ||
|
||
return self.async_show_form( | ||
step_id="user", | ||
data_schema=vol.Schema( | ||
{ | ||
vol.Required(CONF_ZONE): EntitySelector( | ||
EntitySelectorConfig(domain=ZONE_DOMAIN), | ||
), | ||
} | ||
), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.