diff --git a/custom_components/deutschebahn/__init__.py b/custom_components/deutschebahn/__init__.py index d4a545b..658b1a1 100644 --- a/custom_components/deutschebahn/__init__.py +++ b/custom_components/deutschebahn/__init__.py @@ -32,8 +32,8 @@ async def async_setup_entry( async def async_update_data(): """Fetch data from Schiene.""" config = hass.data[DOMAIN][entry.entry_id] - update_interval = config.get("scan_interval", 2) # Default scan interval - async with async_timeout.timeout(update_interval - 1): + update_interval = timedelta(minutes=config.get(CONF_UPDATE_INTERVAL, 2)) + async with async_timeout.timeout(update_interval - 0.1): # Assuming data.update() is an async function, no need for async_add_executor_job await data.update() diff --git a/custom_components/deutschebahn/manifest.json b/custom_components/deutschebahn/manifest.json index d3ed1e0..268043f 100644 --- a/custom_components/deutschebahn/manifest.json +++ b/custom_components/deutschebahn/manifest.json @@ -14,5 +14,5 @@ "requirements": [ "schiene==0.26" ], - "version": "3.0.3" + "version": "3.0.4" } \ No newline at end of file diff --git a/custom_components/deutschebahn/sensor.py b/custom_components/deutschebahn/sensor.py index 8c19af4..ad6f2de 100644 --- a/custom_components/deutschebahn/sensor.py +++ b/custom_components/deutschebahn/sensor.py @@ -39,16 +39,14 @@ async def async_setup_entry( """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") + _LOGGER.debug(f"Sensor async_setup_entry Using scan interval: {scan_interval}") + if entry.options: config.update(entry.options) + sensors = DeutscheBahnSensor(config, hass, scan_interval) - async_add_entities( - [ - DeutscheBahnSensor(config, hass, scan_interval) - ], - update_before_add=True - ) + async_add_entities([sensors], update_before_add=True) + class DeutscheBahnSensor(SensorEntity): """Implementation of a Deutsche Bahn sensor.""" @@ -151,13 +149,13 @@ async def async_update(self): if connections_count > 0: if connections_count < self.max_connections: + verb = "is" if connections_count == 1 else "are" _LOGGER.warning( - f"Requested {self.max_connections} connections, but only {connections_count} are available." + f"{self._name} Requested {self.max_connections} connections, but only {connections_count} {verb} available." ) + for con in self.connections: - # Detail info is not useful. Having a more consistent interface - # simplifies usage of template sensors. if "details" in con: #_LOGGER.debug(f"Processing connection: {con}") con.pop("details")