Skip to content

Huawei: re-add curtail#30145

Merged
andig merged 4 commits into
evcc-io:masterfrom
CiNcH83:huawei_curtail2
Jun 3, 2026
Merged

Huawei: re-add curtail#30145
andig merged 4 commits into
evcc-io:masterfrom
CiNcH83:huawei_curtail2

Conversation

@CiNcH83
Copy link
Copy Markdown
Contributor

@CiNcH83 CiNcH83 commented May 23, 2026

follow-up #30116

Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

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

Hey - I've found 1 issue, and left some high level feedback:

  • Consider adding validation or at least a default for curtailpercent (e.g. range-limiting 0–100) to avoid writing invalid values to register 47418 when the parameter is unset or misconfigured.
  • The curtail block’s if condition uses source: convert with convert: bool2int but no clear boolean source; it would be clearer and less error‑prone to reference an explicit flag or parameter that determines whether curtailment should be enabled.
  • The magic values written to register 47415 (0 and 7) are only described in comments; consider extracting them as named constants or adding a short explanation of the mode mapping to make future changes and reviews easier.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Consider adding validation or at least a default for `curtailpercent` (e.g. range-limiting 0–100) to avoid writing invalid values to register 47418 when the parameter is unset or misconfigured.
- The `curtail` block’s `if` condition uses `source: convert` with `convert: bool2int` but no clear boolean source; it would be clearer and less error‑prone to reference an explicit flag or parameter that determines whether curtailment should be enabled.
- The magic values written to register 47415 (0 and 7) are only described in comments; consider extracting them as named constants or adding a short explanation of the mode mapping to make future changes and reviews easier.

## Individual Comments

### Comment 1
<location path="templates/definition/meter/huawei-sun2000-hybrid.yaml" line_range="168-157" />
<code_context>
+              address: 47415 # Active power control mode
+              type: writesingle
+              encoding: uint16
+    else:
+      source: convert
+      convert: bool2int
+      set:
+        source: const
+        value: 0 # Unlimited 
+        set:
+          source: modbus
+          {{- include "modbus" . | indent 8 }}
+          register:
+            address: 47415 # Active power control mode
+            type: writesingle
+            encoding: uint16
+  curtailed:
+    source: modbus
</code_context>
<issue_to_address>
**issue (bug_risk):** When disabling curtailment, the maximum feed-in power register remains unchanged, which may leave a stale limit configured.

In the `else` branch of `curtail`, only register `47415` is set to `0` (“Unlimited”), while `47418` (max feed-in power, 0–100%) is left unchanged. This can leave a stale limit that will be silently reused if the mode is later switched away from `0`. Consider also resetting `47418` (e.g. to 100%) when disabling curtailment, or clearly document that the firmware ignores `47418` when mode is `0`.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

register:
address: 47418 # Maximum Feed Grid Power (0-100 %)
type: writesingle
encoding: uint16
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

issue (bug_risk): When disabling curtailment, the maximum feed-in power register remains unchanged, which may leave a stale limit configured.

In the else branch of curtail, only register 47415 is set to 0 (“Unlimited”), while 47418 (max feed-in power, 0–100%) is left unchanged. This can leave a stale limit that will be silently reused if the mode is later switched away from 0. Consider also resetting 47418 (e.g. to 100%) when disabling curtailment, or clearly document that the firmware ignores 47418 when mode is 0.

@andig andig marked this pull request as draft May 23, 2026 10:03
@andig andig added the devices Specific device support label May 23, 2026
@CiNcH83 CiNcH83 force-pushed the huawei_curtail2 branch from e16cd63 to c3928aa Compare May 23, 2026 10:36
@CiNcH83 CiNcH83 force-pushed the huawei_curtail2 branch from c3928aa to c19b9eb Compare May 23, 2026 18:51
@CiNcH83
Copy link
Copy Markdown
Contributor Author

CiNcH83 commented May 28, 2026

Is there anything holding this back?

@CiNcH83 CiNcH83 marked this pull request as ready for review May 31, 2026 08:53
Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

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

Hey - I've found 1 issue, and left some high level feedback:

  • In the curtail if/else block, the if branch uses source: convert with convert: bool2int but no underlying source value is specified, so the condition may never reflect any real input; consider wiring this to an explicit signal (e.g. a param or capability flag) so the if/else actually toggles based on a meaningful value.
  • Both branches of the curtail logic manipulate register 47415, but the logic does not appear to consider or preserve any existing control mode that might have been set previously; if this inverter can be controlled by other features, you may want to ensure the curtail flow does not overwrite unrelated modes unintentionally.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In the `curtail` if/else block, the `if` branch uses `source: convert` with `convert: bool2int` but no underlying source value is specified, so the condition may never reflect any real input; consider wiring this to an explicit signal (e.g. a param or capability flag) so the if/else actually toggles based on a meaningful value.
- Both branches of the `curtail` logic manipulate register 47415, but the logic does not appear to consider or preserve any existing control mode that might have been set previously; if this inverter can be controlled by other features, you may want to ensure the curtail flow does not overwrite unrelated modes unintentionally.

## Individual Comments

### Comment 1
<location path="templates/definition/meter/huawei-sun2000-hybrid.yaml" line_range="141-145" />
<code_context>
       decode: uint32nan
     scale: 0.01
   maxacpower: {{ .maxacpower }}
+  curtail:
+    source: ifelse
+    if:
+      source: convert
+      convert: bool2int
+      set:
+        source: sequence
</code_context>
<issue_to_address>
**suggestion:** The `bool2int` conversions in the `curtail` pipeline appear unused and may be redundant.

Both branches wrap `source: convert` with `convert: bool2int`, but that converted value isn’t used; the `set` chains just perform the Modbus writes. If you don’t need the converted value, drop the `convert: bool2int` wrappers; if you do, consider wiring it into the `ifelse` condition so its effect is explicit.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread templates/definition/meter/huawei-sun2000-hybrid.yaml
@andig andig merged commit 0a36403 into evcc-io:master Jun 3, 2026
8 checks passed
toeklk pushed a commit to toeklk/evcc that referenced this pull request Jun 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

devices Specific device support

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants