@@ -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 = (
0 commit comments