Skip to content

Commit

Permalink
chore: minor
Browse files Browse the repository at this point in the history
  • Loading branch information
andig committed Aug 5, 2024
1 parent 314acde commit 7453d12
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions core/site_battery.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,15 @@ func (site *Site) requiredBatteryMode(batteryGridChargeActive bool, rate api.Rat
var res api.BatteryMode
batMode := site.GetBatteryMode()

mapper := func(s api.BatteryMode) api.BatteryMode {
return map[bool]api.BatteryMode{false: s, true: api.BatteryUnknown}[batMode == s]
}

switch {
case batteryGridChargeActive:
res = map[bool]api.BatteryMode{false: api.BatteryCharge, true: api.BatteryUnknown}[batMode == api.BatteryCharge]
case !batteryGridChargeActive && site.dischargeControlActive(rate) && batMode != api.BatteryHold:
res = api.BatteryHold
res = mapper(api.BatteryCharge)
case site.dischargeControlActive(rate):
res = mapper(api.BatteryHold)
case batteryModeModified(batMode):
res = api.BatteryNormal
}
Expand Down

0 comments on commit 7453d12

Please sign in to comment.