Skip to content

Commit

Permalink
Add CoarseCurrent feature for vehicles that can't follow mA charging (e…
Browse files Browse the repository at this point in the history
  • Loading branch information
andig authored Oct 5, 2022
1 parent 85d0117 commit 6e943a0
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 21 deletions.
1 change: 1 addition & 0 deletions api/feature.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ func (f *Feature) UnmarshalText(text []byte) error {
const (
_ Feature = iota
Offline
CoarseCurrent
)
16 changes: 10 additions & 6 deletions api/feature_enumer.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 10 additions & 10 deletions core/loadpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,7 @@ func (lp *LoadPoint) setLimit(chargeCurrent float64, force bool) error {
// set current
if chargeCurrent != lp.chargeCurrent && chargeCurrent >= lp.GetMinCurrent() {
var err error
if charger, ok := lp.charger.(api.ChargerEx); ok {
if charger, ok := lp.charger.(api.ChargerEx); ok && !lp.vehicleHasFeature(api.CoarseCurrent) {
err = charger.MaxCurrentMillis(chargeCurrent)
} else {
chargeCurrent = math.Trunc(chargeCurrent)
Expand Down Expand Up @@ -697,12 +697,7 @@ func (lp *LoadPoint) setStatus(status api.ChargeStatus) {

// targetEnergyReached checks if target is configured and reached
func (lp *LoadPoint) targetEnergyReached() bool {
v, ok := lp.vehicle.(api.FeatureDescriber)
if ok {
ok = v.Has(api.Offline)
}

return (v == nil || ok) &&
return (lp.vehicle == nil || lp.vehicleHasFeature(api.Offline)) &&
lp.targetEnergy > 0 &&
lp.chargedEnergy/1e3 >= float64(lp.targetEnergy)
}
Expand Down Expand Up @@ -941,13 +936,18 @@ func (lp *LoadPoint) unpublishVehicle() {
lp.vehiclePublishFeature(api.Offline)
}

// vehiclePublishFeature availability of vehicle features
func (lp *LoadPoint) vehiclePublishFeature(f api.Feature) {
// vehicleHasFeature checks availability of vehicle feature
func (lp *LoadPoint) vehicleHasFeature(f api.Feature) bool {
v, ok := lp.vehicle.(api.FeatureDescriber)
if ok {
ok = v.Has(f)
}
lp.publish("vehicleFeature"+f.String(), ok)
return ok
}

// vehiclePublishFeature availability of vehicle features
func (lp *LoadPoint) vehiclePublishFeature(f api.Feature) {
lp.publish("vehicleFeature"+f.String(), lp.vehicleHasFeature(f))
}

// vehicleUnidentified returns true if there are associated vehicles and detection is running.
Expand Down
9 changes: 4 additions & 5 deletions core/loadpoint_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,10 @@ func (lp *LoadPoint) GetTargetEnergy() int {
// setTargetEnergy sets loadpoint charge target energy (no mutex)
func (lp *LoadPoint) setTargetEnergy(energy int) {
lp.targetEnergy = energy
// test guard
if lp.socTimer != nil {
// TODO soctimer
// lp.socTimer.Energy = energy
}
// TODO soctimer
// if lp.socTimer != nil {
// lp.socTimer.Energy = energy
// }
lp.publish("targetEnergy", energy)
}

Expand Down

0 comments on commit 6e943a0

Please sign in to comment.