Skip to content

Conversation

@thierolm
Copy link
Contributor

@thierolm thierolm commented Jan 22, 2026

Fix #26857

Eable SML-IR reader phase readings.
Refer to #26857.

Copy link
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 Connection.Currents, the SML branch returns Voltage_L1/2/3 instead of Current_L1/2/3, which looks like a copy-paste bug and will surface as incorrect current readings when SML is available.
  • The decorateTasmota switch has become quite complex with many condition combinations for currents/voltages/powers; consider refactoring to build up the embedded interfaces incrementally to avoid a combinatorial explosion of cases and make future extensions safer.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `Connection.Currents`, the SML branch returns `Voltage_L1/2/3` instead of `Current_L1/2/3`, which looks like a copy-paste bug and will surface as incorrect current readings when SML is available.
- The `decorateTasmota` switch has become quite complex with many condition combinations for currents/voltages/powers; consider refactoring to build up the embedded interfaces incrementally to avoid a combinatorial explosion of cases and make future extensions safer.

## Individual Comments

### Comment 1
<location> `meter/tasmota/connection.go:220-226` </location>
<code_context>
 	return res.StatusSNS.Energy.Total + res.StatusSNS.SML.TotalIn, err
 }

-// Currents implements the api.PhaseCurrents interface
-func (c *Connection) Currents() (float64, float64, float64, error) {
-	return c.getPhaseValues(func(s StatusSNSResponse) Channels {
-		return s.StatusSNS.Energy.Current
-	})
+// Powers implements the api.PhasePowers interface
+func (c *Connection) Powers() (float64, float64, float64, error) {
+	s, err := c.statusSnsG.Get()
+	if err != nil {
+		return 0, 0, 0, err
+	}
+	if s.StatusSNS.SML.TotalIn != 0 {
+		// SML powers available
+		return float64(s.StatusSNS.SML.Power_L1), float64(s.StatusSNS.SML.Power_L2), float64(s.StatusSNS.SML.Power_L3), nil
</code_context>

<issue_to_address>
**issue (bug_risk):** SML branch of Currents returns voltage fields instead of current fields

In the SML branch, the code currently returns `Voltage_L1/L2/L3` instead of `Current_L1/L2/L3`, which will produce wrong current values whenever SML data is used. This appears to be a copy/paste mistake and should be updated to:

```go
if s.StatusSNS.SML.TotalIn != 0 {
    // SML currents available
    return s.StatusSNS.SML.Current_L1, s.StatusSNS.SML.Current_L2, s.StatusSNS.SML.Current_L3, nil
}
```
</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.

@andig andig added the devices Specific device support label Jan 23, 2026
@andig andig marked this pull request as draft January 23, 2026 11:06
meter/tasmota.go Outdated
if usage != "grid" && len(channels) == 3 {
currents = c.currents
var currents, voltages, powers func() (float64, float64, float64, error)
if usage != "grid" && len(channels) == 3 || usage == "grid" {
Copy link
Member

Choose a reason for hiding this comment

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

why is usage necessary here? shouldn't this only check if the measurements are available?

Copy link
Contributor Author

@thierolm thierolm Jan 23, 2026

Choose a reason for hiding this comment

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

There are different device configurations possible with tasmota software. In case a tasmota device was configured to only measure a single phase / one channel for pv, battery, charger usage, I wanted to skip the phase api decoration.
Only in case the meter is configured to meter 3 channels/phases the phase apis should provide information.

@thierolm
Copy link
Contributor Author

@andig imho the PR should be ready for merge.

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.

Tasmota SML IR-reader to support phase currents enabling load management

2 participants