Enphase: add voltages#29795
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Hey - I've found 1 issue, and left some high level feedback:
- The three
voltagesentries 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>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 }} |
Contributor
There was a problem hiding this comment.
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.
andig
reviewed
May 10, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Added voltages to Enphase grid and PV meters.