Skip to content

Report per phase measurements for correct phase#154

Open
sthelen-enqs wants to merge 11 commits into
devfrom
fix/report-per-phase-measurements-for-correct-phase
Open

Report per phase measurements for correct phase#154
sthelen-enqs wants to merge 11 commits into
devfrom
fix/report-per-phase-measurements-for-correct-phase

Conversation

@sthelen-enqs

Copy link
Copy Markdown
Contributor

If/when a device registers PhaseSpecific measurements only for one specific phase (or registers them for all phases but only provides measurements for one of them), MeasurementPhaseSpecificDataForFilter() returns a []float64 containing only 1 value with no way for the API user to know for which phase the measurement was meant. This is an issue in e.g. ma/mpc's PowerPerPhase which would then return an array with less than 3 members and callers would then not know to which phase the measurement corresponds.

This PR changes the return type of MeasurementPhaseSpecificDataForFilter to always contain one entry per phase so that for a device which only reports data on phase B, it would return []float64{0, 10, 0} instead of []float64{10}. The advantage of this approach is that it doesn't change the return type of MeasurementPhaseSpecificDataForFilter or any of its callers, the downside is that callers can't (easily) distinguish devices that are reporting 0 for a phase and devices that aren't reporting a phase at all. The alternative would be to change the return type from []float64 to map[ElectricalConnectionPhaseNameType]float64 and then going through all the callers to make them use/return that as well.

I'm not particular to either approach so I picked the one that changed the surface API less.

@sthelen-enqs

Copy link
Copy Markdown
Contributor Author

After a discussion, we'll rewrite this to return the map[ElectricalConnectionPhaseNameType]float64 to be more explicit about whether phases were written to or not.

@andig

andig commented Feb 14, 2025

Copy link
Copy Markdown
Contributor

Another and easier to use option might be a [3]*float.

@DerAndereAndi DerAndereAndi added this to the Version 0.8 milestone Feb 21, 2025
@sthelen-enqs
sthelen-enqs force-pushed the fix/report-per-phase-measurements-for-correct-phase branch 2 times, most recently from f35aaa1 to 6eb1154 Compare March 5, 2025 15:51
@sthelen-enqs

Copy link
Copy Markdown
Contributor Author

I've updated this PR to return a map[ElectricalConnectionPhaseNameType]float64.
There is one incidental change which may be of interest. The acPowerTotal measurements must now have an acMeasuredPhases electricalConnectionParameterDescriptionData set for the MA MPC/MGCP usecases to pick up/report the value via the Power() functions. These are required values in the MPC/MGCP specification and should therefore not affect communication with real devices (in theory), but I had to adjust two test cases to add the required parameter.

@sthelen-enqs

Copy link
Copy Markdown
Contributor Author

We should update other usecases with the new approach to passing/receiving phase-specific values. That task is tracked in #197

@DerAndereAndi DerAndereAndi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

EVCEM is not updated but requires the same changes. Would be great if it would be part of this PR as well

Comment thread usecases/internal/measurement.go Outdated
phaseName = *param[0].AcMeasuredPhases
} else if validPhaseNameTypes == nil {
// if we're not filtering by valid phase names, allow acMeasuredPhases to be unset
phaseName = model.ElectricalConnectionPhaseNameTypeNone

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do we have a test for this code path?

Comment thread usecases/ma/mgcp/public.go Outdated
return data[0], nil
for _, k := range data {
// If the Monitored Unit is connected to less than three phases, one of the other combinations like "a" or "ab" are allowed instead of "abc".
// The values "a", "b", and "c" are permitted if and only if only one

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

the comment looks incomplete "... and only if only one ..." what? double only? :)

// if we're not filtering by valid phase names, allow acMeasuredPhases to be unset
phaseName = model.ElectricalConnectionPhaseNameTypeNone
} else {
// error getting parameter description

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't think this comment is correct here

@sthelen-enqs
sthelen-enqs force-pushed the fix/report-per-phase-measurements-for-correct-phase branch from 33f8401 to dc0455b Compare July 7, 2026 09:19
@sthelen-enqs
sthelen-enqs force-pushed the fix/report-per-phase-measurements-for-correct-phase branch from dc0455b to 6e53f8b Compare July 7, 2026 09:27
@sthelen-enqs
sthelen-enqs requested a review from Ka0o0 July 20, 2026 11:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants