Skip to content

Feature/simpleapi chargepoint limit - #4278

Open
ChristophCaina wants to merge 3 commits into
openWB:masterfrom
ChristophCaina:feature/simpleapi-chargepoint-limit
Open

ChristophCaina wants to merge 3 commits into
openWB:masterfrom
ChristophCaina:feature/simpleapi-chargepoint-limit

Conversation

@ChristophCaina

@ChristophCaina ChristophCaina commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Zwei Informationen sind bisher nur per MQTT verfügbar und fehlen in der simpleAPI. Ein reiner HTTP-Client kann daher z. B. nicht erkennen, ob ein Ladepunkt nach §14a EnWG gedimmt wird, und die Kontakte eines IO-Geräts (z. B. Dimm & Control Kit) nicht auslesen.

1. Grund der Leistungsbegrenzung eines Ladepunkts

openWB/chargepoint/<id>/control_parameter/limit gibt an, warum openWB die Ladeleistung gerade begrenzt: Dimmen per EMS, Dimmen per Direktsteuerung, RSE-Kontakt, Lastmanagement, Zählerabsicherung usw.

  • neuer Parameter get_chargepoint_limit
  • get_chargepoint_all enthält zusätzlich das Feld limit

Die Werte werden unverändert aus dem MQTT-Topic übernommen; ohne Begrenzung sind beide null.

GET simpleapi.php?get_chargepoint_limit=1
{"chargepoint_1": {"limit": {"message": ", da die Dimmung die Ladeleistung begrenzt.", "limiting_value": ", da die Dimmung die Ladeleistung begrenzt."}}}

2. IO-Eingänge lesen

Neuer Parameter get_io_input_all=<ID|auto>, aufgebaut wie das vorhandene get_io_output_all. Er liefert die digitalen und analogen Eingänge aus openWB/io/states/<id>/get/digital_input und .../analog_input. Nur lesend; die Auswertung der Eingänge erfolgt weiterhin in openWB über die IO-Aktionen.

GET simpleapi.php?get_io_input_all=auto
{"io_0": {"digital_input": {"DI1": true, "DI2": false, ...}, "analog_input": {"AI1": 4.98, "AI2": 0, ...}}}

Getestet

Der Code wurde von einem KI-Agenten (Claude Code) erstellt und geprüft.
Die folgenden Tests liefen in der Arbeitsumgebung des Agenten, nicht auf einer echten openWB:

  • php -l für beide Dateien
  • getChargepointLimit(), getChargepointAll() und getIoInputAll() mit einem Fake-MQTT-Client: Begrenzung aktiv, null-Werte, Topic bzw. IO-Gerät nicht vorhanden
  • get_io_output_all liefert unverändert dasselbe Ergebnis

Ein Test auf echter Hardware steht noch aus.

Hintergrund

Anbindung des Dimm & Control Kits in der Home-Assistant-Integration openwb2mqtt für Ladepunkte und IO-Geräte, die per simpleAPI eingebunden sind.

Summary by Sourcery

Extend the simpleAPI with chargepoint limitation status and IO input readings for HTTP-based integrations.

New Features:

  • Expose chargepoint power-limiting reasons through the simpleAPI, including them in aggregate chargepoint responses.
  • Add read-only simpleAPI access to digital and analog IO inputs, including automatic discovery of input-only devices.

Enhancements:

  • Preserve existing IO output behavior while extending shared IO value handling to input topics.

Die simpleAPI liefert bisher nicht, warum openWB die Ladeleistung eines
Ladepunkts gerade begrenzt (openWB/chargepoint/<id>/control_parameter/limit).
Damit kann ein HTTP-Client z.B. nicht erkennen, ob der Ladepunkt nach
§14a EnWG gedimmt wird (Dimmen per EMS, Dimmen per Direktsteuerung,
RSE-Kontakt) oder durch Lastmanagement/Zählerabsicherung begrenzt ist.

- neuer Parameter get_chargepoint_limit
- get_chargepoint_all enthält zusätzlich das Feld "limit"

