Skip to content

Commit

Permalink
let user not define more connections than available #45
Browse files Browse the repository at this point in the history
  • Loading branch information
FaserF committed Aug 24, 2024
1 parent 374e806 commit 661dc0d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
6 changes: 3 additions & 3 deletions custom_components/deutschebahn/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from homeassistant.data_entry_flow import FlowResult
import homeassistant.helpers.config_validation as cv

from .const import ( # pylint: disable=unused-import
from .const import (
CONF_DESTINATION,
CONF_START,
CONF_OFFSET,
Expand Down Expand Up @@ -45,7 +45,7 @@ def __get_option(key: str, default: Any) -> Any:
data_schema=vol.Schema(
{
vol.Required(CONF_OFFSET, default=0): cv.positive_int,
vol.Required(CONF_MAX_CONNECTIONS, default=2): cv.positive_int,
vol.Required(CONF_MAX_CONNECTIONS, default=2): vol.All(vol.Coerce(int), vol.Range(min=1, max=5)),
vol.Required(CONF_IGNORED_PRODUCTS, default=[]): cv.multi_select(CONF_IGNORED_PRODUCTS_OPTIONS),
vol.Required(CONF_ONLY_DIRECT, default=False): cv.boolean,
vol.Optional(CONF_UPDATE_INTERVAL, 2): cv.positive_int,
Expand Down Expand Up @@ -74,7 +74,7 @@ async def async_step_user(self, user_input=None):
vol.Required(CONF_START): cv.string,
vol.Required(CONF_DESTINATION): cv.string,
vol.Required(CONF_OFFSET, default=0): cv.positive_int,
vol.Required(CONF_MAX_CONNECTIONS, default=2): cv.positive_int,
vol.Required(CONF_MAX_CONNECTIONS, default=2): vol.All(vol.Coerce(int), vol.Range(min=1, max=5)),
vol.Required(CONF_IGNORED_PRODUCTS, default=[]): cv.multi_select(CONF_IGNORED_PRODUCTS_OPTIONS),
vol.Required(CONF_ONLY_DIRECT, default=False): cv.boolean,
vol.Optional(CONF_UPDATE_INTERVAL, 2): cv.positive_int,
Expand Down
5 changes: 5 additions & 0 deletions custom_components/deutschebahn/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,11 @@ async def async_update(self):
connections_count = len(self.connections)

if connections_count > 0:
if connections_count < self.max_connections:
_LOGGER.warning(
f"Requested {self.max_connections} connections, but only {connections_count} are available."
)

for con in self.connections:
# Detail info is not useful. Having a more consistent interface
# simplifies usage of template sensors.
Expand Down

0 comments on commit 661dc0d

Please sign in to comment.