Skip to content

Commit ad767e7

Browse files
authored
Merge pull request #2255 from TCWORLD/energy-dash-unavailable
Keep unavailable states in virtual energy dashboard
2 parents e3ff905 + 864036c commit ad767e7

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

custom_components/solax_modbus/energy_dashboard.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -319,14 +319,16 @@ def get_source_key(self, datadict: dict[str, float]) -> str:
319319

320320
return self.source_key # Use regular sensor (single mode or Slave)
321321

322-
def get_value(self, datadict: dict[str, float]) -> float:
322+
def get_value(self, datadict: dict[str, float]) -> float | None:
323323
"""Get value from source sensor, applying filter, invert, and custom functions."""
324324
source_key = self.get_source_key(datadict) # Handles parallel mode
325-
value = datadict.get(source_key, 0)
326325

326+
# Grab the value for the source. If it is unavailable, return None value to propagate unavailable state.
327+
# This avoids resetting total increasing sensors and unintentionally breaking energy statistics.
328+
value = datadict.get(source_key, None)
327329
if value is None:
328-
_LOGGER.warning(f"Source sensor {source_key} not found, using 0") # type: ignore[unreachable]
329-
return 0
330+
_LOGGER.debug(f"Source sensor {source_key} not found or has no value, marking unavailable")
331+
return None
330332

331333
# Apply filter function first (universal - applies to all sensor types)
332334
if self.filter_function:

0 commit comments

Comments
 (0)