Skip to content

Add read-only HeishaMon heat pump consumer - #4367

Open
kevinwieland wants to merge 4 commits into
openWB:masterfrom
kevinwieland:feat/heishamon-consumer
Open

kevinwieland wants to merge 4 commits into
openWB:masterfrom
kevinwieland:feat/heishamon-consumer

Conversation

@kevinwieland

@kevinwieland kevinwieland commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Add read-only HeishaMon heat pump consumer

Summary

  • Add a Panasonic heat pump consumer under the HeishaMon vendor, restricted to METER_ONLY.
  • Poll the local /json HTTP endpoint once per update with a five-second timeout.
  • Read electrical power exclusively from Heat_Power_Consumption in watts.
  • Read Main_Inlet_Temp, Main_Outlet_Temp, and Main_Target_Temp
    in this fixed order whenever supplied, without a separate configuration toggle.
  • Reject invalid power instead of reporting a misleading zero. Preserve missing
    or invalid optional temperature slots as null.
  • Accept nullable entries specifically in consumer temperature collections and
    reflect that in the consumer data type; phase-value validation is unchanged.
  • Use the common HTTP helper directly for each poll and let the common error
    handling report request, JSON and conversion failures.

No heat pump commands, control features, phase-current estimates, or sums across
operating modes are introduced. Extra-block-only power layouts are explicitly
outside the scope of this module. Energy counters use the existing core integration.

Related UI change

Companion settings PR: openWB/openwb-ui-settings#1180

The core also works with the existing JSON configuration fallback until the
companion UI is published. No compiled frontend assets are included here.

Validation

  • 170 existing consumer, value store, consumer control and dataclass tests passed.
  • 11 additional consumer-related SubData tests passed.
  • 36 temporary local regression checks passed, including the supplied readings,
    unsupported power values, nullable temperatures through broker validation and
    storage, missing sensors replacing old readings, and per-poll HTTP sessions.
  • Flake8 passed for the module and both modified shared files.
  • No test files, sample fixtures, README or compiled frontend assets are added.

Summary by Sourcery

Add read-only HeishaMon monitoring for Panasonic heat pumps with robust power and temperature handling.

New Features:

  • Add a read-only Panasonic heat pump consumer that retrieves electrical power and optional water temperatures from HeishaMon.

Bug Fixes:

  • Preserve missing or invalid optional temperature readings as null and clear temperatures when readings are unavailable.
  • Reject invalid heat pump power values instead of reporting misleading readings.

Enhancements:

  • Allow nullable entries in consumer temperature collections while retaining existing validation for other phase-related values.
  • Support recovery from failed HTTP session initialization and validate the configured host before polling.

KevinWieland added 2 commits November 18, 2026 08:06
Read Heat_Power_Consumption and optional inlet, outlet and target temperatures through the local JSON endpoint. Include validation, documentation and regression tests.

Companion settings: https://github.com/kevinwieland/openwb-ui-settings/tree/feat/heishamon-consumer

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 5 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="packages/modules/consumers/heishamon/heishamon/consumer.py" line_range="13-43" />
<code_context>
+from typing import Optional, Tuple
+
+from control.consumer.consumer_data import ConsumerUsage
+from helpermodules.auto_str import auto_str
</code_context>
<issue_to_address>
**Failed setup leaves polling broken**

When `req.get_http_session()` raises during consumer construction, `ConfigurableConsumer` catches an exception from `initializer()` without retrying it, leaving `session` as `None`; every later `update()` then fails at `session.get()` until the consumer module is recreated.

Retry session initialization after a setup failure, or fail consumer creation instead of retaining a module with an unset session.
</issue_to_address>

### Comment 2
<location path="packages/modules/consumers/heishamon/heishamon/config.py" line_range="12" />
<code_context>
+@auto_str
+class HeishaMonConfiguration:
+    def __init__(self,
+                 ip_address: Optional[str] = None,
+                 read_temperatures: bool = True):
+        self.ip_address = ip_address
</code_context>
<issue_to_address>
**Missing address prevents polling**

When the consumer is created or loaded with `configuration.ip_address` unset, `update` interpolates the missing address as `None` and requests `http://None/json`; the request fails, so no power or temperatures are reported and the consumer enters a fault state.

