Skip to content

Commit

Permalink
Dsmr: fix sign for import current (#3671)
Browse files Browse the repository at this point in the history
  • Loading branch information
andig authored Jun 20, 2022
1 parent 2bb9e5a commit e3326de
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions meter/dsmr.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@ type Dsmr struct {
updated time.Time
}

var currentObisCodes = []string{"1-0:31.7.0", "1-0:51.7.0", "1-0:71.7.0"}
var (
currentObis = []string{"1-0:31.7.0", "1-0:51.7.0", "1-0:71.7.0"}
powerExportObis = []string{"1-0:22.7.0", "1-0:42.7.0", "1-0:62.7.0"}
)

func init() {
registry.Add("dsmr", NewDsmrFromConfig)
Expand Down Expand Up @@ -117,7 +120,7 @@ func NewDsmr(uri, energy string, timeout time.Duration) (api.Meter, error) {
// decorate currents
var currents func() (float64, float64, float64, error)

for _, obis := range currentObisCodes {
for _, obis := range currentObis {
_, err = m.get(obis)
if err != nil {
break
Expand Down Expand Up @@ -254,9 +257,15 @@ func (m *Dsmr) currents() (float64, float64, float64, error) {

for i := 0; i < 3; i++ {
var err error
res[i], err = m.get(currentObisCodes[i])
if err != nil {
if res[i], err = m.get(currentObis[i]); err != nil {
return 0, 0, 0, err
}

// correct import/export sign
if f, err := m.get(powerExportObis[i]); err != nil {
return 0, 0, 0, err
} else if f > 0 {
res[i] = -res[i]
}
}

Expand Down

0 comments on commit e3326de

Please sign in to comment.