chore: align implementation of phase-value returns (#10313)

This commit is contained in:
andig 2023-10-14 16:35:11 +02:00 • committed by GitHub
parent e22564dfe2
commit 3b11d0e253
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 61 additions and 59 deletions

View file

@ -218,12 +218,12 @@ func (wb *ABB) Currents() (float64, float64, float64, error) {
return 0, 0, 0, err
}
var curr [3]float64
var res [3]float64
for l := 0; l < 3; l++ {
curr[l] = float64(binary.BigEndian.Uint32(b[4*l:])) / 1e3
res[l] = float64(binary.BigEndian.Uint32(b[4*l:])) / 1e3
}
return curr[0], curr[1], curr[2], nil
return res[0], res[1], res[2], nil
}
var _ api.PhaseVoltages = (*ABB)(nil)
@ -235,12 +235,12 @@ func (wb *ABB) Voltages() (float64, float64, float64, error) {
return 0, 0, 0, err
}
var volt [3]float64
var res [3]float64
for l := 0; l < 3; l++ {
volt[l] = float64(binary.BigEndian.Uint32(b[4*l:])) / 10
res[l] = float64(binary.BigEndian.Uint32(b[4*l:])) / 10
}
return volt[0], volt[1], volt[2], nil
return res[0], res[1], res[2], nil
}
// var _ api.PhaseSwitcher = (*ABB)(nil)

View file

@ -236,17 +236,17 @@ func (wb *ABLeMH) currents() (float64, float64, float64, error) {
return 0, 0, 0, err
}
var currents []float64
for i := 2; i < 5; i++ {
u := binary.BigEndian.Uint16(b[2*i:])
var res [3]float64
for i := 0; i < 3; i++ {
u := binary.BigEndian.Uint16(b[2*(2+i):])
if u == ablAmpsDisabled || u == 1 {
u = 0
}
currents = append(currents, float64(u)/10)
res[i] = float64(u) / 10
}
return currents[2], currents[1], currents[0], nil
return res[2], res[1], res[0], nil
}
var _ api.Diagnosis = (*ABLeMH)(nil)

View file

@ -287,12 +287,12 @@ func (wb *BenderCC) currents() (float64, float64, float64, error) {
return 0, 0, 0, err
}
var curr [3]float64
var res [3]float64
for l := 0; l < 3; l++ {
curr[l] = float64(binary.BigEndian.Uint32(b[4*l:4*(l+1)])) / 1e3
res[l] = float64(binary.BigEndian.Uint32(b[4*l:4*(l+1)])) / 1e3
}
return curr[0], curr[1], curr[2], nil
return res[0], res[1], res[2], nil
}
// voltages implements the api.PhaseVoltages interface
@ -302,12 +302,12 @@ func (wb *BenderCC) voltages() (float64, float64, float64, error) {
return 0, 0, 0, err
}
var volt [3]float64
var res [3]float64
for l := 0; l < 3; l++ {
volt[l] = float64(binary.BigEndian.Uint32(b[4*l : 4*(l+1)]))
res[l] = float64(binary.BigEndian.Uint32(b[4*l : 4*(l+1)]))
}
return volt[0], volt[1], volt[2], nil
return res[0], res[1], res[2], nil
}
// identify implements the api.Identifier interface

View file

@ -271,12 +271,12 @@ func (wb *HeidelbergEC) Currents() (float64, float64, float64, error) {
return 0, 0, 0, err
}
var curr [3]float64
var res [3]float64
for l := 0; l < 3; l++ {
curr[l] = float64(binary.BigEndian.Uint16(b[2*l:])) / 10
res[l] = float64(binary.BigEndian.Uint16(b[2*l:])) / 10
}
return curr[0], curr[1], curr[2], nil
return res[0], res[1], res[2], nil
}
var _ api.PhaseVoltages = (*HeidelbergEC)(nil)
@ -288,12 +288,12 @@ func (wb *HeidelbergEC) Voltages() (float64, float64, float64, error) {
return 0, 0, 0, err
}
var volt [3]float64
var res [3]float64
for l := 0; l < 3; l++ {
volt[l] = float64(binary.BigEndian.Uint16(b[2*l:]))
res[l] = float64(binary.BigEndian.Uint16(b[2*l:]))
}
return volt[0], volt[1], volt[2], nil
return res[0], res[1], res[2], nil
}
var _ api.Diagnosis = (*HeidelbergEC)(nil)

View file

@ -214,17 +214,17 @@ var _ api.PhaseCurrents = (*OpenWB)(nil)
// Currents implements the api.PhaseCurrents interface
func (m *OpenWB) Currents() (float64, float64, float64, error) {
var currents []float64
var res []float64
for _, currentG := range m.currentsG {
c, err := currentG()
if err != nil {
return 0, 0, 0, err
}
currents = append(currents, c)
res = append(res, c)
}
return currents[0], currents[1], currents[2], nil
return res[0], res[1], res[2], nil
}
var _ api.Authorizer = (*OpenWB)(nil)

View file

@ -252,18 +252,18 @@ var _ api.PhaseCurrents = (*Smaevcharger)(nil)
// Currents implements the api.PhaseCurrents interface
func (wb *Smaevcharger) Currents() (float64, float64, float64, error) {
var curr []float64
var res [3]float64
for _, phase := range []string{"A", "B", "C"} {
for i, phase := range []string{"A", "B", "C"} {
val, err := wb.getMeasurement("Measurement.GridMs.A.phs" + phase)
if err != nil {
return 0, 0, 0, err
}
curr = append(curr, -val)
res[i] = -val
}
return curr[0], curr[1], curr[2], nil
return res[0], res[1], res[2], nil
}
// reset cache

View file

@ -42,11 +42,13 @@ const (
vestelRegSessionEnergy = 1502
vestelRegFailsafeTimeout = 2002
vestelRegAlive = 6000
//vestelRegChargepointState = 1000
// vestelRegChargepointState = 1000
)
var vestelRegCurrents = []uint16{1008, 1010, 1012} // non-continuous uint16 registers!
var vestelRegVoltages = []uint16{1014, 1016, 1018} // non-continuous uint16 registers!
var (
vestelRegCurrents = []uint16{1008, 1010, 1012} // non-continuous uint16 registers!
vestelRegVoltages = []uint16{1014, 1016, 1018} // non-continuous uint16 registers!
)
// Vestel is an api.Charger implementation for Vestel/Hymes wallboxes with Ethernet (SW modells).
// It uses Modbus TCP to communicate with the wallbox at modbus client id 255.
@ -212,34 +214,34 @@ var _ api.PhaseCurrents = (*Vestel)(nil)
// Currents implements the api.PhaseCurrents interface
func (wb *Vestel) Currents() (float64, float64, float64, error) {
var currents []float64
for _, regCurrent := range vestelRegCurrents {
var res [3]float64
for i, regCurrent := range vestelRegCurrents {
b, err := wb.conn.ReadInputRegisters(regCurrent, 1)
if err != nil {
return 0, 0, 0, err
}
currents = append(currents, float64(binary.BigEndian.Uint16(b))/1e3)
res[i] = float64(binary.BigEndian.Uint16(b)) / 1e3
}
return currents[0], currents[1], currents[2], nil
return res[0], res[1], res[2], nil
}
var _ api.PhaseVoltages = (*Vestel)(nil)
// Voltages implements the api.PhaseVoltages interface
func (wb *Vestel) Voltages() (float64, float64, float64, error) {
var voltages []float64
for _, regVoltage := range vestelRegVoltages {
var res [3]float64
for i, regVoltage := range vestelRegVoltages {
b, err := wb.conn.ReadInputRegisters(regVoltage, 1)
if err != nil {
return 0, 0, 0, err
}
voltages = append(voltages, float64(binary.BigEndian.Uint16(b)))
res[i] = float64(binary.BigEndian.Uint16(b))
}
return voltages[0], voltages[1], voltages[2], nil
return res[0], res[1], res[2], nil
}
var _ api.Diagnosis = (*Vestel)(nil)

View file

@ -195,17 +195,17 @@ func (wb *Wallbe) totalEnergy() (float64, error) {
// currents implements the api.PhaseCurrents interface
func (wb *Wallbe) currents() (float64, float64, float64, error) {
var currents []float64
for _, regCurrent := range wbRegCurrents {
b, err := wb.conn.ReadInputRegisters(regCurrent, 2)
var res [3]float64
for i, reg := range wbRegCurrents {
b, err := wb.conn.ReadInputRegisters(reg, 2)
if err != nil {
return 0, 0, 0, err
}
currents = append(currents, rs485.RTUInt32ToFloat64Swapped(b))
res[i] = rs485.RTUInt32ToFloat64Swapped(b)
}
return currents[0], currents[1], currents[2], nil
return res[0], res[1], res[2], nil
}
var _ api.Diagnosis = (*Wallbe)(nil)

View file

@ -217,17 +217,17 @@ var _ api.PhaseCurrents = (*WebastoNext)(nil)
// Currents implements the api.PhaseCurrents interface
func (wb *WebastoNext) Currents() (float64, float64, float64, error) {
var curr [3]float64
var res [3]float64
for l := uint16(0); l < 3; l++ {
b, err := wb.conn.ReadInputRegisters(tqRegCurrents+2*l, 1)
if err != nil {
return 0, 0, 0, err
}
curr[l] = float64(binary.BigEndian.Uint16(b)) / 1e3
res[l] = float64(binary.BigEndian.Uint16(b)) / 1e3
}
return curr[0], curr[1], curr[2], nil
return res[0], res[1], res[2], nil
}
var _ api.Identifier = (*WebastoNext)(nil)

View file

@ -125,12 +125,12 @@ func (sm *SMA) Currents() (float64, float64, float64, error) {
}
}
var currents [3]float64
var res [3]float64
for i, id := range []sunny.ValueID{sunny.CurrentL1, sunny.CurrentL2, sunny.CurrentL3} {
currents[i] = util.SignFromPower(sma.AsFloat(values[id]), powers[i])
res[i] = util.SignFromPower(sma.AsFloat(values[id]), powers[i])
}
return currents[0], currents[1], currents[2], err
return res[0], res[1], res[2], err
}
var _ api.PhaseVoltages = (*SMA)(nil)
@ -139,12 +139,12 @@ var _ api.PhaseVoltages = (*SMA)(nil)
func (sm *SMA) Voltages() (float64, float64, float64, error) {
values, err := sm.device.Values()
var voltages [3]float64
var res [3]float64
for i, id := range []sunny.ValueID{sunny.VoltageL1, sunny.VoltageL2, sunny.VoltageL3} {
voltages[i] = sma.AsFloat(values[id])
res[i] = sma.AsFloat(values[id])
}
return voltages[0], voltages[1], voltages[2], err
return res[0], res[1], res[2], err
}
var _ api.PhasePowers = (*SMA)(nil)
@ -153,15 +153,15 @@ var _ api.PhasePowers = (*SMA)(nil)
func (sm *SMA) Powers() (float64, float64, float64, error) {
values, err := sm.device.Values()
var powers [3]float64
var res [3]float64
for i, id := range []sunny.ValueID{sunny.ActivePowerPlusL1, sunny.ActivePowerPlusL2, sunny.ActivePowerPlusL3} {
powers[i] = sma.AsFloat(values[id])
res[i] = sma.AsFloat(values[id])
}
for i, id := range []sunny.ValueID{sunny.ActivePowerMinusL1, sunny.ActivePowerMinusL2, sunny.ActivePowerMinusL3} {
powers[i] -= sma.AsFloat(values[id])
res[i] -= sma.AsFloat(values[id])
}
return powers[0], powers[1], powers[2], err
return res[0], res[1], res[2], err
}
// soc implements the api.Battery interface