Validate that the address is present before constructing the consumer or attempting the request.

Also at `packages/modules/consumers/heishamon/heishamon/consumer.py:43`.
</issue_to_address>

### Comment 3
<location path="packages/modules/consumers/heishamon/heishamon/consumer.py" line_range="59-60" />
<code_context>
+                "Die Wärmepumpe liefert möglicherweise nur erweiterte Leistungswerte.")
+
+        # Keep fixed positions even when one optional sensor is missing or invalid.
+        temperatures = ([_get_temperature(values, name) for name in TEMPERATURE_NAMES]
+                        if config.configuration.read_temperatures else None)
+        return ConsumerState(power=power, temperatures=temperatures)
+
</code_context>
<issue_to_address>
**Valid temperatures are discarded**

When at least one optional temperature is missing or invalid, `ConsumerValueStoreBroker` passes the temperature list to `SetData`, which rejects the entire list because its `None` entries fail float validation; no temperature slots reach the consumer state.

Allow `None` entries in temperature collections through `SetData` validation and storage while retaining the fixed slots.
</issue_to_address>

### Comment 4
<location path="packages/modules/consumers/heishamon/heishamon/consumer.py" line_range="61" />
<code_context>
+        # Keep fixed positions even when one optional sensor is missing or invalid.
+        temperatures = ([_get_temperature(values, name) for name in TEMPERATURE_NAMES]
+                        if config.configuration.read_temperatures else None)
+        return ConsumerState(power=power, temperatures=temperatures)
+
+    return ConfigurableConsumer(consumer_config=config,
</code_context>
<issue_to_address>
**Unmeasured phases are stored as zero**

`ConsumerState` fills omitted phase measurements with zero currents and powers and default voltages; `ConsumerValueStoreBroker` publishes those values, so phase data is recorded even though HeishaMon supplied no phase measurements.

Avoid publishing phase measurements for this consumer unless the module actually reads them.
</issue_to_address>

### Comment 5
<location path="packages/modules/consumers/heishamon/heishamon/consumer.py" line_range="59-60" />
<code_context>
+                "Die Wärmepumpe liefert möglicherweise nur erweiterte Leistungswerte.")
+
+        # Keep fixed positions even when one optional sensor is missing or invalid.
+        temperatures = ([_get_temperature(values, name) for name in TEMPERATURE_NAMES]
+                        if config.configuration.read_temperatures else None)
+        return ConsumerState(power=power, temperatures=temperatures)
+
</code_context>
<issue_to_address>
**Old temperatures remain visible**

When temperature readings are disabled after a temperature value has been published, `ConsumerValueStoreBroker` skips publishing `None`, so the previously published temperature value remains stored and appears current.

Clear or remove the published temperature value when readings are disabled instead of skipping the `None` update.

Also at `packages/modules/consumers/heishamon/heishamon/consumer.py:61`.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨

# Keep fixed positions even when one optional sensor is missing or invalid.
temperatures = ([_get_temperature(values, name) for name in TEMPERATURE_NAMES]
if config.configuration.read_temperatures else None)
return ConsumerState(power=power, temperatures=temperatures)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Medium · Unmeasured phases are stored as zero

ConsumerState fills omitted phase measurements with zero currents and powers and default voltages; ConsumerValueStoreBroker publishes those values, so phase data is recorded even though HeishaMon supplied no phase measurements.

Avoid publishing phase measurements for this consumer unless the module actually reads them.

Prompt for AI agents
In `packages/modules/consumers/heishamon/heishamon/consumer.py` at line 61:

**Unmeasured phases are stored as zero**

`ConsumerState` fills omitted phase measurements with zero currents and powers and default voltages; `ConsumerValueStoreBroker` publishes those values, so phase data is recorded even though HeishaMon supplied no phase measurements.

Avoid publishing phase measurements for this consumer unless the module actually reads them.

Validate the host before polling, retry failed HTTP-session initialization, preserve nullable temperature slots through the consumer validator, and clear temperatures when disabled. Leave phase handling unchanged.
@seaspotter

Copy link
Copy Markdown
Collaborator

