Zendure: fix power and soc limits
This commit is contained in:
parent
d381e16084
commit
ce1eb43191
2 changed files with 8 additions and 64 deletions
|
|
@ -19,12 +19,12 @@ type Zendure struct {
|
|||
conn *zendure.Connection
|
||||
}
|
||||
|
||||
//go:generate go tool decorate -f decorateZendure -b *Zendure -r api.Meter -t api.Battery,api.BatteryCapacity
|
||||
|
||||
// NewZendureFromConfig creates a Zendure meter from generic config
|
||||
func NewZendureFromConfig(other map[string]any) (api.Meter, error) {
|
||||
cc := struct {
|
||||
batteryCapacity `mapstructure:",squash"`
|
||||
batteryPowerLimits `mapstructure:",squash"`
|
||||
batterySocLimits `mapstructure:",squash"`
|
||||
Usage, Account, Serial, Region string
|
||||
Timeout time.Duration
|
||||
}{
|
||||
|
|
@ -41,18 +41,20 @@ func NewZendureFromConfig(other map[string]any) (api.Meter, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
c := &Zendure{
|
||||
m := &Zendure{
|
||||
usage: cc.Usage,
|
||||
conn: conn,
|
||||
}
|
||||
|
||||
// decorate battery
|
||||
var soc func() (float64, error)
|
||||
if cc.Usage == "battery" {
|
||||
soc = c.soc
|
||||
return decorateMeterBattery(
|
||||
m, nil, m.soc, cc.batteryCapacity.Decorator(),
|
||||
cc.batterySocLimits.Decorator(), cc.batteryPowerLimits.Decorator(), nil,
|
||||
), nil
|
||||
}
|
||||
|
||||
return decorateZendure(c, soc, cc.batteryCapacity.Decorator()), nil
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// CurrentPower implements the api.Meter interface
|
||||
|
|
|
|||
|
|
@ -1,58 +0,0 @@
|
|||
package meter
|
||||
|
||||
// Code generated by github.com/evcc-io/evcc/cmd/tools/decorate.go. DO NOT EDIT.
|
||||
|
||||
import (
|
||||
"github.com/evcc-io/evcc/api"
|
||||
)
|
||||
|
||||
func decorateZendure(base *Zendure, battery func() (float64, error), batteryCapacity func() float64) api.Meter {
|
||||
switch {
|
||||
case battery == nil:
|
||||
return base
|
||||
|
||||
case battery != nil && batteryCapacity == nil:
|
||||
return &struct {
|
||||
*Zendure
|
||||
api.Battery
|
||||
}{
|
||||
Zendure: base,
|
||||
Battery: &decorateZendureBatteryImpl{
|
||||
battery: battery,
|
||||
},
|
||||
}
|
||||
|
||||
case battery != nil && batteryCapacity != nil:
|
||||
return &struct {
|
||||
*Zendure
|
||||
api.Battery
|
||||
api.BatteryCapacity
|
||||
}{
|
||||
Zendure: base,
|
||||
Battery: &decorateZendureBatteryImpl{
|
||||
battery: battery,
|
||||
},
|
||||
BatteryCapacity: &decorateZendureBatteryCapacityImpl{
|
||||
batteryCapacity: batteryCapacity,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type decorateZendureBatteryImpl struct {
|
||||
battery func() (float64, error)
|
||||
}
|
||||
|
||||
func (impl *decorateZendureBatteryImpl) Soc() (float64, error) {
|
||||
return impl.battery()
|
||||
}
|
||||
|
||||
type decorateZendureBatteryCapacityImpl struct {
|
||||
batteryCapacity func() float64
|
||||
}
|
||||
|
||||
func (impl *decorateZendureBatteryCapacityImpl) Capacity() float64 {
|
||||
return impl.batteryCapacity()
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue