-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
3,894 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import asyncio | ||
import logging | ||
|
||
from homeassistant import config_entries, core | ||
|
||
from .const import DOMAIN | ||
|
||
|
||
_LOGGER = logging.getLogger(__name__) | ||
|
||
|
||
async def async_setup_entry( | ||
hass: core.HomeAssistant, entry: config_entries.ConfigEntry | ||
) -> bool: | ||
"""Set up platform from a ConfigEntry.""" | ||
hass.data.setdefault(DOMAIN, {}) | ||
hass.data[DOMAIN][entry.entry_id] = entry.data | ||
|
||
# Forward the setup to the sensor platform. | ||
hass.async_create_task( | ||
hass.config_entries.async_forward_entry_setup(entry, "sensor") | ||
) | ||
return True | ||
|
||
|
||
async def async_setup(hass: core.HomeAssistant, config: dict) -> bool: | ||
hass.data.setdefault(DOMAIN, {}) | ||
return True | ||
|
||
|
||
async def async_unload_entry( | ||
hass: core.HomeAssistant, entry: config_entries.ConfigEntry | ||
) -> bool: | ||
"""Unload a config entry.""" | ||
unload_ok = all( | ||
await asyncio.gather( | ||
*[hass.config_entries.async_forward_entry_unload(entry, "sensor")] | ||
) | ||
) | ||
# Remove options_update_listener. | ||
# hass.data[DOMAIN][entry.entry_id]["unsub_options_update_listener"]() | ||
|
||
# Remove config entry from domain. | ||
if unload_ok: | ||
hass.data[DOMAIN].pop(entry.entry_id) | ||
|
||
return unload_ok |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
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,56 @@ | ||
import logging | ||
from typing import Any, Optional | ||
|
||
from homeassistant import config_entries | ||
import homeassistant.helpers.config_validation as cv | ||
import voluptuous as vol | ||
|
||
from .const import CONF_STOPS, CONF_STATION, CONF_MAX, DEFAULT_MAX, DOMAIN, STOPS | ||
|
||
_LOGGER = logging.getLogger(__name__) | ||
|
||
|
||
DEFAULT_LINES = {"dlr": "DLR", "jubilee": "Jubilee"} | ||
|
||
|
||
@config_entries.HANDLERS.register(DOMAIN) | ||
class NysseConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): | ||
"""Nysse config flow.""" | ||
|
||
def __init__(self) -> None: | ||
"""Initialize.""" | ||
self.data: dict[str, Any] = {CONF_STOPS: []} | ||
|
||
async def async_step_user(self, user_input: Optional[dict[str, Any]] = None): | ||
errors: dict[str, str] = {} | ||
if user_input is not None: | ||
self.data[CONF_STOPS].append( | ||
{ | ||
"station": user_input[CONF_STATION], | ||
"max": user_input[CONF_MAX], | ||
} | ||
) | ||
# If user ticked the box show this form again so they can add an | ||
# additional station. | ||
if user_input.get("add_another", False): | ||
return await self.async_step_user() | ||
|
||
return self.async_create_entry( | ||
title=user_input[CONF_STATION], data=self.data | ||
) | ||
|
||
stations = dict(sorted(STOPS.items(), key=lambda item: item[1])) | ||
for k in stations.keys(): | ||
stations[k] += " (" + k + ")" | ||
|
||
return self.async_show_form( | ||
step_id="user", | ||
data_schema=vol.Schema( | ||
{ | ||
vol.Required(CONF_STATION): vol.In(stations), | ||
vol.Optional(CONF_MAX, default=DEFAULT_MAX): cv.positive_int, | ||
vol.Optional("add_another", default=False): cv.boolean, | ||
} | ||
), | ||
errors=errors, | ||
) |
Oops, something went wrong.