Ein paar Kommentare mit Hinblick auf alle anderen Consumer Module: :)

  1. Option "Temperaturen auslesen" entfernen (config.py). Shelly, AVM, myStrom und my-PV lesen die Temperaturen immer, wenn das Gerät sie liefert. Eine Option gibt es nur bei den generischen Modulen, weil die das Gerät nicht kennen. HeishaMon liefert die Felder ohnehin; fehlt ein Wert, bleibt er None. Damit entfällt auch der Zweig, der bei ausgeschalteter Option eine leere Liste veröffentlicht. Mit der Option im Core kann auch die Checkbox samt Hilfetext in der UI (consumer.vue) entfallen.
  2. Weniger Absicherung in consumer.py.
  • _get_number mit isfinite, Bool-Prüfung und OverflowError ist deutlich mehr, als die anderen Module machen. Dort reicht float(...); Fehler meldet die Fehlerbehandlung des Moduls.
  • Die erneute Session-Initialisierung (if session is None: initializer()) ist nicht nötig, req.get_http_session() schlägt nicht fehl. Bei Shelly wird die Session im Initializer erzeugt. Eine error_handler-Funktion, die den Initializer erneut aufruft, haben die meisten Module.
  • Die Prüfung der IP-Adresse (isinstance, strip) kann entfallen, das Feld ist in der UI required.
  1. Kommentare sind meist auf Deutsch, wie in den anderen Modulen. Der lange englische Kommentar zu Heat_Power_Consumption kann auf einen Satz gekürzt werden.

Als Anhaltspunkt, wieupdate()dann aussehen könnte (nicht getestet):

def update() -> ConsumerState:
    response = req.get_http_session().get(f"http://{config.configuration.ip_address}/json", timeout=5).json()
    values = {entry["Name"]: entry.get("Value") for entry in response["heatpump"]}
    power = float(values["Heat_Power_Consumption"])
    return ConsumerState(power=power, temperatures=[_temperature(values.get(name)) for name in TEMPERATURE_NAMES])
  1. UI-Texte allgemein: Der Info-Hinweis in consumer.vue ist sehr lang. Die anderen Verbraucher-Einstellungen kommen mit den Eingabefeldern und höchstens einem kurzen Hinweis aus. Ein Satz reicht, z. B. "Die Messwerte werden lokal über HeishaMon ausgelesen, die Wärmepumpe wird nicht gesteuert. Es wird nur Heat_Power_Consumption verwendet." Die Details (kein thermischer Wert, keine Summe über Betriebsarten, Heat_Power_Consumption_Extra nicht unterstützt) gehören vllt eher in die Beschreibung des Pull Requests.

Always read available temperatures, use the common HTTP helper directly, and rely on standard conversion and error handling. Keep invalid negative power readings rejected and nullable temperature slots intact.
@kevinwieland

Copy link
Copy Markdown
Contributor Author

Danke @seaspotter, die Vereinfachungen sind in a2d52ee und im UI-PR openWB/openwb-ui-settings#1180 (d95caf5) umgesetzt:

  • Temperatur-Option und Checkbox entfernt; die drei Temperaturen werden immer ausgelesen, fehlende oder ungültige Werte bleiben an ihrer Position None.
  • Direkter Zugriff über req.get_http_session() pro Abfrage, float-Konvertierung und zentrale Fehlerbehandlung statt eigener Session-, IP- und Zahlenwert-Absicherungen.
  • Kommentare gekürzt und auf Deutsch umgestellt, UI-Hinweis und Host-Hilfe gekürzt. Die technischen Einschränkungen stehen in den PR-Beschreibungen.

Die fachliche Prüfung auf negative elektrische Leistungswerte bleibt wegen ungültiger HeishaMon-Werte wie -200 W erhalten. Die Unterstützung von None innerhalb der Temperaturliste bleibt ebenfalls bestehen, damit fehlende Sensorwerte nicht die anderen Temperaturen verwerfen. Die Phasenbehandlung ist unverändert.

181 bestehende Core-Tests, 36 lokale Prüfungen sowie 61 bestehende UI-Tests erfolgreich; Lint und UI-Build ebenfalls erfolgreich. Keine Testdateien, README oder Build-Artefakte in den PRs ergänzt.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants