Skip to content

Commit

Permalink
Rct change battery mode logic (#18222)
Browse files Browse the repository at this point in the history
* Update dependency

* fix BatteryCharge

* add defaults

* add comment

* change battery mode logic
  • Loading branch information
Maschga authored Jan 14, 2025
1 parent cb4d8e0 commit c085115
Showing 1 changed file with 8 additions and 13 deletions.
21 changes: 8 additions & 13 deletions meter/rct.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,37 +113,32 @@ func NewRCT(uri, usage string, minSoc, maxSoc int, cache time.Duration, capacity
batterySoc = m.batterySoc

batteryMode = func(mode api.BatteryMode) error {

Check failure on line 115 in meter/rct.go

View workflow job for this annotation

GitHub Actions / Lint

unnecessary leading newline (whitespace)

switch mode {
case api.BatteryNormal:
if err := m.conn.Write(rct.BatterySoCTargetMin, m.floatVal(float32(minSoc)/100)); err != nil {
return err
}

if err := m.conn.Write(rct.PowerMngSocCharge, m.floatVal(float32(0.05))); err != nil {
if err := m.conn.Write(rct.PowerMngSocStrategy, []byte{rct.SOCTargetInternal}); err != nil {
return err
}

if err := m.conn.Write(rct.PowerMngSocChargePowerW, m.floatVal(float32(100))); err != nil {
if err := m.conn.Write(rct.BatterySoCTargetMin, m.floatVal(float32(minSoc)/100)); err != nil {
return err
}

return m.conn.Write(rct.BatterySoCTargetMinIsland, m.floatVal(float32(minSoc)/100))
return m.conn.Write(rct.PowerMngBatteryPowerExternW, m.floatVal(float32(0)))

case api.BatteryHold:
soc, err := m.batterySoc()
if err != nil {
if err := m.conn.Write(rct.PowerMngSocStrategy, []byte{rct.SOCTargetInternal}); err != nil {
return err
}

return m.conn.Write(rct.BatterySoCTargetMin, m.floatVal(float32(soc)/100))
return m.conn.Write(rct.BatterySoCTargetMin, m.floatVal(float32(maxSoc)/100))

case api.BatteryCharge:
if err := m.conn.Write(rct.PowerMngSocChargePowerW, m.floatVal(float32(10_000))); err != nil {
if err := m.conn.Write(rct.PowerMngBatteryPowerExternW, m.floatVal(float32(-10_000))); err != nil {
return err
}

// automatically sets BatterySoCTargetMin and BatterySoCTargetMinIsland to maxsoc
return m.conn.Write(rct.PowerMngSocCharge, m.floatVal(float32(maxSoc)/100))
return m.conn.Write(rct.PowerMngSocStrategy, []byte{rct.SOCTargetExternal})

default:
return api.ErrNotAvailable
Expand Down

0 comments on commit c085115

Please sign in to comment.