Skip to content

Commit

Permalink
Version 0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
warrior25 committed Mar 24, 2022
1 parent b599204 commit 68f24c6
Show file tree
Hide file tree
Showing 17 changed files with 3,894 additions and 0 deletions.
47 changes: 47 additions & 0 deletions __init__.py
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 added __pycache__/__init__.cpython-39.pyc
Binary file not shown.
Binary file added __pycache__/config_flow.cpython-39.pyc
Binary file not shown.
Binary file added __pycache__/const.cpython-39.pyc
Binary file not shown.
Binary file added __pycache__/network.cpython-39.pyc
Binary file not shown.
Binary file added __pycache__/nysse_data.cpython-39.pyc
Binary file not shown.
Binary file added __pycache__/sensor.cpython-39.pyc
Binary file not shown.
Binary file added __pycache__/tfl_data.cpython-39.pyc
Binary file not shown.
56 changes: 56 additions & 0 deletions config_flow.py
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,
)
Loading

0 comments on commit 68f24c6

Please sign in to comment.