Skip to content

Commit

Permalink
Merge pull request #4 from BottlecapDave/develop
Browse files Browse the repository at this point in the history
New release
  • Loading branch information
BottlecapDave authored Sep 2, 2022
2 parents a3f6ce7 + 2651827 commit 0f1e4b1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
27 changes: 16 additions & 11 deletions custom_components/first_bus/config_flow.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import voluptuous as vol
import re
import logging

from homeassistant.config_entries import (ConfigFlow, OptionsFlow)
from homeassistant.core import callback
Expand All @@ -14,6 +15,8 @@
REGEX_BUSES,
)

_LOGGER = logging.getLogger(__name__)

class FirstBusConfigFlow(ConfigFlow, domain=DOMAIN):
"""Config flow."""

Expand Down Expand Up @@ -65,7 +68,7 @@ async def async_step_init(self, user_input):
return self.async_show_form(
step_id="user",
data_schema=vol.Schema({
vol.Optional(CONFIG_BUSES, default=config[CONFIG_BUSES]): str,
vol.Optional(CONFIG_BUSES, default=','.join(config[CONFIG_BUSES])): str,
})
)

Expand All @@ -80,22 +83,24 @@ async def async_step_user(self, user_input):
if user_input is not None:
config.update(user_input)

if CONFIG_BUSES in config and config[CONFIG_BUSES] != None:
matches = re.search(REGEX_BUSES, config[CONFIG_BUSES])
if (matches == None):
errors[CONFIG_BUSES] = "invalid_buses"
else:
config[CONFIG_BUSES] = config[CONFIG_BUSES].split(",")
_LOGGER.debug(f"Update config {config}")

if CONFIG_BUSES in config and config[CONFIG_BUSES] != None and len(config[CONFIG_BUSES]) > 0:
matches = re.search(REGEX_BUSES, config[CONFIG_BUSES])
if (matches == None):
errors[CONFIG_BUSES] = "invalid_buses"
else:
config[CONFIG_BUSES] = []
config[CONFIG_BUSES] = config[CONFIG_BUSES].split(",")
else:
config[CONFIG_BUSES] = []

if len(errors) < 1:
return self.async_create_entry(title="", data=config)
if len(errors) < 1:
return self.async_create_entry(title="", data=config)

return self.async_show_form(
step_id="user",
data_schema=vol.Schema({
vol.Optional(CONFIG_BUSES, default=config[CONFIG_BUSES]): str,
vol.Optional(CONFIG_BUSES, default=','.join(config[CONFIG_BUSES])): str,
}),
errors=errors
)
1 change: 1 addition & 0 deletions custom_components/first_bus/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ async def async_update(self):
if self._minsSinceLastUpdate >= 5:
next_time = await self._client.async_get_next_bus(self._data[CONFIG_STOP], self._data[CONFIG_BUSES])
self._attributes = next_time
self._attributes["stop"] = self._data[CONFIG_STOP]
self._minsSinceLastUpdate = 0

if next_time != None:
Expand Down

0 comments on commit 0f1e4b1

Please sign in to comment.