Antwort (Werte wie im MQTT-Topic, beide null ohne Begrenzung):
  {"chargepoint_1": {"limit": {"message": ", da die Dimmung die
   Ladeleistung begrenzt.", "limiting_value": "..."}}}

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Bisher kann die simpleAPI nur die Ausgaenge eines IO-Geraets lesen
(get_io_output_all). Die Eingaenge, z.B. die Kontakte des Dimm & Control
Kits, sind nur per MQTT verfuegbar.

Neuer Parameter get_io_input_all=<ID|auto>, analog zu get_io_output_all:

  {"io_0": {"digital_input": {"DI1": true, ...},
            "analog_input": {"AI1": 4.98, ...}}}

Nur lesend; die Auswertung der Eingaenge erfolgt weiterhin in openWB
ueber die IO-Aktionen.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@sourcery-ai

sourcery-ai Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

API

Expose the new chargepoint-limit parameter, include limit in aggregated chargepoint data, and treat the standalone result as a complex value for raw-output handling.

  • simpleAPI/simpleapi.php L257, L525
  • simpleAPI/src/ParameterHandler.php L533-552, L1489-1502 (+3 small edits)

Add get_io_input_all to the simpleAPI and return digital and analog input maps for the requested IO device.

  • simpleAPI/simpleapi.php L336-337, L524
  • simpleAPI/src/ParameterHandler.php L248-249, L2826-2843, L2953-2954

Implementation

Discover input-only IO devices for automatic ID selection by scanning input topics while leaving the existing output-device scan unchanged.

  • simpleAPI/src/MqttClient.php L248-262, L285, L308

Route automatic IO-input discovery to its auxiliary scan type rather than the standard IO scan.

  • simpleAPI/simpleapi.php L483-485

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@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 3 issues

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

## Individual Comments

### Comment 1
<location path="simpleAPI/src/ParameterHandler.php" line_range="1498" />
<code_context>
+            $topic = "openWB/chargepoint/{$id}/control_parameter/limit";
+            $value = $this->mqttClient->getValue($topic);
+            return ["chargepoint_{$id}" => ['limit' => $this->parseLimitValue($value)]];
+        } catch (Exception $e) {
+            return ["chargepoint_{$id}" => ['limit' => $this->parseLimitValue(null)]];
+        }
</code_context>
<issue_to_address>
**Missing MQTT topics abort reads**

When an input or chargepoint limit MQTT topic has no data, `getValue()` throws global `\Exception`, but these catches resolve `Exception` inside the `SimpleAPI` namespace, so the exception escapes instead of producing null limit values or empty input maps. Chargepoint reads can then fall back to ID 0, while IO reads omit their result.

Catch `\Exception` (or import the global `Exception` class) in these helpers.

Also at `simpleAPI/src/ParameterHandler.php:2833-2834`.
</issue_to_address>

### Comment 2
<location path="simpleAPI/src/ParameterHandler.php" line_range="2833-2834" />
<code_context>
+     */
+    private function getIoInputAll($id)
+    {
+        $digital = $this->getIoOutputMap($id, 'digital_input');
+        $analog = $this->getIoOutputMap($id, 'analog_input');
+
+        return [
</code_context>
<issue_to_address>
**Auto lookup misses input-only devices**

When an IO device publishes inputs but has no discoverable digital-output topic and the caller uses `get_io_input_all=auto`, `handleReadRequest()` calls `getLowestId('io')`, whose scan only finds `digital_output` topics, so the input-only device is skipped and the caller receives no input readings.

Update `getLowestId('io')` to discover devices from input topics as well as digital-output topics.

Also at `simpleAPI/simpleapi.php:337`.
</issue_to_address>

### Comment 3
<location path="simpleAPI/simpleapi.php" line_range="257" />
<code_context>
             'get_chargepoint_pv_charging_min_current',
             'get_chargepoint_soc',
             'get_chargepoint_state_str',
+            'get_chargepoint_limit',
             'get_chargepoint_fault_str',
             'get_chargepoint_fault_state',
</code_context>
<issue_to_address>
**Raw limit response is invalid**

When a caller requests `get_chargepoint_limit` with `raw=true`, `isComplexParameter()` does not classify `get_chargepoint_limit` as complex, so the request reaches `formatRawOutput()` and prints `Array` instead of returning the limit data or a raw-mode error.

Classify `get_chargepoint_limit` as a complex parameter so raw requests are rejected.
</issue_to_address>

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

$topic = "openWB/chargepoint/{$id}/control_parameter/limit";
$value = $this->mqttClient->getValue($topic);
return ["chargepoint_{$id}" => ['limit' => $this->parseLimitValue($value)]];
} catch (Exception $e) {

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 · Missing MQTT topics abort reads

When an input or chargepoint limit MQTT topic has no data, getValue() throws global \Exception, but these catches resolve Exception inside the SimpleAPI namespace, so the exception escapes instead of producing null limit values or empty input maps. Chargepoint reads can then fall back to ID 0, while IO reads omit their result.

Catch \Exception (or import the global Exception class) in these helpers.

Also at simpleAPI/src/ParameterHandler.php:2833-2834.

Prompt for AI agents
In `simpleAPI/src/ParameterHandler.php` at line 1498:

**Missing MQTT topics abort reads**

When an input or chargepoint limit MQTT topic has no data, `getValue()` throws global `\Exception`, but these catches resolve `Exception` inside the `SimpleAPI` namespace, so the exception escapes instead of producing null limit values or empty input maps. Chargepoint reads can then fall back to ID 0, while IO reads omit their result.

Catch `\Exception` (or import the global `Exception` class) in these helpers.

Also at `simpleAPI/src/ParameterHandler.php:2833-2834`.

Comment thread simpleAPI/src/ParameterHandler.php Resolved
Comment thread simpleAPI/simpleapi.php Resolved
- get_io_input_all=auto: openWB publiziert get/digital_output nur fuer
  IO-Geraete mit Ausgaengen, reine Eingabe-Geraete wurden von der
  Auto-ID daher nicht gefunden. Eigene Suche ueber die Eingangs-Topics
  (digital_input/analog_input, ohne *_prev). Die bestehende Suche fuer
  Ausgaenge und die Typen in list_components bleiben unveraendert.
- get_chargepoint_limit liefert ein Objekt und wird daher wie
  get_chargepoint_all als komplexer Parameter behandelt: raw=true wird
  mit einer Fehlermeldung abgelehnt statt "Array" auszugeben.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@ChristophCaina
ChristophCaina force-pushed the feature/simpleapi-chargepoint-limit branch from 2f14114 to e73a023 Compare November 6, 2026 23:18
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