Skip to content

Commit b617d52

Browse files
authored
Validate connection parameters in MarstekCoordinator and update version in manifest.json (#246)
2 parents ff96ee8 + c295f15 commit b617d52

2 files changed

Lines changed: 15 additions & 7 deletions

File tree

custom_components/marstek_modbus/coordinator.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,19 @@ class MarstekCoordinator(DataUpdateCoordinator):
3434
def __init__(self, hass: HomeAssistant, entry: ConfigEntry):
3535
"""Initialize the coordinator with connection parameters and update interval."""
3636
self.hass = hass
37-
self.host = entry.data["host"]
38-
self.port = entry.data["port"]
39-
self.message_wait_ms = entry.data.get("message_wait_milliseconds")
40-
self.timeout = entry.data.get("timeout")
41-
self.unit_id = entry.data.get("unit_id", DEFAULT_UNIT_ID)
37+
entry_data = entry.data or {}
38+
39+
self.host = entry_data.get("host")
40+
self.port = entry_data.get("port")
41+
if self.host is None or self.port is None:
42+
raise ValueError(
43+
"Config entry is missing required connection data (host/port). "
44+
"Please reconfigure the Marstek integration."
45+
)
46+
47+
self.message_wait_ms = entry_data.get("message_wait_milliseconds")
48+
self.timeout = entry_data.get("timeout")
49+
self.unit_id = entry_data.get("unit_id", DEFAULT_UNIT_ID)
4250

4351
# Mapping from sensor key to entity type for logging and processing
4452
self._entity_types: dict[str, str] = {}
@@ -562,7 +570,7 @@ async def _async_update_data(self):
562570
# For total_increasing sensors, reject suspicious regressions/glitches
563571
# by failing the coordinator update.
564572
if sensor.get("state_class") == "total_increasing" and isinstance(value, (int, float)):
565-
previous_value = self.data.get(key)
573+
previous_value = self.data.get(key) if isinstance(self.data, dict) else None
566574
if isinstance(previous_value, (int, float)):
567575
regression = value < previous_value
568576
scale_glitch = (

custom_components/marstek_modbus/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"domain": "marstek_modbus",
33
"name": "Marstek Venus Modbus",
4-
"version": "2026.5.1.b1",
4+
"version": "2026.5.1.b2",
55
"config_flow": true,
66
"documentation": "https://github.com/viperrnmc/marstek_venus_modbus",
77
"requirements": ["pymodbus>=3.9.2"],

0 commit comments

Comments
 (0)