Skip to content

Enphase: add voltages#29795

Merged
andig merged 1 commit into
evcc-io:masterfrom
FrankvdAa:feat-enphase-voltages
May 10, 2026
Merged

Enphase: add voltages#29795
andig merged 1 commit into
evcc-io:masterfrom
FrankvdAa:feat-enphase-voltages

Conversation

@FrankvdAa
Copy link
Copy Markdown
Contributor

Added voltages to Enphase grid and PV meters.

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:

  • The three voltages entries for both consumption and production repeat the same HTTP request and jq selection logic; consider extracting common parts via YAML anchors/aliases or template helpers to reduce duplication and make future changes less error‑prone.
  • The jq expressions repeat .consumption[] | select(.measurementType == "net-consumption") / .production[] | select(.measurementType == "production") multiple times; defining a local (e.g. def net: .consumption[] | select(...);) would simplify the filters and make them easier to read and maintain.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The three `voltages` entries for both consumption and production repeat the same HTTP request and jq selection logic; consider extracting common parts via YAML anchors/aliases or template helpers to reduce duplication and make future changes less error‑prone.
- The jq expressions repeat `.consumption[] | select(.measurementType == "net-consumption")` / `.production[] | select(.measurementType == "production")` multiple times; defining a local (e.g. `def net: .consumption[] | select(...);`) would simplify the filters and make them easier to read and maintain.

## Individual Comments

### Comment 1
<location path="templates/definition/meter/enphase.yaml" line_range="61-70" />
<code_context>
+      jq: if (( .consumption[] | select(.measurementType == "net-consumption").activeCount >= 1 ) and ( .consumption[] | select(.measurementType == "net-consumption").lines | length >= 1 )) then .consumption[] | select(.measurementType == "net-consumption").lines[0].rmsVoltage else 0 end
</code_context>
<issue_to_address>
**issue:** Consider how jq behaves when there is no matching `net-consumption` entry.

Here, `select(.measurementType == "net-consumption")` may return no items, in which case jq produces no output at all and never reaches the `else 0`. The same risk exists for `.production`. To guarantee a defined boolean check and numeric fallback, consider wrapping the selection in `first(...)`, using `// {}` to provide a default object, or adding an `any`/`index`-style existence check before dereferencing fields.
</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 on lines +61 to +70
jq: if (( .consumption[] | select(.measurementType == "net-consumption").activeCount >= 1 ) and ( .consumption[] | select(.measurementType == "net-consumption").lines | length >= 1 )) then .consumption[] | select(.measurementType == "net-consumption").lines[0].rmsVoltage else 0 end
- source: http
uri: {{ .schema }}://{{ .host }}/production.json?details=1
{{- if .token }}
auth:
type: bearer
token: {{ .token }}
insecure: true
{{- end }}
cache: {{ .cache }}
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: Consider how jq behaves when there is no matching net-consumption entry.

Here, select(.measurementType == "net-consumption") may return no items, in which case jq produces no output at all and never reaches the else 0. The same risk exists for .production. To guarantee a defined boolean check and numeric fallback, consider wrapping the selection in first(...), using // {} to provide a default object, or adding an any/index-style existence check before dereferencing fields.

@premultiply premultiply added the devices Specific device support label May 9, 2026
@premultiply premultiply self-assigned this May 9, 2026
Comment thread templates/definition/meter/enphase.yaml
@andig andig merged commit b1d5f57 into evcc-io:master May 10, 2026
20 checks passed
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.

3 participants