30 lines
563 B
Go
30 lines
563 B
Go
package subaru
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/evcc-io/evcc/util"
|
|
)
|
|
|
|
type Provider struct {
|
|
status func() (Status, error)
|
|
}
|
|
|
|
func NewProvider(api *API, vin string, cache time.Duration) *Provider {
|
|
impl := &Provider{
|
|
status: util.Cached(func() (Status, error) {
|
|
return api.Status(vin)
|
|
}, cache),
|
|
}
|
|
return impl
|
|
}
|
|
|
|
func (v *Provider) Soc() (float64, error) {
|
|
res, err := v.status()
|
|
return float64(res.Payload.BatteryLevel), err
|
|
}
|
|
|
|
func (v *Provider) Range() (int64, error) {
|
|
res, err := v.status()
|
|
return int64(res.Payload.EvRangeWithAc.Value), err
|
|
}
|