Skip to content

Commit

Permalink
allow configuring scan interval time
Browse files Browse the repository at this point in the history
  • Loading branch information
FaserF committed Jun 9, 2024
1 parent 9943cf7 commit d790650
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 21 deletions.
11 changes: 7 additions & 4 deletions custom_components/deutschebahn/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
CONF_MAX_CONNECTIONS,
CONF_IGNORED_PRODUCTS,
CONF_IGNORED_PRODUCTS_OPTIONS,
CONF_UPDATE_INTERVAL,
)

DOMAIN = "deutschebahn"
Expand Down Expand Up @@ -43,10 +44,11 @@ def __get_option(key: str, default: Any) -> Any:
step_id="init",
data_schema=vol.Schema(
{
vol.Required(CONF_OFFSET, default=__get_option(CONF_OFFSET, 0)): cv.positive_int,
vol.Required(CONF_MAX_CONNECTIONS, default=__get_option(CONF_MAX_CONNECTIONS, 2)): cv.positive_int,
vol.Required(CONF_IGNORED_PRODUCTS, default=__get_option(CONF_IGNORED_PRODUCTS, [])): cv.multi_select(CONF_IGNORED_PRODUCTS_OPTIONS),
vol.Required(CONF_ONLY_DIRECT, default=__get_option(CONF_ONLY_DIRECT, False)): cv.boolean,
vol.Required(CONF_OFFSET, default=0): cv.positive_int,
vol.Required(CONF_MAX_CONNECTIONS, default=2): cv.positive_int,
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 @@ -75,6 +77,7 @@ async def async_step_user(self, user_input=None):
vol.Required(CONF_MAX_CONNECTIONS, default=2): cv.positive_int,
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
3 changes: 2 additions & 1 deletion custom_components/deutschebahn/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
CONF_START = "start"
CONF_OFFSET = "offset"
CONF_ONLY_DIRECT = "only_direct"
CONF_MAX_CONNECTIONS = "max_connections"
CONF_MAX_CONNECTIONS = "maximum count of connections that will be fetched"
CONF_UPDATE_INTERVAL = "refresh time in seconds"
CONF_IGNORED_PRODUCTS = "ignored_products"
CONF_IGNORED_PRODUCTS_OPTIONS = {
"BUS": "Busverkehr (BUS)",
Expand Down
3 changes: 2 additions & 1 deletion custom_components/deutschebahn/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,19 @@
CONF_ONLY_DIRECT,
CONF_MAX_CONNECTIONS,
CONF_IGNORED_PRODUCTS,
CONF_UPDATE_INTERVAL,
ATTR_DATA,
DOMAIN,
)

_LOGGER = logging.getLogger(__name__)
SCAN_INTERVAL = timedelta(minutes=2)

async def async_setup_entry(
hass: core.HomeAssistant, entry: ConfigType, async_add_entities
):
"""Setup sensors from a config entry created in the integrations UI."""
config = hass.data[DOMAIN][entry.entry_id]
SCAN_INTERVAL = timedelta(minutes=config.get(CONF_UPDATE_INTERVAL, 2))
_LOGGER.debug("Sensor async_setup_entry")
if entry.options:
config.update(entry.options)
Expand Down
6 changes: 4 additions & 2 deletions custom_components/deutschebahn/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"offset": "Offset in minutes",
"only_direct": "Only show direct connections?",
"max_connections": "Max connections in sensor",
"ignored_products": "Products to ignore"
"ignored_products": "Products to ignore",
"scan_interval": "Scan interval in seconds"
}
}
}
Expand All @@ -24,7 +25,8 @@
"offset": "Offset in minutes",
"only_direct": "Only show direct connections?",
"max_connections": "Max connections in sensor",
"ignored_products": "Products to ignore"
"ignored_products": "Products to ignore",
"scan_interval": "Scan interval in seconds"
}
}
},
Expand Down
24 changes: 13 additions & 11 deletions custom_components/deutschebahn/translations/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
"init": {
"description": "Trage hier deine Zug Station Informationen ein für die Suchabfrage.",
"data": {
"offset": "Versatz in Minutes",
"only_direct": "Zeige nur direkte Verbindungen?",
"max_connections": "Maximale Anzahle der angezeigten Verbindungen",
"ignored_products": "Zu ignorierende Produkte"
"offset": "Versatz in Minuten",
"only_direct": "Nur direkte Verbindungen anzeigen?",
"max_connections": "Maximale Anzahl der angezeigten Verbindungen",
"ignored_products": "Zu ignorierende Produkte",
"scan_interval": "Aktualisierungsintervall in Sekunden"
}
}
}
Expand All @@ -19,20 +20,21 @@
"user": {
"description": "Trage hier deine Zug Station Informationen ein für die Suchabfrage.",
"data": {
"start": "Start Station",
"destination": "Ziel station",
"offset": "Versatz in Minutes",
"only_direct": "Zeige nur direkte Verbindungen?",
"max_connections": "Maximale Anzahle der angezeigten Verbindungen",
"ignored_products": "Zu ignorierende Produkte"
"start": "Startstation",
"destination": "Zielstation",
"offset": "Versatz in Minuten",
"only_direct": "Nur direkte Verbindungen anzeigen?",
"max_connections": "Maximale Anzahl der angezeigten Verbindungen",
"ignored_products": "Zu ignorierende Produkte",
"scan_interval": "Aktualisierungsintervall in Sekunden"
}
}
},
"abort": {
"already_configured": "Diese Start & Ziel Station Kombination ist bereits konfiguriert."
},
"error": {
"invalid_station": "Ungültige Start/Ziel Station",
"invalid_station": "Ungültige Start/Ziel-Station",
"unknown": "Unbekannter Fehler"
}
}
Expand Down
6 changes: 4 additions & 2 deletions custom_components/deutschebahn/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"offset": "Offset in minutes",
"only_direct": "Only show direct connections?",
"max_connections": "Max connections in sensor",
"ignored_products": "Products to ignore"
"ignored_products": "Products to ignore",
"scan_interval": "Scan interval in seconds"
}
}
}
Expand All @@ -24,7 +25,8 @@
"offset": "Offset in minutes",
"only_direct": "Only show direct connections?",
"max_connections": "Max connections in sensor",
"ignored_products": "Products to ignore"
"ignored_products": "Products to ignore",
"scan_interval": "Scan interval in seconds"
}
}
},
Expand Down

0 comments on commit d790650

Please sign in to comment.