Skip to content

Commit bc8d1f5

Browse files
authored
Bug/sensors unavailable (#103)
* Added configurable timeout for data scraping * Bump version
1 parent 298b03d commit bc8d1f5

6 files changed

Lines changed: 17 additions & 2 deletions

File tree

custom_components/enpal_webparser/config_flow.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
from .const import (
3434
DEFAULT_GROUPS,
3535
DEFAULT_INTERVAL,
36+
DEFAULT_TIMEOUT,
3637
DEFAULT_URL,
3738
DEFAULT_USE_WALLBOX_ADDON,
3839
DEFAULT_WALLBOX_API_ENDPOINT,
@@ -103,6 +104,7 @@ def get_default_config(options: dict[str, Any] | None = None) -> dict[str, Any]:
103104
return {
104105
"url": src.get("url", DEFAULT_URL),
105106
"interval": src.get("interval", DEFAULT_INTERVAL),
107+
"timeout": src.get("timeout", DEFAULT_TIMEOUT),
106108
"groups": src.get("groups", DEFAULT_GROUPS),
107109
"use_wallbox_addon": src.get("use_wallbox_addon", DEFAULT_USE_WALLBOX_ADDON),
108110
}
@@ -113,6 +115,7 @@ def get_form_schema(config: dict[str, Any]) -> vol.Schema:
113115
{
114116
vol.Required("url", default=cast(Any, config["url"])): str,
115117
vol.Required("interval", default=cast(Any, config["interval"])): int,
118+
vol.Required("timeout", default=cast(Any, config["timeout"])): vol.All(int, vol.Range(min=10, max=120)),
116119
vol.Optional("groups", default=cast(Any, config["groups"])): cv.multi_select(DEFAULT_GROUPS),
117120
vol.Optional("use_wallbox_addon", default=cast(Any, config["use_wallbox_addon"])): bool,
118121
}
@@ -138,6 +141,7 @@ async def process_user_input(hass, user_input: dict[str, Any]) -> tuple[dict[str
138141
return {
139142
"url": url_checked,
140143
"interval": user_input["interval"],
144+
"timeout": user_input.get("timeout", DEFAULT_TIMEOUT),
141145
"groups": user_input.get("groups", DEFAULT_GROUPS),
142146
"use_wallbox_addon": user_input.get("use_wallbox_addon", False),
143147
}, {}
@@ -317,6 +321,7 @@ async def async_step_configure(self, user_input=None):
317321
config = {
318322
"url": getattr(self, "_url", DEFAULT_URL),
319323
"interval": DEFAULT_INTERVAL,
324+
"timeout": DEFAULT_TIMEOUT,
320325
"groups": DEFAULT_GROUPS,
321326
"use_wallbox_addon": DEFAULT_USE_WALLBOX_ADDON,
322327
}
@@ -339,6 +344,7 @@ async def async_step_configure(self, user_input=None):
339344
options={
340345
"url": self._url,
341346
"interval": user_input["interval"],
347+
"timeout": user_input.get("timeout", DEFAULT_TIMEOUT),
342348
"groups": user_input.get("groups", DEFAULT_GROUPS),
343349
"use_wallbox_addon": user_input.get("use_wallbox_addon", False),
344350
},
@@ -349,6 +355,7 @@ async def async_step_configure(self, user_input=None):
349355
step_id="configure",
350356
data_schema=vol.Schema({
351357
vol.Required("interval", default=config["interval"]): int,
358+
vol.Required("timeout", default=config["timeout"]): vol.All(int, vol.Range(min=10, max=120)),
352359
vol.Optional("groups", default=config["groups"]): cv.multi_select(DEFAULT_GROUPS),
353360
vol.Optional("use_wallbox_addon", default=config["use_wallbox_addon"]): bool,
354361
}),
@@ -362,6 +369,7 @@ async def async_step_configure(self, user_input=None):
362369
step_id="configure",
363370
data_schema=vol.Schema({
364371
vol.Required("interval", default=config["interval"]): int,
372+
vol.Required("timeout", default=config["timeout"]): vol.All(int, vol.Range(min=10, max=120)),
365373
vol.Optional("groups", default=config["groups"]): cv.multi_select(DEFAULT_GROUPS),
366374
vol.Optional("use_wallbox_addon", default=config["use_wallbox_addon"]): bool,
367375
}),

custom_components/enpal_webparser/const.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
# Note: Enpal boxes get IP via DHCP, use auto-discovery or check your router
2424
DEFAULT_URL = "http://192.168.1.1/deviceMessages" # Placeholder - use discovery or check router
2525
DEFAULT_INTERVAL = 60
26+
DEFAULT_TIMEOUT = 30
2627

2728
DEFAULT_GROUPS = [
2829
"Wallbox",

custom_components/enpal_webparser/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@
88
"iot_class": "local_polling",
99
"issue_tracker": "https://github.com/derolli1976/enpal/issues",
1010
"requirements": ["beautifulsoup4", "psutil"],
11-
"version": "2.3.0"
11+
"version": "2.3.1"
1212
}

custom_components/enpal_webparser/sensor.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949

5050
from .const import (
5151
DEFAULT_INTERVAL,
52+
DEFAULT_TIMEOUT,
5253
DEFAULT_URL,
5354
DOMAIN,
5455
)
@@ -60,6 +61,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry, async_add_e
6061

6162
url = entry.options.get("url", DEFAULT_URL)
6263
interval = entry.options.get("interval", DEFAULT_INTERVAL)
64+
timeout = entry.options.get("timeout", DEFAULT_TIMEOUT)
6365
groups = entry.options.get("groups", [])
6466
_LOGGER.debug("[Enpal] Configuration - URL: %s, Interval: %s, Groups: %s", url, interval, groups)
6567

@@ -69,7 +71,7 @@ async def async_update_data():
6971
nonlocal last_successful_data
7072
try:
7173
session = async_get_clientsession(hass)
72-
async with session.get(url, timeout=30) as resp:
74+
async with session.get(url, timeout=timeout) as resp:
7375
if resp.status != 200:
7476
raise Exception(f"Unexpected status code: {resp.status}")
7577
html = await resp.text()

custom_components/enpal_webparser/translations/de.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"description": "Einstellungen für Gerät konfigurieren: {url}",
2828
"data": {
2929
"interval": "Abfrageintervall (in Sekunden) - Weniger als 60 Sekunden wird nicht empfohlen!",
30+
"timeout": "HTTP-Timeout (in Sekunden, 10-120) - Erhöhen, wenn Sensoren häufig als nicht verfügbar angezeigt werden",
3031
"groups": "Sensorgruppen auswählen",
3132
"use_wallbox_addon": "Wallbox Add-on verwenden (EXPERIMENTELL!) - Das Add-on muss vorher installiert und konfiguriert werden - Bitte die README Datei im Repository beachten!"
3233
}
@@ -50,6 +51,7 @@
5051
"data": {
5152
"url": "URL / IP-Adresse der Enpal Box",
5253
"interval": "Abfrageintervall (in Sekunden) - Weniger als 60 Sekunden wird nicht empfohlen!",
54+
"timeout": "HTTP-Timeout (in Sekunden, 10-120) - Erhöhen, wenn Sensoren häufig als nicht verfügbar angezeigt werden",
5355
"groups": "Sensorgruppen auswählen",
5456
"use_wallbox_addon": "Wallbox Add-on verwenden (EXPERIMENTELL!) - Das Add-on muss vorher installiert und konfiguriert werden - Bitte die README Datei im Repository beachten!"
5557
}

custom_components/enpal_webparser/translations/en.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"description": "Configure settings for device at: {url}",
2828
"data": {
2929
"interval": "Polling interval (in seconds) - Intervals below 60 seconds are not recommended!",
30+
"timeout": "HTTP timeout (in seconds, 10-120) - Increase if sensors frequently become unavailable",
3031
"groups": "Select sensor groups",
3132
"use_wallbox_addon": "Use Wallbox add-on (EXPERIMENTAL!) - The add-on must be installed and configured beforehand - See README in the Repository!"
3233
}
@@ -50,6 +51,7 @@
5051
"data": {
5152
"url": "URL / IP address of the Enpal Box",
5253
"interval": "Polling interval (in seconds) - Intervals below 60 seconds are not recommended!",
54+
"timeout": "HTTP timeout (in seconds, 10-120) - Increase if sensors frequently become unavailable",
5355
"groups": "Select sensor groups",
5456
"use_wallbox_addon": "Use Wallbox add-on (EXPERIMENTAL!) - The add-on must be installed and configured beforehand - See README in the Repository!"
5557
}

0 commit comments

Comments
 (0)