chore: refactor plugin structure (#18335)
This commit is contained in:
parent
9127e1a913
commit
07fa1b64f8
127 changed files with 861 additions and 938 deletions
|
|
@ -7,7 +7,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/evcc-io/evcc/api"
|
"github.com/evcc-io/evcc/api"
|
||||||
"github.com/evcc-io/evcc/provider/mqtt"
|
"github.com/evcc-io/evcc/plugin/mqtt"
|
||||||
"github.com/evcc-io/evcc/push"
|
"github.com/evcc-io/evcc/push"
|
||||||
"github.com/evcc-io/evcc/server/eebus"
|
"github.com/evcc-io/evcc/server/eebus"
|
||||||
"github.com/evcc-io/evcc/util/config"
|
"github.com/evcc-io/evcc/util/config"
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ import (
|
||||||
|
|
||||||
"github.com/evcc-io/evcc/api"
|
"github.com/evcc-io/evcc/api"
|
||||||
"github.com/evcc-io/evcc/meter"
|
"github.com/evcc-io/evcc/meter"
|
||||||
"github.com/evcc-io/evcc/provider"
|
"github.com/evcc-io/evcc/plugin"
|
||||||
"github.com/evcc-io/evcc/util"
|
"github.com/evcc-io/evcc/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -30,40 +30,40 @@ func init() {
|
||||||
func NewConfigurableFromConfig(ctx context.Context, other map[string]interface{}) (api.Charger, error) {
|
func NewConfigurableFromConfig(ctx context.Context, other map[string]interface{}) (api.Charger, error) {
|
||||||
var cc struct {
|
var cc struct {
|
||||||
embed `mapstructure:",squash"`
|
embed `mapstructure:",squash"`
|
||||||
Status, Enable, Enabled, MaxCurrent provider.Config
|
Status, Enable, Enabled, MaxCurrent plugin.Config
|
||||||
MaxCurrentMillis *provider.Config
|
MaxCurrentMillis *plugin.Config
|
||||||
Identify, Phases1p3p *provider.Config
|
Identify, Phases1p3p *plugin.Config
|
||||||
Wakeup *provider.Config
|
Wakeup *plugin.Config
|
||||||
Soc *provider.Config
|
Soc *plugin.Config
|
||||||
Tos bool
|
Tos bool
|
||||||
|
|
||||||
// optional measurements
|
// optional measurements
|
||||||
Power *provider.Config
|
Power *plugin.Config
|
||||||
Energy *provider.Config
|
Energy *plugin.Config
|
||||||
|
|
||||||
Currents, Voltages []provider.Config
|
Currents, Voltages []plugin.Config
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := util.DecodeOther(other, &cc); err != nil {
|
if err := util.DecodeOther(other, &cc); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
status, err := provider.NewStringGetterFromConfig(ctx, cc.Status)
|
status, err := cc.Status.StringGetter(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("status: %w", err)
|
return nil, fmt.Errorf("status: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
enabled, err := provider.NewBoolGetterFromConfig(ctx, cc.Enabled)
|
enabled, err := cc.Enabled.BoolGetter(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("enabled: %w", err)
|
return nil, fmt.Errorf("enabled: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
enable, err := provider.NewBoolSetterFromConfig(ctx, "enable", cc.Enable)
|
enable, err := cc.Enable.BoolSetter(ctx, "enable")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("enable: %w", err)
|
return nil, fmt.Errorf("enable: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
maxcurrent, err := provider.NewIntSetterFromConfig(ctx, "maxcurrent", cc.MaxCurrent)
|
maxcurrent, err := cc.MaxCurrent.IntSetter(ctx, "maxcurrent")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("maxcurrent: %w", err)
|
return nil, fmt.Errorf("maxcurrent: %w", err)
|
||||||
}
|
}
|
||||||
|
|
@ -75,12 +75,9 @@ func NewConfigurableFromConfig(ctx context.Context, other map[string]interface{}
|
||||||
|
|
||||||
c.embed = &cc.embed
|
c.embed = &cc.embed
|
||||||
|
|
||||||
var maxcurrentmillis func(float64) error
|
maxcurrentmillis, err := cc.MaxCurrentMillis.FloatSetter(ctx, "maxcurrentmillis")
|
||||||
if cc.MaxCurrentMillis != nil {
|
if err != nil {
|
||||||
maxcurrentmillis, err = provider.NewFloatSetterFromConfig(ctx, "maxcurrentmillis", *cc.MaxCurrentMillis)
|
return nil, fmt.Errorf("maxcurrentmillis: %w", err)
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("maxcurrentmillis: %w", err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// decorate phases
|
// decorate phases
|
||||||
|
|
@ -90,7 +87,7 @@ func NewConfigurableFromConfig(ctx context.Context, other map[string]interface{}
|
||||||
return nil, errors.New("1p3p does no longer handle disable/enable. Use tos: true to confirm you understand the consequences")
|
return nil, errors.New("1p3p does no longer handle disable/enable. Use tos: true to confirm you understand the consequences")
|
||||||
}
|
}
|
||||||
|
|
||||||
phases1p3pS, err := provider.NewIntSetterFromConfig(ctx, "phases", *cc.Phases1p3p)
|
phases1p3pS, err := cc.Phases1p3p.IntSetter(ctx, "phases")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("phases: %w", err)
|
return nil, fmt.Errorf("phases: %w", err)
|
||||||
}
|
}
|
||||||
|
|
@ -101,34 +98,28 @@ func NewConfigurableFromConfig(ctx context.Context, other map[string]interface{}
|
||||||
}
|
}
|
||||||
|
|
||||||
// decorate identifier
|
// decorate identifier
|
||||||
var identify func() (string, error)
|
identify, err := cc.Identify.StringGetter(ctx)
|
||||||
if cc.Identify != nil {
|
if err != nil {
|
||||||
identify, err = provider.NewStringGetterFromConfig(ctx, *cc.Identify)
|
return nil, fmt.Errorf("identify: %w", err)
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("identify: %w", err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// decorate wakeup
|
// decorate wakeup
|
||||||
var wakeup func() error
|
var wakeup func() error
|
||||||
if cc.Wakeup != nil {
|
if cc.Wakeup != nil {
|
||||||
wakeupS, err := provider.NewBoolSetterFromConfig(ctx, "wakeup", *cc.Wakeup)
|
set, err := cc.Wakeup.BoolSetter(ctx, "wakeup")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("wakeup: %w", err)
|
return nil, fmt.Errorf("wakeup: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
wakeup = func() error {
|
wakeup = func() error {
|
||||||
return wakeupS(true)
|
return set(true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// decorate soc
|
// decorate soc
|
||||||
var soc func() (float64, error)
|
soc, err := cc.Soc.FloatGetter(ctx)
|
||||||
if cc.Soc != nil {
|
if err != nil {
|
||||||
soc, err = provider.NewFloatGetterFromConfig(ctx, *cc.Soc)
|
return nil, fmt.Errorf("soc: %w", err)
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("soc: %w", err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// decorate measurements
|
// decorate measurements
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ import (
|
||||||
|
|
||||||
"github.com/evcc-io/evcc/api"
|
"github.com/evcc-io/evcc/api"
|
||||||
"github.com/evcc-io/evcc/charger/connectiq"
|
"github.com/evcc-io/evcc/charger/connectiq"
|
||||||
"github.com/evcc-io/evcc/provider"
|
"github.com/evcc-io/evcc/plugin"
|
||||||
"github.com/evcc-io/evcc/util"
|
"github.com/evcc-io/evcc/util"
|
||||||
"github.com/evcc-io/evcc/util/request"
|
"github.com/evcc-io/evcc/util/request"
|
||||||
)
|
)
|
||||||
|
|
@ -71,7 +71,7 @@ func NewConnectIq(uri string, cache time.Duration) (api.Charger, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// cache meter readings
|
// cache meter readings
|
||||||
wb.meterG = provider.Cached(func() (connectiq.MeterStatus, error) {
|
wb.meterG = plugin.Cached(func() (connectiq.MeterStatus, error) {
|
||||||
var res connectiq.MeterStatus
|
var res connectiq.MeterStatus
|
||||||
uri := fmt.Sprintf("%s/meter/status", wb.uri)
|
uri := fmt.Sprintf("%s/meter/status", wb.uri)
|
||||||
err := wb.GetJSON(uri, &res)
|
err := wb.GetJSON(uri, &res)
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ import (
|
||||||
|
|
||||||
"github.com/evcc-io/evcc/api"
|
"github.com/evcc-io/evcc/api"
|
||||||
"github.com/evcc-io/evcc/charger/daheimladen"
|
"github.com/evcc-io/evcc/charger/daheimladen"
|
||||||
"github.com/evcc-io/evcc/provider"
|
"github.com/evcc-io/evcc/plugin"
|
||||||
"github.com/evcc-io/evcc/util"
|
"github.com/evcc-io/evcc/util"
|
||||||
"github.com/evcc-io/evcc/util/request"
|
"github.com/evcc-io/evcc/util/request"
|
||||||
"golang.org/x/oauth2"
|
"golang.org/x/oauth2"
|
||||||
|
|
@ -22,8 +22,8 @@ type DaheimLaden struct {
|
||||||
idTag string
|
idTag string
|
||||||
token string
|
token string
|
||||||
transactionID int32
|
transactionID int32
|
||||||
statusG provider.Cacheable[daheimladen.GetLatestStatus]
|
statusG plugin.Cacheable[daheimladen.GetLatestStatus]
|
||||||
meterG provider.Cacheable[daheimladen.GetLatestMeterValueResponse]
|
meterG plugin.Cacheable[daheimladen.GetLatestMeterValueResponse]
|
||||||
cache time.Duration
|
cache time.Duration
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -67,13 +67,13 @@ func NewDaheimLaden(token, stationID string, cache time.Duration) (*DaheimLaden,
|
||||||
Base: c.Client.Transport,
|
Base: c.Client.Transport,
|
||||||
}
|
}
|
||||||
|
|
||||||
c.statusG = provider.ResettableCached(func() (daheimladen.GetLatestStatus, error) {
|
c.statusG = plugin.ResettableCached(func() (daheimladen.GetLatestStatus, error) {
|
||||||
var res daheimladen.GetLatestStatus
|
var res daheimladen.GetLatestStatus
|
||||||
err := c.GetJSON(fmt.Sprintf("%s/cs/%s/status", daheimladen.BASE_URL, c.stationID), &res)
|
err := c.GetJSON(fmt.Sprintf("%s/cs/%s/status", daheimladen.BASE_URL, c.stationID), &res)
|
||||||
return res, err
|
return res, err
|
||||||
}, c.cache)
|
}, c.cache)
|
||||||
|
|
||||||
c.meterG = provider.ResettableCached(func() (daheimladen.GetLatestMeterValueResponse, error) {
|
c.meterG = plugin.ResettableCached(func() (daheimladen.GetLatestMeterValueResponse, error) {
|
||||||
var res daheimladen.GetLatestMeterValueResponse
|
var res daheimladen.GetLatestMeterValueResponse
|
||||||
err := c.GetJSON(fmt.Sprintf("%s/cs/%s/metervalue", daheimladen.BASE_URL, c.stationID), &res)
|
err := c.GetJSON(fmt.Sprintf("%s/cs/%s/metervalue", daheimladen.BASE_URL, c.stationID), &res)
|
||||||
return res, err
|
return res, err
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ import (
|
||||||
"github.com/enbility/spine-go/model"
|
"github.com/enbility/spine-go/model"
|
||||||
"github.com/evcc-io/evcc/api"
|
"github.com/evcc-io/evcc/api"
|
||||||
"github.com/evcc-io/evcc/core/loadpoint"
|
"github.com/evcc-io/evcc/core/loadpoint"
|
||||||
"github.com/evcc-io/evcc/provider"
|
"github.com/evcc-io/evcc/plugin"
|
||||||
"github.com/evcc-io/evcc/server/eebus"
|
"github.com/evcc-io/evcc/server/eebus"
|
||||||
"github.com/evcc-io/evcc/util"
|
"github.com/evcc-io/evcc/util"
|
||||||
"github.com/samber/lo"
|
"github.com/samber/lo"
|
||||||
|
|
@ -88,7 +88,7 @@ func NewEEBus(ski, ip string, hasMeter, hasChargedEnergy, vasVW bool) (api.Charg
|
||||||
}
|
}
|
||||||
|
|
||||||
c.Connector = eebus.NewConnector()
|
c.Connector = eebus.NewConnector()
|
||||||
c.minMaxG = provider.Cached(c.minMax, time.Second)
|
c.minMaxG = plugin.Cached(c.minMax, time.Second)
|
||||||
|
|
||||||
if err := eebus.Instance.RegisterDevice(ski, ip, c); err != nil {
|
if err := eebus.Instance.RegisterDevice(ski, ip, c); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ import (
|
||||||
|
|
||||||
"github.com/evcc-io/evcc/api"
|
"github.com/evcc-io/evcc/api"
|
||||||
"github.com/evcc-io/evcc/charger/evse"
|
"github.com/evcc-io/evcc/charger/evse"
|
||||||
"github.com/evcc-io/evcc/provider"
|
"github.com/evcc-io/evcc/plugin"
|
||||||
"github.com/evcc-io/evcc/util"
|
"github.com/evcc-io/evcc/util"
|
||||||
"github.com/evcc-io/evcc/util/request"
|
"github.com/evcc-io/evcc/util/request"
|
||||||
)
|
)
|
||||||
|
|
@ -20,7 +20,7 @@ type EVSEWifi struct {
|
||||||
alwaysActive bool
|
alwaysActive bool
|
||||||
current int64 // current will always be the physical value sent to the API
|
current int64 // current will always be the physical value sent to the API
|
||||||
hires bool
|
hires bool
|
||||||
paramG provider.Cacheable[evse.ListEntry]
|
paramG plugin.Cacheable[evse.ListEntry]
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
|
@ -122,7 +122,7 @@ func NewEVSEWifi(uri string, cache time.Duration) (*EVSEWifi, error) {
|
||||||
current: 6, // 6A defined value
|
current: 6, // 6A defined value
|
||||||
}
|
}
|
||||||
|
|
||||||
wb.paramG = provider.ResettableCached(func() (evse.ListEntry, error) {
|
wb.paramG = plugin.ResettableCached(func() (evse.ListEntry, error) {
|
||||||
var res evse.ParameterResponse
|
var res evse.ParameterResponse
|
||||||
uri := fmt.Sprintf("%s/getParameters", wb.uri)
|
uri := fmt.Sprintf("%s/getParameters", wb.uri)
|
||||||
if err := wb.GetJSON(uri, &res); err != nil {
|
if err := wb.GetJSON(uri, &res); err != nil {
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ import (
|
||||||
"github.com/evcc-io/evcc/charger/echarge"
|
"github.com/evcc-io/evcc/charger/echarge"
|
||||||
"github.com/evcc-io/evcc/charger/echarge/ecb1"
|
"github.com/evcc-io/evcc/charger/echarge/ecb1"
|
||||||
"github.com/evcc-io/evcc/meter/obis"
|
"github.com/evcc-io/evcc/meter/obis"
|
||||||
"github.com/evcc-io/evcc/provider"
|
"github.com/evcc-io/evcc/plugin"
|
||||||
"github.com/evcc-io/evcc/util"
|
"github.com/evcc-io/evcc/util"
|
||||||
"github.com/evcc-io/evcc/util/request"
|
"github.com/evcc-io/evcc/util/request"
|
||||||
"github.com/evcc-io/evcc/util/sponsor"
|
"github.com/evcc-io/evcc/util/sponsor"
|
||||||
|
|
@ -85,7 +85,7 @@ func NewHardyBarth(uri string, chargecontrol, meter int, cache time.Duration) (a
|
||||||
}
|
}
|
||||||
|
|
||||||
// cache meter readings
|
// cache meter readings
|
||||||
wb.meterG = provider.Cached(func() (ecb1.Meter, error) {
|
wb.meterG = plugin.Cached(func() (ecb1.Meter, error) {
|
||||||
var res struct {
|
var res struct {
|
||||||
Meter struct {
|
Meter struct {
|
||||||
ecb1.Meter
|
ecb1.Meter
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ import (
|
||||||
"github.com/evcc-io/evcc/api"
|
"github.com/evcc-io/evcc/api"
|
||||||
"github.com/evcc-io/evcc/charger/echarge"
|
"github.com/evcc-io/evcc/charger/echarge"
|
||||||
"github.com/evcc-io/evcc/charger/echarge/salia"
|
"github.com/evcc-io/evcc/charger/echarge/salia"
|
||||||
"github.com/evcc-io/evcc/provider"
|
"github.com/evcc-io/evcc/plugin"
|
||||||
"github.com/evcc-io/evcc/util"
|
"github.com/evcc-io/evcc/util"
|
||||||
"github.com/evcc-io/evcc/util/request"
|
"github.com/evcc-io/evcc/util/request"
|
||||||
"github.com/evcc-io/evcc/util/sponsor"
|
"github.com/evcc-io/evcc/util/sponsor"
|
||||||
|
|
@ -46,7 +46,7 @@ type Salia struct {
|
||||||
uri string
|
uri string
|
||||||
current int64
|
current int64
|
||||||
fw int // 2 if fw 2.0
|
fw int // 2 if fw 2.0
|
||||||
apiG provider.Cacheable[salia.Api]
|
apiG plugin.Cacheable[salia.Api]
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
|
@ -84,7 +84,7 @@ func NewSalia(ctx context.Context, uri string, cache time.Duration) (api.Charger
|
||||||
current: 6,
|
current: 6,
|
||||||
}
|
}
|
||||||
|
|
||||||
wb.apiG = provider.ResettableCached(func() (salia.Api, error) {
|
wb.apiG = plugin.ResettableCached(func() (salia.Api, error) {
|
||||||
var res salia.Api
|
var res salia.Api
|
||||||
err := wb.GetJSON(wb.uri, &res)
|
err := wb.GetJSON(wb.uri, &res)
|
||||||
return res, err
|
return res, err
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ import (
|
||||||
|
|
||||||
"github.com/evcc-io/evcc/api"
|
"github.com/evcc-io/evcc/api"
|
||||||
"github.com/evcc-io/evcc/meter/mystrom"
|
"github.com/evcc-io/evcc/meter/mystrom"
|
||||||
"github.com/evcc-io/evcc/provider"
|
"github.com/evcc-io/evcc/plugin"
|
||||||
"github.com/evcc-io/evcc/util"
|
"github.com/evcc-io/evcc/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -21,7 +21,7 @@ func init() {
|
||||||
type MyStrom struct {
|
type MyStrom struct {
|
||||||
*switchSocket
|
*switchSocket
|
||||||
conn *mystrom.Connection
|
conn *mystrom.Connection
|
||||||
reportG provider.Cacheable[mystrom.Report]
|
reportG plugin.Cacheable[mystrom.Report]
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewMyStromFromConfig creates a myStrom charger from generic config
|
// NewMyStromFromConfig creates a myStrom charger from generic config
|
||||||
|
|
@ -44,7 +44,7 @@ func NewMyStromFromConfig(other map[string]interface{}) (api.Charger, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
c.switchSocket = NewSwitchSocket(&cc.embed, c.Enabled, c.conn.CurrentPower, cc.StandbyPower)
|
c.switchSocket = NewSwitchSocket(&cc.embed, c.Enabled, c.conn.CurrentPower, cc.StandbyPower)
|
||||||
c.reportG = provider.ResettableCached(c.conn.Report, cc.Cache)
|
c.reportG = plugin.ResettableCached(c.conn.Report, cc.Cache)
|
||||||
|
|
||||||
return c, nil
|
return c, nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ import (
|
||||||
|
|
||||||
"github.com/evcc-io/evcc/api"
|
"github.com/evcc-io/evcc/api"
|
||||||
"github.com/evcc-io/evcc/charger/nrg/connect"
|
"github.com/evcc-io/evcc/charger/nrg/connect"
|
||||||
"github.com/evcc-io/evcc/provider"
|
"github.com/evcc-io/evcc/plugin"
|
||||||
"github.com/evcc-io/evcc/util"
|
"github.com/evcc-io/evcc/util"
|
||||||
"github.com/evcc-io/evcc/util/request"
|
"github.com/evcc-io/evcc/util/request"
|
||||||
)
|
)
|
||||||
|
|
@ -23,8 +23,8 @@ type NRGKickConnect struct {
|
||||||
mac string
|
mac string
|
||||||
password string
|
password string
|
||||||
enabled bool
|
enabled bool
|
||||||
settingsG provider.Cacheable[connect.Settings]
|
settingsG plugin.Cacheable[connect.Settings]
|
||||||
measurementsG provider.Cacheable[connect.Measurements]
|
measurementsG plugin.Cacheable[connect.Measurements]
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
|
@ -56,7 +56,7 @@ func NewNRGKickConnect(uri, mac, password string, cache time.Duration) (*NRGKick
|
||||||
password: password,
|
password: password,
|
||||||
}
|
}
|
||||||
|
|
||||||
nrg.settingsG = provider.ResettableCached(func() (connect.Settings, error) {
|
nrg.settingsG = plugin.ResettableCached(func() (connect.Settings, error) {
|
||||||
var res connect.Settings
|
var res connect.Settings
|
||||||
|
|
||||||
err := nrg.GetJSON(nrg.apiURL(connect.SettingsPath), &res)
|
err := nrg.GetJSON(nrg.apiURL(connect.SettingsPath), &res)
|
||||||
|
|
@ -67,7 +67,7 @@ func NewNRGKickConnect(uri, mac, password string, cache time.Duration) (*NRGKick
|
||||||
return res, err
|
return res, err
|
||||||
}, cache)
|
}, cache)
|
||||||
|
|
||||||
nrg.measurementsG = provider.ResettableCached(func() (connect.Measurements, error) {
|
nrg.measurementsG = plugin.ResettableCached(func() (connect.Measurements, error) {
|
||||||
var res connect.Measurements
|
var res connect.Measurements
|
||||||
|
|
||||||
err := nrg.GetJSON(nrg.apiURL(connect.MeasurementsPath), &res)
|
err := nrg.GetJSON(nrg.apiURL(connect.MeasurementsPath), &res)
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ import (
|
||||||
|
|
||||||
"github.com/evcc-io/evcc/api"
|
"github.com/evcc-io/evcc/api"
|
||||||
"github.com/evcc-io/evcc/charger/openevse"
|
"github.com/evcc-io/evcc/charger/openevse"
|
||||||
"github.com/evcc-io/evcc/provider"
|
"github.com/evcc-io/evcc/plugin"
|
||||||
"github.com/evcc-io/evcc/util"
|
"github.com/evcc-io/evcc/util"
|
||||||
"github.com/evcc-io/evcc/util/request"
|
"github.com/evcc-io/evcc/util/request"
|
||||||
"github.com/evcc-io/evcc/util/transport"
|
"github.com/evcc-io/evcc/util/transport"
|
||||||
|
|
@ -20,7 +20,7 @@ import (
|
||||||
type OpenEVSE struct {
|
type OpenEVSE struct {
|
||||||
*request.Helper
|
*request.Helper
|
||||||
uri string
|
uri string
|
||||||
statusG provider.Cacheable[openevse.Status]
|
statusG plugin.Cacheable[openevse.Status]
|
||||||
current int
|
current int
|
||||||
enabled bool
|
enabled bool
|
||||||
}
|
}
|
||||||
|
|
@ -67,7 +67,7 @@ func NewOpenEVSE(uri, user, password string, cache time.Duration) (api.Charger,
|
||||||
c.Client.Transport = transport.BasicAuth(user, password, c.Client.Transport)
|
c.Client.Transport = transport.BasicAuth(user, password, c.Client.Transport)
|
||||||
}
|
}
|
||||||
|
|
||||||
c.statusG = provider.ResettableCached(func() (openevse.Status, error) {
|
c.statusG = plugin.ResettableCached(func() (openevse.Status, error) {
|
||||||
var res openevse.Status
|
var res openevse.Status
|
||||||
|
|
||||||
uri := fmt.Sprintf("%s/status", c.uri)
|
uri := fmt.Sprintf("%s/status", c.uri)
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ import (
|
||||||
|
|
||||||
"github.com/evcc-io/evcc/api"
|
"github.com/evcc-io/evcc/api"
|
||||||
"github.com/evcc-io/evcc/charger/openwb/pro"
|
"github.com/evcc-io/evcc/charger/openwb/pro"
|
||||||
"github.com/evcc-io/evcc/provider"
|
"github.com/evcc-io/evcc/plugin"
|
||||||
"github.com/evcc-io/evcc/util"
|
"github.com/evcc-io/evcc/util"
|
||||||
"github.com/evcc-io/evcc/util/request"
|
"github.com/evcc-io/evcc/util/request"
|
||||||
)
|
)
|
||||||
|
|
@ -24,7 +24,7 @@ type OpenWBPro struct {
|
||||||
*request.Helper
|
*request.Helper
|
||||||
uri string
|
uri string
|
||||||
current float64
|
current float64
|
||||||
statusG provider.Cacheable[pro.Status]
|
statusG plugin.Cacheable[pro.Status]
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewOpenWBProFromConfig creates a OpenWBPro charger from generic config
|
// NewOpenWBProFromConfig creates a OpenWBPro charger from generic config
|
||||||
|
|
@ -53,7 +53,7 @@ func NewOpenWBPro(ctx context.Context, uri string, cache time.Duration) (*OpenWB
|
||||||
current: 6, // 6A defined value
|
current: 6, // 6A defined value
|
||||||
}
|
}
|
||||||
|
|
||||||
wb.statusG = provider.ResettableCached(func() (pro.Status, error) {
|
wb.statusG = plugin.ResettableCached(func() (pro.Status, error) {
|
||||||
var res pro.Status
|
var res pro.Status
|
||||||
uri := fmt.Sprintf("%s/%s", wb.uri, "connect.php")
|
uri := fmt.Sprintf("%s/%s", wb.uri, "connect.php")
|
||||||
err := wb.GetJSON(uri, &res)
|
err := wb.GetJSON(uri, &res)
|
||||||
|
|
|
||||||
|
|
@ -8,8 +8,8 @@ import (
|
||||||
|
|
||||||
"github.com/evcc-io/evcc/api"
|
"github.com/evcc-io/evcc/api"
|
||||||
"github.com/evcc-io/evcc/charger/openwb"
|
"github.com/evcc-io/evcc/charger/openwb"
|
||||||
"github.com/evcc-io/evcc/provider"
|
"github.com/evcc-io/evcc/plugin"
|
||||||
"github.com/evcc-io/evcc/provider/mqtt"
|
"github.com/evcc-io/evcc/plugin/mqtt"
|
||||||
"github.com/evcc-io/evcc/util"
|
"github.com/evcc-io/evcc/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -63,18 +63,18 @@ func NewOpenWB(log *util.Logger, mqttconf mqtt.Config, id int, topic string, p1p
|
||||||
}
|
}
|
||||||
|
|
||||||
// timeout handler
|
// timeout handler
|
||||||
h, err := provider.NewMqtt(log, client, fmt.Sprintf("%s/system/%s", topic, openwb.TimestampTopic), timeout).StringGetter()
|
h, err := plugin.NewMqtt(log, client, fmt.Sprintf("%s/system/%s", topic, openwb.TimestampTopic), timeout).StringGetter()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
to := provider.NewTimeoutHandler(h)
|
to := plugin.NewTimeoutHandler(h)
|
||||||
|
|
||||||
mq := func(subtopic string) *provider.Mqtt {
|
mq := func(subtopic string) *plugin.Mqtt {
|
||||||
return provider.NewMqtt(log, client, fmt.Sprintf("%s/lp/%d/%s", topic, id, subtopic), 0)
|
return plugin.NewMqtt(log, client, fmt.Sprintf("%s/lp/%d/%s", topic, id, subtopic), 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if loadpoint configured
|
// check if loadpoint configured
|
||||||
configured, err := provider.NewMqtt(log, client, fmt.Sprintf("%s/lp/%d/%s", topic, id, openwb.ConfiguredTopic), timeout).BoolGetter()
|
configured, err := plugin.NewMqtt(log, client, fmt.Sprintf("%s/lp/%d/%s", topic, id, openwb.ConfiguredTopic), timeout).BoolGetter()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
@ -91,7 +91,7 @@ func NewOpenWB(log *util.Logger, mqttconf mqtt.Config, id int, topic string, p1p
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
statusG, err := provider.NewCombinedProvider(pluggedG, chargingG).StringGetter()
|
statusG, err := plugin.NewCombinedPlugin(pluggedG, chargingG).StringGetter()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
@ -102,7 +102,7 @@ func NewOpenWB(log *util.Logger, mqttconf mqtt.Config, id int, topic string, p1p
|
||||||
// TODO remove after https://github.com/snaptec/openWB/issues/1757
|
// TODO remove after https://github.com/snaptec/openWB/issues/1757
|
||||||
currentTopic = "Lp2" + openwb.SlaveChargeCurrentTopic
|
currentTopic = "Lp2" + openwb.SlaveChargeCurrentTopic
|
||||||
}
|
}
|
||||||
currentS, err := provider.NewMqtt(log, client, fmt.Sprintf("%s/set/isss/%s", topic, currentTopic),
|
currentS, err := plugin.NewMqtt(log, client, fmt.Sprintf("%s/set/isss/%s", topic, currentTopic),
|
||||||
timeout).WithRetained().IntSetter("current")
|
timeout).WithRetained().IntSetter("current")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
@ -113,13 +113,13 @@ func NewOpenWB(log *util.Logger, mqttconf mqtt.Config, id int, topic string, p1p
|
||||||
// TODO remove after https://github.com/snaptec/openWB/issues/1757
|
// TODO remove after https://github.com/snaptec/openWB/issues/1757
|
||||||
cpTopic = strings.TrimSuffix(cpTopic, "1") + "2"
|
cpTopic = strings.TrimSuffix(cpTopic, "1") + "2"
|
||||||
}
|
}
|
||||||
wakeupS, err := provider.NewMqtt(log, client, fmt.Sprintf("%s/set/isss/%s", topic, cpTopic),
|
wakeupS, err := plugin.NewMqtt(log, client, fmt.Sprintf("%s/set/isss/%s", topic, cpTopic),
|
||||||
timeout).WithRetained().IntSetter("cp")
|
timeout).WithRetained().IntSetter("cp")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
authS, err := provider.NewMqtt(log, client, fmt.Sprintf("%s/set/chargepoint/%d/set/%s", topic, id, openwb.RfidTopic),
|
authS, err := plugin.NewMqtt(log, client, fmt.Sprintf("%s/set/chargepoint/%d/set/%s", topic, id, openwb.RfidTopic),
|
||||||
timeout).WithRetained().StringSetter("rfid")
|
timeout).WithRetained().StringSetter("rfid")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
@ -155,7 +155,7 @@ func NewOpenWB(log *util.Logger, mqttconf mqtt.Config, id int, topic string, p1p
|
||||||
}
|
}
|
||||||
|
|
||||||
// heartbeat
|
// heartbeat
|
||||||
heartbeatS, err := provider.NewMqtt(log, client, fmt.Sprintf("%s/set/isss/%s", topic, openwb.SlaveHeartbeatTopic),
|
heartbeatS, err := plugin.NewMqtt(log, client, fmt.Sprintf("%s/set/isss/%s", topic, openwb.SlaveHeartbeatTopic),
|
||||||
timeout).WithRetained().IntSetter("heartbeat")
|
timeout).WithRetained().IntSetter("heartbeat")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
@ -178,7 +178,7 @@ func NewOpenWB(log *util.Logger, mqttconf mqtt.Config, id int, topic string, p1p
|
||||||
// TODO remove after https://github.com/snaptec/openWB/issues/1757
|
// TODO remove after https://github.com/snaptec/openWB/issues/1757
|
||||||
phasesTopic += "Lp2"
|
phasesTopic += "Lp2"
|
||||||
}
|
}
|
||||||
phasesS, err := provider.NewMqtt(log, client, fmt.Sprintf("%s/set/isss/%s", topic, phasesTopic),
|
phasesS, err := plugin.NewMqtt(log, client, fmt.Sprintf("%s/set/isss/%s", topic, phasesTopic),
|
||||||
timeout).WithRetained().IntSetter("phases")
|
timeout).WithRetained().IntSetter("phases")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/evcc-io/evcc/api"
|
"github.com/evcc-io/evcc/api"
|
||||||
"github.com/evcc-io/evcc/provider"
|
"github.com/evcc-io/evcc/plugin"
|
||||||
"github.com/evcc-io/evcc/util"
|
"github.com/evcc-io/evcc/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -54,13 +54,13 @@ const (
|
||||||
func NewSgReadyFromConfig(ctx context.Context, other map[string]interface{}) (api.Charger, error) {
|
func NewSgReadyFromConfig(ctx context.Context, other map[string]interface{}) (api.Charger, error) {
|
||||||
cc := struct {
|
cc := struct {
|
||||||
embed `mapstructure:",squash"`
|
embed `mapstructure:",squash"`
|
||||||
SetMode provider.Config
|
SetMode plugin.Config
|
||||||
GetMode *provider.Config // optional
|
GetMode *plugin.Config // optional
|
||||||
MaxPower *provider.Config // optional
|
MaxPower *plugin.Config // optional
|
||||||
Power *provider.Config // optional
|
Power *plugin.Config // optional
|
||||||
Energy *provider.Config // optional
|
Energy *plugin.Config // optional
|
||||||
Temp *provider.Config // optional
|
Temp *plugin.Config // optional
|
||||||
LimitTemp *provider.Config // optional
|
LimitTemp *plugin.Config // optional
|
||||||
Phases int
|
Phases int
|
||||||
}{
|
}{
|
||||||
embed: embed{
|
embed: embed{
|
||||||
|
|
@ -74,25 +74,19 @@ func NewSgReadyFromConfig(ctx context.Context, other map[string]interface{}) (ap
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
set, err := provider.NewIntSetterFromConfig(ctx, "mode", cc.SetMode)
|
set, err := cc.SetMode.IntSetter(ctx, "mode")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
var get func() (int64, error)
|
get, err := cc.GetMode.IntGetter(ctx)
|
||||||
if cc.GetMode != nil {
|
if err != nil {
|
||||||
get, err = provider.NewIntGetterFromConfig(ctx, *cc.GetMode)
|
return nil, err
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var maxPower func(int64) error
|
maxPower, err := cc.MaxPower.IntSetter(ctx, "maxpower")
|
||||||
if cc.MaxPower != nil {
|
if err != nil {
|
||||||
maxPower, err = provider.NewIntSetterFromConfig(ctx, "maxpower", *cc.MaxPower)
|
return nil, err
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
res, err := NewSgReady(ctx, &cc.embed, set, get, maxPower, cc.Phases)
|
res, err := NewSgReady(ctx, &cc.embed, set, get, maxPower, cc.Phases)
|
||||||
|
|
@ -101,38 +95,26 @@ func NewSgReadyFromConfig(ctx context.Context, other map[string]interface{}) (ap
|
||||||
}
|
}
|
||||||
|
|
||||||
// decorate power
|
// decorate power
|
||||||
var powerG func() (float64, error)
|
powerG, err := cc.Power.FloatGetter(ctx)
|
||||||
if cc.Power != nil {
|
if err != nil {
|
||||||
powerG, err = provider.NewFloatGetterFromConfig(ctx, *cc.Power)
|
return nil, fmt.Errorf("power: %w", err)
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("power: %w", err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// decorate energy
|
// decorate energy
|
||||||
var energyG func() (float64, error)
|
energyG, err := cc.Energy.FloatGetter(ctx)
|
||||||
if cc.Energy != nil {
|
if err != nil {
|
||||||
energyG, err = provider.NewFloatGetterFromConfig(ctx, *cc.Energy)
|
return nil, fmt.Errorf("energy: %w", err)
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("energy: %w", err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// decorate temp
|
// decorate temp
|
||||||
var tempG func() (float64, error)
|
tempG, err := cc.Temp.FloatGetter(ctx)
|
||||||
if cc.Temp != nil {
|
if err != nil {
|
||||||
tempG, err = provider.NewFloatGetterFromConfig(ctx, *cc.Temp)
|
return nil, fmt.Errorf("temp: %w", err)
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("temp: %w", err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var limitTempG func() (int64, error)
|
limitTempG, err := cc.LimitTemp.IntGetter(ctx)
|
||||||
if cc.LimitTemp != nil {
|
if err != nil {
|
||||||
limitTempG, err = provider.NewIntGetterFromConfig(ctx, *cc.LimitTemp)
|
return nil, fmt.Errorf("limit temp: %w", err)
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("limit temp: %w", err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return decorateSgReady(res, powerG, energyG, tempG, limitTempG), nil
|
return decorateSgReady(res, powerG, energyG, tempG, limitTempG), nil
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ import (
|
||||||
|
|
||||||
"github.com/evcc-io/evcc/api"
|
"github.com/evcc-io/evcc/api"
|
||||||
"github.com/evcc-io/evcc/charger/smaevcharger"
|
"github.com/evcc-io/evcc/charger/smaevcharger"
|
||||||
"github.com/evcc-io/evcc/provider"
|
"github.com/evcc-io/evcc/plugin"
|
||||||
"github.com/evcc-io/evcc/util"
|
"github.com/evcc-io/evcc/util"
|
||||||
"github.com/evcc-io/evcc/util/request"
|
"github.com/evcc-io/evcc/util/request"
|
||||||
"github.com/evcc-io/evcc/util/sponsor"
|
"github.com/evcc-io/evcc/util/sponsor"
|
||||||
|
|
@ -41,8 +41,8 @@ type Smaevcharger struct {
|
||||||
uri string // 192.168.XXX.XXX
|
uri string // 192.168.XXX.XXX
|
||||||
cache time.Duration
|
cache time.Duration
|
||||||
oldstate float64
|
oldstate float64
|
||||||
measurementG provider.Cacheable[[]smaevcharger.Measurements]
|
measurementG plugin.Cacheable[[]smaevcharger.Measurements]
|
||||||
parameterG provider.Cacheable[[]smaevcharger.Parameters]
|
parameterG plugin.Cacheable[[]smaevcharger.Parameters]
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
|
@ -95,8 +95,8 @@ func NewSmaevcharger(uri, user, password string, cache time.Duration) (api.Charg
|
||||||
}
|
}
|
||||||
|
|
||||||
// setup cached values
|
// setup cached values
|
||||||
wb.measurementG = provider.ResettableCached(wb._measurementData, wb.cache)
|
wb.measurementG = plugin.ResettableCached(wb._measurementData, wb.cache)
|
||||||
wb.parameterG = provider.ResettableCached(wb._parameterData, wb.cache)
|
wb.parameterG = plugin.ResettableCached(wb._parameterData, wb.cache)
|
||||||
|
|
||||||
ts, err := smaevcharger.TokenSource(log, wb.uri, user, password)
|
ts, err := smaevcharger.TokenSource(log, wb.uri, user, password)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ import (
|
||||||
|
|
||||||
"github.com/evcc-io/evcc/api"
|
"github.com/evcc-io/evcc/api"
|
||||||
"github.com/evcc-io/evcc/core/loadpoint"
|
"github.com/evcc-io/evcc/core/loadpoint"
|
||||||
"github.com/evcc-io/evcc/provider"
|
"github.com/evcc-io/evcc/plugin"
|
||||||
"github.com/evcc-io/evcc/util"
|
"github.com/evcc-io/evcc/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -24,11 +24,11 @@ type SwitchSocket struct {
|
||||||
func NewSwitchSocketFromConfig(ctx context.Context, other map[string]interface{}) (api.Charger, error) {
|
func NewSwitchSocketFromConfig(ctx context.Context, other map[string]interface{}) (api.Charger, error) {
|
||||||
var cc struct {
|
var cc struct {
|
||||||
embed `mapstructure:",squash"`
|
embed `mapstructure:",squash"`
|
||||||
Enabled provider.Config
|
Enabled plugin.Config
|
||||||
Enable provider.Config
|
Enable plugin.Config
|
||||||
Power provider.Config
|
Power plugin.Config
|
||||||
Energy *provider.Config
|
Energy *plugin.Config
|
||||||
Soc *provider.Config
|
Soc *plugin.Config
|
||||||
StandbyPower float64
|
StandbyPower float64
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -36,35 +36,29 @@ func NewSwitchSocketFromConfig(ctx context.Context, other map[string]interface{}
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
enabled, err := provider.NewBoolGetterFromConfig(ctx, cc.Enabled)
|
enabled, err := cc.Enabled.BoolGetter(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
enable, err := provider.NewBoolSetterFromConfig(ctx, "enable", cc.Enable)
|
enable, err := cc.Enable.BoolSetter(ctx, "enable")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
power, err := provider.NewFloatGetterFromConfig(ctx, cc.Power)
|
power, err := cc.Power.FloatGetter(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
var energy func() (float64, error)
|
energy, err := cc.Energy.FloatGetter(ctx)
|
||||||
if cc.Energy != nil {
|
if err != nil {
|
||||||
energy, err = provider.NewFloatGetterFromConfig(ctx, *cc.Energy)
|
return nil, err
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var soc func() (float64, error)
|
soc, err := cc.Soc.FloatGetter(ctx)
|
||||||
if cc.Soc != nil {
|
if err != nil {
|
||||||
soc, err = provider.NewFloatGetterFromConfig(ctx, *cc.Soc)
|
return nil, err
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
c := &SwitchSocket{
|
c := &SwitchSocket{
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/evcc-io/evcc/api"
|
"github.com/evcc-io/evcc/api"
|
||||||
"github.com/evcc-io/evcc/provider"
|
"github.com/evcc-io/evcc/plugin"
|
||||||
"github.com/evcc-io/evcc/util"
|
"github.com/evcc-io/evcc/util"
|
||||||
"github.com/evcc-io/evcc/util/request"
|
"github.com/evcc-io/evcc/util/request"
|
||||||
"github.com/evcc-io/evcc/util/sponsor"
|
"github.com/evcc-io/evcc/util/sponsor"
|
||||||
|
|
@ -43,7 +43,7 @@ type RealTimeData struct {
|
||||||
type Trydan struct {
|
type Trydan struct {
|
||||||
*request.Helper
|
*request.Helper
|
||||||
uri string
|
uri string
|
||||||
statusG provider.Cacheable[RealTimeData]
|
statusG plugin.Cacheable[RealTimeData]
|
||||||
current int
|
current int
|
||||||
enabled bool
|
enabled bool
|
||||||
}
|
}
|
||||||
|
|
@ -83,7 +83,7 @@ func NewTrydan(uri string, cache time.Duration) (api.Charger, error) {
|
||||||
uri: util.DefaultScheme(strings.TrimSuffix(uri, "/"), "http"),
|
uri: util.DefaultScheme(strings.TrimSuffix(uri, "/"), "http"),
|
||||||
}
|
}
|
||||||
|
|
||||||
c.statusG = provider.ResettableCached(func() (RealTimeData, error) {
|
c.statusG = plugin.ResettableCached(func() (RealTimeData, error) {
|
||||||
var res RealTimeData
|
var res RealTimeData
|
||||||
uri := fmt.Sprintf("%s/RealTimeData", c.uri)
|
uri := fmt.Sprintf("%s/RealTimeData", c.uri)
|
||||||
err := c.GetJSON(uri, &res)
|
err := c.GetJSON(uri, &res)
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ import (
|
||||||
|
|
||||||
"github.com/evcc-io/evcc/api"
|
"github.com/evcc-io/evcc/api"
|
||||||
"github.com/evcc-io/evcc/core/loadpoint"
|
"github.com/evcc-io/evcc/core/loadpoint"
|
||||||
"github.com/evcc-io/evcc/provider"
|
"github.com/evcc-io/evcc/plugin"
|
||||||
"github.com/evcc-io/evcc/util"
|
"github.com/evcc-io/evcc/util"
|
||||||
"github.com/evcc-io/evcc/util/request"
|
"github.com/evcc-io/evcc/util/request"
|
||||||
)
|
)
|
||||||
|
|
@ -73,7 +73,7 @@ func NewTwc3FromConfig(other map[string]interface{}) (api.Charger, error) {
|
||||||
client := request.NewHelper(util.NewLogger("twc3"))
|
client := request.NewHelper(util.NewLogger("twc3"))
|
||||||
uri := fmt.Sprintf("%s/api/1/vitals", util.DefaultScheme(strings.TrimSuffix(cc.URI, "/"), "http"))
|
uri := fmt.Sprintf("%s/api/1/vitals", util.DefaultScheme(strings.TrimSuffix(cc.URI, "/"), "http"))
|
||||||
|
|
||||||
c.vitalsG = provider.Cached(func() (Vitals, error) {
|
c.vitalsG = plugin.Cached(func() (Vitals, error) {
|
||||||
var res Vitals
|
var res Vitals
|
||||||
err := client.GetJSON(uri, &res)
|
err := client.GetJSON(uri, &res)
|
||||||
return res, err
|
return res, err
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ import (
|
||||||
|
|
||||||
"github.com/WulfgarW/sensonet"
|
"github.com/WulfgarW/sensonet"
|
||||||
"github.com/evcc-io/evcc/api"
|
"github.com/evcc-io/evcc/api"
|
||||||
"github.com/evcc-io/evcc/provider"
|
"github.com/evcc-io/evcc/plugin"
|
||||||
"github.com/evcc-io/evcc/util"
|
"github.com/evcc-io/evcc/util"
|
||||||
"github.com/evcc-io/evcc/util/request"
|
"github.com/evcc-io/evcc/util/request"
|
||||||
"github.com/samber/lo"
|
"github.com/samber/lo"
|
||||||
|
|
@ -127,7 +127,7 @@ func NewVaillantFromConfig(ctx context.Context, other map[string]interface{}) (a
|
||||||
|
|
||||||
var power func() (float64, error)
|
var power func() (float64, error)
|
||||||
if devices, _ := conn.GetMpcData(systemId); len(devices) > 0 {
|
if devices, _ := conn.GetMpcData(systemId); len(devices) > 0 {
|
||||||
power = provider.Cached(func() (float64, error) {
|
power = plugin.Cached(func() (float64, error) {
|
||||||
res, err := conn.GetMpcData(systemId)
|
res, err := conn.GetMpcData(systemId)
|
||||||
return lo.SumBy(res, func(d sensonet.MpcDevice) float64 {
|
return lo.SumBy(res, func(d sensonet.MpcDevice) float64 {
|
||||||
return d.CurrentPower
|
return d.CurrentPower
|
||||||
|
|
@ -153,7 +153,7 @@ func NewVaillantFromConfig(ctx context.Context, other map[string]interface{}) (a
|
||||||
|
|
||||||
var temp func() (float64, error)
|
var temp func() (float64, error)
|
||||||
if !heating || heatingTempSensor {
|
if !heating || heatingTempSensor {
|
||||||
temp = provider.Cached(func() (float64, error) {
|
temp = plugin.Cached(func() (float64, error) {
|
||||||
system, err := conn.GetSystem(systemId)
|
system, err := conn.GetSystem(systemId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
|
|
|
||||||
|
|
@ -9,8 +9,8 @@ import (
|
||||||
|
|
||||||
"github.com/evcc-io/evcc/api"
|
"github.com/evcc-io/evcc/api"
|
||||||
"github.com/evcc-io/evcc/charger/warp"
|
"github.com/evcc-io/evcc/charger/warp"
|
||||||
"github.com/evcc-io/evcc/provider"
|
"github.com/evcc-io/evcc/plugin"
|
||||||
"github.com/evcc-io/evcc/provider/mqtt"
|
"github.com/evcc-io/evcc/plugin/mqtt"
|
||||||
"github.com/evcc-io/evcc/util"
|
"github.com/evcc-io/evcc/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -104,14 +104,14 @@ func NewWarp2(mqttconf mqtt.Config, topic, emTopic string, timeout time.Duration
|
||||||
}
|
}
|
||||||
|
|
||||||
// timeout handler
|
// timeout handler
|
||||||
h, err := provider.NewMqtt(log, client, fmt.Sprintf("%s/evse/low_level_state", topic), timeout).StringGetter()
|
h, err := plugin.NewMqtt(log, client, fmt.Sprintf("%s/evse/low_level_state", topic), timeout).StringGetter()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
to := provider.NewTimeoutHandler(h)
|
to := plugin.NewTimeoutHandler(h)
|
||||||
|
|
||||||
mq := func(s string, args ...any) *provider.Mqtt {
|
mq := func(s string, args ...any) *plugin.Mqtt {
|
||||||
return provider.NewMqtt(log, client, fmt.Sprintf(s, args...), 0)
|
return plugin.NewMqtt(log, client, fmt.Sprintf(s, args...), 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
wb.maxcurrentG, err = to.JsonGetter(mq("%s/evse/external_current", topic))
|
wb.maxcurrentG, err = to.JsonGetter(mq("%s/evse/external_current", topic))
|
||||||
|
|
@ -135,7 +135,7 @@ func NewWarp2(mqttconf mqtt.Config, topic, emTopic string, timeout time.Duration
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
wb.maxcurrentS, err = provider.NewMqtt(log, client,
|
wb.maxcurrentS, err = plugin.NewMqtt(log, client,
|
||||||
fmt.Sprintf("%s/evse/external_current_update", topic), 0).
|
fmt.Sprintf("%s/evse/external_current_update", topic), 0).
|
||||||
WithPayload(`{ "current": ${maxcurrent} }`).
|
WithPayload(`{ "current": ${maxcurrent} }`).
|
||||||
IntSetter("maxcurrent")
|
IntSetter("maxcurrent")
|
||||||
|
|
@ -148,7 +148,7 @@ func NewWarp2(mqttconf mqtt.Config, topic, emTopic string, timeout time.Duration
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
wb.phasesS, err = provider.NewMqtt(log, client,
|
wb.phasesS, err = plugin.NewMqtt(log, client,
|
||||||
fmt.Sprintf("%s/power_manager/external_control_update", emTopic), 0).
|
fmt.Sprintf("%s/power_manager/external_control_update", emTopic), 0).
|
||||||
WithPayload(`{ "phases_wanted": ${phases} }`).
|
WithPayload(`{ "phases_wanted": ${phases} }`).
|
||||||
IntSetter("phases")
|
IntSetter("phases")
|
||||||
|
|
@ -171,7 +171,7 @@ func (wb *Warp2) hasFeature(root, feature string, timeout time.Duration) bool {
|
||||||
|
|
||||||
topic := fmt.Sprintf("%s/info/features", root)
|
topic := fmt.Sprintf("%s/info/features", root)
|
||||||
|
|
||||||
if dataG, err := provider.NewMqtt(wb.log, wb.client, topic, timeout).StringGetter(); err == nil {
|
if dataG, err := plugin.NewMqtt(wb.log, wb.client, topic, timeout).StringGetter(); err == nil {
|
||||||
if data, err := dataG(); err == nil {
|
if data, err := dataG(); err == nil {
|
||||||
if err := json.Unmarshal([]byte(data), &wb.features); err == nil {
|
if err := json.Unmarshal([]byte(data), &wb.features); err == nil {
|
||||||
return slices.Contains(wb.features, feature)
|
return slices.Contains(wb.features, feature)
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ import (
|
||||||
"github.com/coreos/go-oidc/v3/oidc"
|
"github.com/coreos/go-oidc/v3/oidc"
|
||||||
"github.com/evcc-io/evcc/api"
|
"github.com/evcc-io/evcc/api"
|
||||||
"github.com/evcc-io/evcc/charger/zaptec"
|
"github.com/evcc-io/evcc/charger/zaptec"
|
||||||
"github.com/evcc-io/evcc/provider"
|
"github.com/evcc-io/evcc/plugin"
|
||||||
"github.com/evcc-io/evcc/util"
|
"github.com/evcc-io/evcc/util"
|
||||||
"github.com/evcc-io/evcc/util/request"
|
"github.com/evcc-io/evcc/util/request"
|
||||||
"github.com/evcc-io/evcc/util/sponsor"
|
"github.com/evcc-io/evcc/util/sponsor"
|
||||||
|
|
@ -43,7 +43,7 @@ import (
|
||||||
type Zaptec struct {
|
type Zaptec struct {
|
||||||
*request.Helper
|
*request.Helper
|
||||||
log *util.Logger
|
log *util.Logger
|
||||||
statusG provider.Cacheable[zaptec.StateResponse]
|
statusG plugin.Cacheable[zaptec.StateResponse]
|
||||||
id string
|
id string
|
||||||
enabled bool
|
enabled bool
|
||||||
priority bool
|
priority bool
|
||||||
|
|
@ -91,7 +91,7 @@ func NewZaptec(user, password, id string, priority bool, cache time.Duration) (a
|
||||||
}
|
}
|
||||||
|
|
||||||
// setup cached values
|
// setup cached values
|
||||||
c.statusG = provider.ResettableCached(func() (zaptec.StateResponse, error) {
|
c.statusG = plugin.ResettableCached(func() (zaptec.StateResponse, error) {
|
||||||
var res zaptec.StateResponse
|
var res zaptec.StateResponse
|
||||||
|
|
||||||
uri := fmt.Sprintf("%s/api/chargers/%s/state", zaptec.ApiURL, c.id)
|
uri := fmt.Sprintf("%s/api/chargers/%s/state", zaptec.ApiURL, c.id)
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ import (
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/evcc-io/evcc/provider/mqtt"
|
"github.com/evcc-io/evcc/plugin/mqtt"
|
||||||
"github.com/evcc-io/evcc/util"
|
"github.com/evcc-io/evcc/util"
|
||||||
"github.com/evcc-io/evcc/util/sponsor"
|
"github.com/evcc-io/evcc/util/sponsor"
|
||||||
"github.com/evcc-io/evcc/util/templates"
|
"github.com/evcc-io/evcc/util/templates"
|
||||||
|
|
|
||||||
|
|
@ -24,9 +24,9 @@ import (
|
||||||
"github.com/evcc-io/evcc/core/keys"
|
"github.com/evcc-io/evcc/core/keys"
|
||||||
"github.com/evcc-io/evcc/hems"
|
"github.com/evcc-io/evcc/hems"
|
||||||
"github.com/evcc-io/evcc/meter"
|
"github.com/evcc-io/evcc/meter"
|
||||||
"github.com/evcc-io/evcc/provider/golang"
|
"github.com/evcc-io/evcc/plugin/golang"
|
||||||
"github.com/evcc-io/evcc/provider/javascript"
|
"github.com/evcc-io/evcc/plugin/javascript"
|
||||||
"github.com/evcc-io/evcc/provider/mqtt"
|
"github.com/evcc-io/evcc/plugin/mqtt"
|
||||||
"github.com/evcc-io/evcc/push"
|
"github.com/evcc-io/evcc/push"
|
||||||
"github.com/evcc-io/evcc/server"
|
"github.com/evcc-io/evcc/server"
|
||||||
"github.com/evcc-io/evcc/server/db"
|
"github.com/evcc-io/evcc/server/db"
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/evcc-io/evcc/api"
|
"github.com/evcc-io/evcc/api"
|
||||||
"github.com/evcc-io/evcc/provider"
|
"github.com/evcc-io/evcc/plugin"
|
||||||
"github.com/evcc-io/evcc/util"
|
"github.com/evcc-io/evcc/util"
|
||||||
"github.com/evcc-io/evcc/util/config"
|
"github.com/evcc-io/evcc/util/config"
|
||||||
)
|
)
|
||||||
|
|
@ -41,14 +41,14 @@ type Circuit struct {
|
||||||
// NewFromConfig creates a new Circuit
|
// NewFromConfig creates a new Circuit
|
||||||
func NewFromConfig(log *util.Logger, other map[string]interface{}) (api.Circuit, error) {
|
func NewFromConfig(log *util.Logger, other map[string]interface{}) (api.Circuit, error) {
|
||||||
cc := struct {
|
cc := struct {
|
||||||
Title string // title
|
Title string // title
|
||||||
ParentRef string `mapstructure:"parent"` // parent circuit reference
|
ParentRef string `mapstructure:"parent"` // parent circuit reference
|
||||||
MeterRef string `mapstructure:"meter"` // meter reference
|
MeterRef string `mapstructure:"meter"` // meter reference
|
||||||
MaxCurrent float64 // the max allowed current
|
MaxCurrent float64 // the max allowed current
|
||||||
MaxPower float64 // the max allowed power
|
MaxPower float64 // the max allowed power
|
||||||
GetMaxCurrent *provider.Config // dynamic max allowed current
|
GetMaxCurrent *plugin.Config // dynamic max allowed current
|
||||||
GetMaxPower *provider.Config // dynamic max allowed power
|
GetMaxPower *plugin.Config // dynamic max allowed power
|
||||||
Timeout time.Duration // timeout between meter updates
|
Timeout time.Duration // timeout between meter updates
|
||||||
}{
|
}{
|
||||||
Timeout: time.Minute,
|
Timeout: time.Minute,
|
||||||
}
|
}
|
||||||
|
|
@ -71,20 +71,14 @@ func NewFromConfig(log *util.Logger, other map[string]interface{}) (api.Circuit,
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if cc.GetMaxPower != nil {
|
circuit.getMaxPower, err = cc.GetMaxPower.FloatGetter(context.TODO())
|
||||||
res, err := provider.NewFloatGetterFromConfig(context.TODO(), *cc.GetMaxPower)
|
if err != nil {
|
||||||
if err != nil {
|
return nil, err
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
circuit.getMaxPower = res
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if cc.GetMaxCurrent != nil {
|
circuit.getMaxCurrent, err = cc.GetMaxCurrent.FloatGetter(context.TODO())
|
||||||
res, err := provider.NewFloatGetterFromConfig(context.TODO(), *cc.GetMaxCurrent)
|
if err != nil {
|
||||||
if err != nil {
|
return nil, err
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
circuit.getMaxCurrent = res
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if cc.ParentRef != "" {
|
if cc.ParentRef != "" {
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ import (
|
||||||
"github.com/evcc-io/evcc/core/soc"
|
"github.com/evcc-io/evcc/core/soc"
|
||||||
"github.com/evcc-io/evcc/core/vehicle"
|
"github.com/evcc-io/evcc/core/vehicle"
|
||||||
"github.com/evcc-io/evcc/core/wrapper"
|
"github.com/evcc-io/evcc/core/wrapper"
|
||||||
"github.com/evcc-io/evcc/provider"
|
"github.com/evcc-io/evcc/plugin"
|
||||||
"github.com/evcc-io/evcc/push"
|
"github.com/evcc-io/evcc/push"
|
||||||
"github.com/evcc-io/evcc/util"
|
"github.com/evcc-io/evcc/util"
|
||||||
"github.com/evcc-io/evcc/util/config"
|
"github.com/evcc-io/evcc/util/config"
|
||||||
|
|
@ -457,7 +457,7 @@ func (lp *Loadpoint) evChargeStopHandler() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// soc update reset
|
// soc update reset
|
||||||
provider.ResetCached()
|
plugin.ResetCached()
|
||||||
lp.socUpdated = time.Time{}
|
lp.socUpdated = time.Time{}
|
||||||
|
|
||||||
// reset pv enable/disable timer
|
// reset pv enable/disable timer
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ import (
|
||||||
"github.com/evcc-io/evcc/core/session"
|
"github.com/evcc-io/evcc/core/session"
|
||||||
"github.com/evcc-io/evcc/core/soc"
|
"github.com/evcc-io/evcc/core/soc"
|
||||||
"github.com/evcc-io/evcc/core/vehicle"
|
"github.com/evcc-io/evcc/core/vehicle"
|
||||||
"github.com/evcc-io/evcc/provider"
|
"github.com/evcc-io/evcc/plugin"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|
@ -234,7 +234,7 @@ func (lp *Loadpoint) vehicleUnidentified() bool {
|
||||||
select {
|
select {
|
||||||
case <-lp.vehicleDetectTicker.C:
|
case <-lp.vehicleDetectTicker.C:
|
||||||
lp.log.DEBUG.Println("vehicle api refresh")
|
lp.log.DEBUG.Println("vehicle api refresh")
|
||||||
provider.ResetCached()
|
plugin.ResetCached()
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -260,7 +260,7 @@ func (lp *Loadpoint) vehicleDefaultOrDetect() {
|
||||||
func (lp *Loadpoint) startVehicleDetection() {
|
func (lp *Loadpoint) startVehicleDetection() {
|
||||||
// flush all vehicles before detection starts
|
// flush all vehicles before detection starts
|
||||||
lp.log.DEBUG.Println("vehicle api refresh")
|
lp.log.DEBUG.Println("vehicle api refresh")
|
||||||
provider.ResetCached()
|
plugin.ResetCached()
|
||||||
|
|
||||||
lp.vehicleDetect = lp.clock.Now()
|
lp.vehicleDetect = lp.clock.Now()
|
||||||
lp.vehicleDetectTicker = lp.clock.Ticker(vehicleDetectInterval)
|
lp.vehicleDetectTicker = lp.clock.Ticker(vehicleDetectInterval)
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ import (
|
||||||
"github.com/evcc-io/evcc/api"
|
"github.com/evcc-io/evcc/api"
|
||||||
"github.com/evcc-io/evcc/core/circuit"
|
"github.com/evcc-io/evcc/core/circuit"
|
||||||
"github.com/evcc-io/evcc/core/site"
|
"github.com/evcc-io/evcc/core/site"
|
||||||
"github.com/evcc-io/evcc/provider"
|
"github.com/evcc-io/evcc/plugin"
|
||||||
"github.com/evcc-io/evcc/server/eebus"
|
"github.com/evcc-io/evcc/server/eebus"
|
||||||
"github.com/evcc-io/evcc/util"
|
"github.com/evcc-io/evcc/util"
|
||||||
)
|
)
|
||||||
|
|
@ -30,7 +30,7 @@ type EEBus struct {
|
||||||
failsafeLimit float64
|
failsafeLimit float64
|
||||||
failsafeDuration time.Duration
|
failsafeDuration time.Duration
|
||||||
|
|
||||||
heartbeat *provider.Value[struct{}]
|
heartbeat *plugin.Value[struct{}]
|
||||||
}
|
}
|
||||||
|
|
||||||
type Limits struct {
|
type Limits struct {
|
||||||
|
|
@ -90,7 +90,7 @@ func NewEEBus(ski string, limits Limits, root api.Circuit) (*EEBus, error) {
|
||||||
root: root,
|
root: root,
|
||||||
uc: eebus.Instance.ControllableSystem(),
|
uc: eebus.Instance.ControllableSystem(),
|
||||||
Connector: eebus.NewConnector(),
|
Connector: eebus.NewConnector(),
|
||||||
heartbeat: provider.NewValue[struct{}](2 * time.Minute), // LPC-031
|
heartbeat: plugin.NewValue[struct{}](2 * time.Minute), // LPC-031
|
||||||
|
|
||||||
consumptionLimit: &ucapi.LoadLimit{
|
consumptionLimit: &ucapi.LoadLimit{
|
||||||
Value: limits.ConsumptionLimit,
|
Value: limits.ConsumptionLimit,
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ import (
|
||||||
"github.com/evcc-io/evcc/api"
|
"github.com/evcc-io/evcc/api"
|
||||||
"github.com/evcc-io/evcc/core/circuit"
|
"github.com/evcc-io/evcc/core/circuit"
|
||||||
"github.com/evcc-io/evcc/core/site"
|
"github.com/evcc-io/evcc/core/site"
|
||||||
"github.com/evcc-io/evcc/provider"
|
"github.com/evcc-io/evcc/plugin"
|
||||||
"github.com/evcc-io/evcc/util"
|
"github.com/evcc-io/evcc/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -24,7 +24,7 @@ type Relay struct {
|
||||||
func New(ctx context.Context, other map[string]interface{}, site site.API) (*Relay, error) {
|
func New(ctx context.Context, other map[string]interface{}, site site.API) (*Relay, error) {
|
||||||
var cc struct {
|
var cc struct {
|
||||||
MaxPower float64
|
MaxPower float64
|
||||||
Limit provider.Config
|
Limit plugin.Config
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := util.DecodeOther(other, &cc); err != nil {
|
if err := util.DecodeOther(other, &cc); err != nil {
|
||||||
|
|
@ -50,7 +50,7 @@ func New(ctx context.Context, other map[string]interface{}, site site.API) (*Rel
|
||||||
site.SetCircuit(lpc)
|
site.SetCircuit(lpc)
|
||||||
|
|
||||||
// limit getter
|
// limit getter
|
||||||
limitG, err := provider.NewBoolGetterFromConfig(ctx, cc.Limit)
|
limitG, err := cc.Limit.BoolGetter(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ import (
|
||||||
|
|
||||||
"github.com/evcc-io/evcc/api"
|
"github.com/evcc-io/evcc/api"
|
||||||
"github.com/evcc-io/evcc/meter/discovergy"
|
"github.com/evcc-io/evcc/meter/discovergy"
|
||||||
"github.com/evcc-io/evcc/provider"
|
"github.com/evcc-io/evcc/plugin"
|
||||||
"github.com/evcc-io/evcc/util"
|
"github.com/evcc-io/evcc/util"
|
||||||
"github.com/evcc-io/evcc/util/request"
|
"github.com/evcc-io/evcc/util/request"
|
||||||
"github.com/evcc-io/evcc/util/transport"
|
"github.com/evcc-io/evcc/util/transport"
|
||||||
|
|
@ -74,7 +74,7 @@ func NewDiscovergyFromConfig(other map[string]interface{}) (api.Meter, error) {
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
dataG := provider.Cached(func() (discovergy.Reading, error) {
|
dataG := plugin.Cached(func() (discovergy.Reading, error) {
|
||||||
var res discovergy.Reading
|
var res discovergy.Reading
|
||||||
uri := fmt.Sprintf("%s/last_reading?meterId=%s", discovergy.API, meterID)
|
uri := fmt.Sprintf("%s/last_reading?meterId=%s", discovergy.API, meterID)
|
||||||
err := client.GetJSON(uri, &res)
|
err := client.GetJSON(uri, &res)
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ import (
|
||||||
"github.com/enbility/eebus-go/usecases/ma/mgcp"
|
"github.com/enbility/eebus-go/usecases/ma/mgcp"
|
||||||
spineapi "github.com/enbility/spine-go/api"
|
spineapi "github.com/enbility/spine-go/api"
|
||||||
"github.com/evcc-io/evcc/api"
|
"github.com/evcc-io/evcc/api"
|
||||||
"github.com/evcc-io/evcc/provider"
|
"github.com/evcc-io/evcc/plugin"
|
||||||
"github.com/evcc-io/evcc/server/eebus"
|
"github.com/evcc-io/evcc/server/eebus"
|
||||||
"github.com/evcc-io/evcc/util"
|
"github.com/evcc-io/evcc/util"
|
||||||
)
|
)
|
||||||
|
|
@ -19,8 +19,8 @@ type EEBus struct {
|
||||||
*eebus.Connector
|
*eebus.Connector
|
||||||
uc *eebus.UseCasesCS
|
uc *eebus.UseCasesCS
|
||||||
|
|
||||||
power, energy *provider.Value[float64]
|
power, energy *plugin.Value[float64]
|
||||||
voltages, currents *provider.Value[[]float64]
|
voltages, currents *plugin.Value[[]float64]
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
|
@ -54,10 +54,10 @@ func NewEEBus(ski, ip string, timeout time.Duration) (*EEBus, error) {
|
||||||
log: util.NewLogger("eebus"),
|
log: util.NewLogger("eebus"),
|
||||||
uc: eebus.Instance.ControllableSystem(),
|
uc: eebus.Instance.ControllableSystem(),
|
||||||
Connector: eebus.NewConnector(),
|
Connector: eebus.NewConnector(),
|
||||||
power: provider.NewValue[float64](timeout),
|
power: plugin.NewValue[float64](timeout),
|
||||||
energy: provider.NewValue[float64](timeout),
|
energy: plugin.NewValue[float64](timeout),
|
||||||
voltages: provider.NewValue[[]float64](timeout),
|
voltages: plugin.NewValue[[]float64](timeout),
|
||||||
currents: provider.NewValue[[]float64](timeout),
|
currents: plugin.NewValue[[]float64](timeout),
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := eebus.Instance.RegisterDevice(ski, ip, c); err != nil {
|
if err := eebus.Instance.RegisterDevice(ski, ip, c); err != nil {
|
||||||
|
|
|
||||||
|
|
@ -5,34 +5,26 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/evcc-io/evcc/provider"
|
"github.com/evcc-io/evcc/plugin"
|
||||||
)
|
)
|
||||||
|
|
||||||
// BuildMeasurements returns typical meter measurement getters from config
|
// BuildMeasurements returns typical meter measurement getters from config
|
||||||
func BuildMeasurements(ctx context.Context, power, energy *provider.Config) (func() (float64, error), func() (float64, error), error) {
|
func BuildMeasurements(ctx context.Context, power, energy *plugin.Config) (func() (float64, error), func() (float64, error), error) {
|
||||||
var powerG func() (float64, error)
|
powerG, err := power.FloatGetter(ctx)
|
||||||
if power != nil {
|
if err != nil {
|
||||||
var err error
|
return nil, nil, fmt.Errorf("power: %w", err)
|
||||||
powerG, err = provider.NewFloatGetterFromConfig(ctx, *power)
|
|
||||||
if err != nil {
|
|
||||||
return nil, nil, fmt.Errorf("power: %w", err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var energyG func() (float64, error)
|
energyG, err := energy.FloatGetter(ctx)
|
||||||
if energy != nil {
|
if err != nil {
|
||||||
var err error
|
return nil, nil, fmt.Errorf("energy: %w", err)
|
||||||
energyG, err = provider.NewFloatGetterFromConfig(ctx, *energy)
|
|
||||||
if err != nil {
|
|
||||||
return nil, nil, fmt.Errorf("energy: %w", err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return powerG, energyG, nil
|
return powerG, energyG, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// BuildPhaseMeasurements returns typical meter measurement getters from config
|
// BuildPhaseMeasurements returns typical meter measurement getters from config
|
||||||
func BuildPhaseMeasurements(ctx context.Context, currents, voltages, powers []provider.Config) (
|
func BuildPhaseMeasurements(ctx context.Context, currents, voltages, powers []plugin.Config) (
|
||||||
func() (float64, float64, float64, error),
|
func() (float64, float64, float64, error),
|
||||||
func() (float64, float64, float64, error),
|
func() (float64, float64, float64, error),
|
||||||
func() (float64, float64, float64, error),
|
func() (float64, float64, float64, error),
|
||||||
|
|
@ -57,7 +49,7 @@ func BuildPhaseMeasurements(ctx context.Context, currents, voltages, powers []pr
|
||||||
}
|
}
|
||||||
|
|
||||||
// buildPhaseProviders returns phases getter for given config
|
// buildPhaseProviders returns phases getter for given config
|
||||||
func buildPhaseProviders(ctx context.Context, providers []provider.Config) (func() (float64, float64, float64, error), error) {
|
func buildPhaseProviders(ctx context.Context, providers []plugin.Config) (func() (float64, float64, float64, error), error) {
|
||||||
if len(providers) == 0 {
|
if len(providers) == 0 {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
@ -68,7 +60,7 @@ func buildPhaseProviders(ctx context.Context, providers []provider.Config) (func
|
||||||
|
|
||||||
var phases [3]func() (float64, error)
|
var phases [3]func() (float64, error)
|
||||||
for idx, prov := range providers {
|
for idx, prov := range providers {
|
||||||
c, err := provider.NewFloatGetterFromConfig(ctx, prov)
|
c, err := prov.FloatGetter(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("[%d] %w", idx, err)
|
return nil, fmt.Errorf("[%d] %w", idx, err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/evcc-io/evcc/provider"
|
"github.com/evcc-io/evcc/plugin"
|
||||||
"github.com/evcc-io/evcc/util"
|
"github.com/evcc-io/evcc/util"
|
||||||
"github.com/evcc-io/evcc/util/request"
|
"github.com/evcc-io/evcc/util/request"
|
||||||
"github.com/evcc-io/evcc/util/transport"
|
"github.com/evcc-io/evcc/util/transport"
|
||||||
|
|
@ -29,8 +29,8 @@ type Connection struct {
|
||||||
log *util.Logger
|
log *util.Logger
|
||||||
*request.Helper
|
*request.Helper
|
||||||
*Settings
|
*Settings
|
||||||
meterG provider.Cacheable[MethodResponse]
|
meterG plugin.Cacheable[MethodResponse]
|
||||||
switchG provider.Cacheable[MethodResponse]
|
switchG plugin.Cacheable[MethodResponse]
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewConnection creates a new Homematic device connection.
|
// NewConnection creates a new Homematic device connection.
|
||||||
|
|
@ -58,11 +58,11 @@ func NewConnection(uri, device, meterchannel, switchchannel, user, password stri
|
||||||
conn.Client.Transport = transport.BasicAuth(user, password, conn.Client.Transport)
|
conn.Client.Transport = transport.BasicAuth(user, password, conn.Client.Transport)
|
||||||
}
|
}
|
||||||
|
|
||||||
conn.switchG = provider.ResettableCached(func() (MethodResponse, error) {
|
conn.switchG = plugin.ResettableCached(func() (MethodResponse, error) {
|
||||||
return conn.XmlCmd("getParamset", conn.SwitchChannel, Param{CCUString: "VALUES"})
|
return conn.XmlCmd("getParamset", conn.SwitchChannel, Param{CCUString: "VALUES"})
|
||||||
}, conn.Cache)
|
}, conn.Cache)
|
||||||
|
|
||||||
conn.meterG = provider.ResettableCached(func() (MethodResponse, error) {
|
conn.meterG = plugin.ResettableCached(func() (MethodResponse, error) {
|
||||||
return conn.XmlCmd("getParamset", conn.MeterChannel, Param{CCUString: "VALUES"})
|
return conn.XmlCmd("getParamset", conn.MeterChannel, Param{CCUString: "VALUES"})
|
||||||
}, conn.Cache)
|
}, conn.Cache)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/evcc-io/evcc/provider"
|
"github.com/evcc-io/evcc/plugin"
|
||||||
"github.com/evcc-io/evcc/util"
|
"github.com/evcc-io/evcc/util"
|
||||||
"github.com/evcc-io/evcc/util/request"
|
"github.com/evcc-io/evcc/util/request"
|
||||||
"github.com/evcc-io/evcc/util/transport"
|
"github.com/evcc-io/evcc/util/transport"
|
||||||
|
|
@ -19,8 +19,8 @@ type Connection struct {
|
||||||
uri string
|
uri string
|
||||||
usage string
|
usage string
|
||||||
ProductType string
|
ProductType string
|
||||||
dataG provider.Cacheable[DataResponse]
|
dataG plugin.Cacheable[DataResponse]
|
||||||
stateG provider.Cacheable[StateResponse]
|
stateG plugin.Cacheable[StateResponse]
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewConnection creates a homewizard connection
|
// NewConnection creates a homewizard connection
|
||||||
|
|
@ -50,13 +50,13 @@ func NewConnection(uri string, usage string, cache time.Duration) (*Connection,
|
||||||
c.uri = c.uri + "/" + res.ApiVersion
|
c.uri = c.uri + "/" + res.ApiVersion
|
||||||
c.ProductType = res.ProductType
|
c.ProductType = res.ProductType
|
||||||
|
|
||||||
c.dataG = provider.ResettableCached(func() (DataResponse, error) {
|
c.dataG = plugin.ResettableCached(func() (DataResponse, error) {
|
||||||
var res DataResponse
|
var res DataResponse
|
||||||
err := c.GetJSON(fmt.Sprintf("%s/data", c.uri), &res)
|
err := c.GetJSON(fmt.Sprintf("%s/data", c.uri), &res)
|
||||||
return res, err
|
return res, err
|
||||||
}, cache)
|
}, cache)
|
||||||
|
|
||||||
c.stateG = provider.ResettableCached(func() (StateResponse, error) {
|
c.stateG = plugin.ResettableCached(func() (StateResponse, error) {
|
||||||
var res StateResponse
|
var res StateResponse
|
||||||
err := c.GetJSON(fmt.Sprintf("%s/state", c.uri), &res)
|
err := c.GetJSON(fmt.Sprintf("%s/state", c.uri), &res)
|
||||||
return res, err
|
return res, err
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ import (
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/evcc-io/evcc/provider"
|
"github.com/evcc-io/evcc/plugin"
|
||||||
"github.com/evcc-io/evcc/util"
|
"github.com/evcc-io/evcc/util"
|
||||||
"github.com/evcc-io/evcc/util/request"
|
"github.com/evcc-io/evcc/util/request"
|
||||||
"github.com/evcc-io/evcc/util/transport"
|
"github.com/evcc-io/evcc/util/transport"
|
||||||
|
|
@ -63,7 +63,7 @@ func GetInstance(uri, registration, password string, cache time.Duration, essTyp
|
||||||
|
|
||||||
// caches the data access for the "cache" time duration
|
// caches the data access for the "cache" time duration
|
||||||
// sends a new request to the pcs if the cache is expired and Data() requested
|
// sends a new request to the pcs if the cache is expired and Data() requested
|
||||||
instance.dataG = provider.Cached(instance.refreshData, cache)
|
instance.dataG = plugin.Cached(instance.refreshData, cache)
|
||||||
|
|
||||||
// do first login if no authKey exists and uri and password exist
|
// do first login if no authKey exists and uri and password exist
|
||||||
if instance.authKey == "" && instance.uri != "" && instance.password != "" {
|
if instance.authKey == "" && instance.uri != "" && instance.password != "" {
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/evcc-io/evcc/api"
|
"github.com/evcc-io/evcc/api"
|
||||||
"github.com/evcc-io/evcc/provider"
|
"github.com/evcc-io/evcc/plugin"
|
||||||
"github.com/evcc-io/evcc/util"
|
"github.com/evcc-io/evcc/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -18,19 +18,19 @@ func init() {
|
||||||
// NewConfigurableFromConfig creates api.Meter from config
|
// NewConfigurableFromConfig creates api.Meter from config
|
||||||
func NewConfigurableFromConfig(ctx context.Context, other map[string]interface{}) (api.Meter, error) {
|
func NewConfigurableFromConfig(ctx context.Context, other map[string]interface{}) (api.Meter, error) {
|
||||||
cc := struct {
|
cc := struct {
|
||||||
Power provider.Config
|
Power plugin.Config
|
||||||
Energy *provider.Config // optional
|
Energy *plugin.Config // optional
|
||||||
Currents []provider.Config // optional
|
Currents []plugin.Config // optional
|
||||||
Voltages []provider.Config // optional
|
Voltages []plugin.Config // optional
|
||||||
Powers []provider.Config // optional
|
Powers []plugin.Config // optional
|
||||||
|
|
||||||
// battery
|
// battery
|
||||||
capacity `mapstructure:",squash"`
|
capacity `mapstructure:",squash"`
|
||||||
maxpower `mapstructure:",squash"`
|
maxpower `mapstructure:",squash"`
|
||||||
battery `mapstructure:",squash"`
|
battery `mapstructure:",squash"`
|
||||||
Soc *provider.Config // optional
|
Soc *plugin.Config // optional
|
||||||
LimitSoc *provider.Config // optional
|
LimitSoc *plugin.Config // optional
|
||||||
BatteryMode *provider.Config // optional
|
BatteryMode *plugin.Config // optional
|
||||||
}{
|
}{
|
||||||
battery: battery{
|
battery: battery{
|
||||||
MinSoc: 20,
|
MinSoc: 20,
|
||||||
|
|
@ -55,19 +55,16 @@ func NewConfigurableFromConfig(ctx context.Context, other map[string]interface{}
|
||||||
m, _ := NewConfigurable(powerG)
|
m, _ := NewConfigurable(powerG)
|
||||||
|
|
||||||
// decorate soc
|
// decorate soc
|
||||||
var socG func() (float64, error)
|
socG, err := cc.Soc.FloatGetter(ctx)
|
||||||
if cc.Soc != nil {
|
if err != nil {
|
||||||
socG, err = provider.NewFloatGetterFromConfig(ctx, *cc.Soc)
|
return nil, fmt.Errorf("battery soc: %w", err)
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("battery soc: %w", err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var batModeS func(api.BatteryMode) error
|
var batModeS func(api.BatteryMode) error
|
||||||
|
|
||||||
switch {
|
switch {
|
||||||
case cc.Soc != nil && cc.LimitSoc != nil:
|
case cc.Soc != nil && cc.LimitSoc != nil:
|
||||||
limitSocS, err := provider.NewFloatSetterFromConfig(ctx, "limitSoc", *cc.LimitSoc)
|
limitSocS, err := cc.LimitSoc.FloatSetter(ctx, "limitSoc")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("battery limit soc: %w", err)
|
return nil, fmt.Errorf("battery limit soc: %w", err)
|
||||||
}
|
}
|
||||||
|
|
@ -75,7 +72,7 @@ func NewConfigurableFromConfig(ctx context.Context, other map[string]interface{}
|
||||||
batModeS = cc.battery.LimitController(socG, limitSocS)
|
batModeS = cc.battery.LimitController(socG, limitSocS)
|
||||||
|
|
||||||
case cc.BatteryMode != nil:
|
case cc.BatteryMode != nil:
|
||||||
modeS, err := provider.NewIntSetterFromConfig(ctx, "batteryMode", *cc.BatteryMode)
|
modeS, err := cc.BatteryMode.IntSetter(ctx, "batteryMode")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("battery mode: %w", err)
|
return nil, fmt.Errorf("battery mode: %w", err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,8 +8,8 @@ import (
|
||||||
|
|
||||||
"github.com/evcc-io/evcc/api"
|
"github.com/evcc-io/evcc/api"
|
||||||
"github.com/evcc-io/evcc/charger/openwb"
|
"github.com/evcc-io/evcc/charger/openwb"
|
||||||
"github.com/evcc-io/evcc/provider"
|
"github.com/evcc-io/evcc/plugin"
|
||||||
"github.com/evcc-io/evcc/provider/mqtt"
|
"github.com/evcc-io/evcc/plugin/mqtt"
|
||||||
"github.com/evcc-io/evcc/util"
|
"github.com/evcc-io/evcc/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -42,14 +42,14 @@ func NewOpenWBFromConfig(other map[string]interface{}) (api.Meter, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// timeout handler
|
// timeout handler
|
||||||
h, err := provider.NewMqtt(log, client, fmt.Sprintf("%s/system/%s", cc.Topic, openwb.TimestampTopic), cc.Timeout).StringGetter()
|
h, err := plugin.NewMqtt(log, client, fmt.Sprintf("%s/system/%s", cc.Topic, openwb.TimestampTopic), cc.Timeout).StringGetter()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
to := provider.NewTimeoutHandler(h)
|
to := plugin.NewTimeoutHandler(h)
|
||||||
|
|
||||||
mq := func(s string, args ...any) *provider.Mqtt {
|
mq := func(s string, args ...any) *plugin.Mqtt {
|
||||||
return provider.NewMqtt(log, client, fmt.Sprintf(s, args...), 0)
|
return plugin.NewMqtt(log, client, fmt.Sprintf(s, args...), 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
var power func() (float64, error)
|
var power func() (float64, error)
|
||||||
|
|
@ -77,7 +77,7 @@ func NewOpenWBFromConfig(other map[string]interface{}) (api.Meter, error) {
|
||||||
|
|
||||||
case "pv":
|
case "pv":
|
||||||
// first pv
|
// first pv
|
||||||
configuredG, err := provider.NewMqtt(log, client, fmt.Sprintf("%s/pv/1/%s", cc.Topic, openwb.PvConfigured), cc.Timeout).BoolGetter()
|
configuredG, err := plugin.NewMqtt(log, client, fmt.Sprintf("%s/pv/1/%s", cc.Topic, openwb.PvConfigured), cc.Timeout).BoolGetter()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
@ -100,7 +100,7 @@ func NewOpenWBFromConfig(other map[string]interface{}) (api.Meter, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
case "battery":
|
case "battery":
|
||||||
configuredG, err := provider.NewMqtt(log, client, fmt.Sprintf("%s/housebattery/%s", cc.Topic, openwb.BatteryConfigured), cc.Timeout).BoolGetter()
|
configuredG, err := plugin.NewMqtt(log, client, fmt.Sprintf("%s/housebattery/%s", cc.Topic, openwb.BatteryConfigured), cc.Timeout).BoolGetter()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ import (
|
||||||
"github.com/andig/go-powerwall"
|
"github.com/andig/go-powerwall"
|
||||||
"github.com/bogosj/tesla"
|
"github.com/bogosj/tesla"
|
||||||
"github.com/evcc-io/evcc/api"
|
"github.com/evcc-io/evcc/api"
|
||||||
"github.com/evcc-io/evcc/provider"
|
"github.com/evcc-io/evcc/plugin"
|
||||||
"github.com/evcc-io/evcc/util"
|
"github.com/evcc-io/evcc/util"
|
||||||
"github.com/evcc-io/evcc/util/request"
|
"github.com/evcc-io/evcc/util/request"
|
||||||
"golang.org/x/oauth2"
|
"golang.org/x/oauth2"
|
||||||
|
|
@ -90,7 +90,7 @@ func NewPowerWall(uri, usage, user, password string, cache time.Duration, refres
|
||||||
m := &PowerWall{
|
m := &PowerWall{
|
||||||
client: client,
|
client: client,
|
||||||
usage: strings.ToLower(usage),
|
usage: strings.ToLower(usage),
|
||||||
meterG: provider.Cached(client.GetMetersAggregates, cache),
|
meterG: plugin.Cached(client.GetMetersAggregates, cache),
|
||||||
}
|
}
|
||||||
|
|
||||||
var batteryControl bool
|
var batteryControl bool
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ import (
|
||||||
"text/tabwriter"
|
"text/tabwriter"
|
||||||
|
|
||||||
"github.com/evcc-io/evcc/api"
|
"github.com/evcc-io/evcc/api"
|
||||||
"github.com/evcc-io/evcc/provider/sma"
|
"github.com/evcc-io/evcc/plugin/sma"
|
||||||
"github.com/evcc-io/evcc/util"
|
"github.com/evcc-io/evcc/util"
|
||||||
"gitlab.com/bboehmke/sunny"
|
"gitlab.com/bboehmke/sunny"
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/evcc-io/evcc/provider"
|
"github.com/evcc-io/evcc/plugin"
|
||||||
"github.com/evcc-io/evcc/util"
|
"github.com/evcc-io/evcc/util"
|
||||||
"github.com/evcc-io/evcc/util/request"
|
"github.com/evcc-io/evcc/util/request"
|
||||||
"github.com/evcc-io/evcc/util/transport"
|
"github.com/evcc-io/evcc/util/transport"
|
||||||
|
|
@ -18,8 +18,8 @@ type Connection struct {
|
||||||
*request.Helper
|
*request.Helper
|
||||||
uri, user, password string
|
uri, user, password string
|
||||||
channels []int
|
channels []int
|
||||||
statusSnsG provider.Cacheable[StatusSNSResponse]
|
statusSnsG plugin.Cacheable[StatusSNSResponse]
|
||||||
statusStsG provider.Cacheable[StatusSTSResponse]
|
statusStsG plugin.Cacheable[StatusSTSResponse]
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewConnection creates a Tasmota connection
|
// NewConnection creates a Tasmota connection
|
||||||
|
|
@ -50,7 +50,7 @@ func NewConnection(uri, user, password string, channels []int, cache time.Durati
|
||||||
|
|
||||||
c.Client.Transport = request.NewTripper(log, transport.Insecure())
|
c.Client.Transport = request.NewTripper(log, transport.Insecure())
|
||||||
|
|
||||||
c.statusSnsG = provider.ResettableCached(func() (StatusSNSResponse, error) {
|
c.statusSnsG = plugin.ResettableCached(func() (StatusSNSResponse, error) {
|
||||||
parameters := url.Values{
|
parameters := url.Values{
|
||||||
"user": {c.user},
|
"user": {c.user},
|
||||||
"password": {c.password},
|
"password": {c.password},
|
||||||
|
|
@ -61,7 +61,7 @@ func NewConnection(uri, user, password string, channels []int, cache time.Durati
|
||||||
return res, err
|
return res, err
|
||||||
}, cache)
|
}, cache)
|
||||||
|
|
||||||
c.statusStsG = provider.ResettableCached(func() (StatusSTSResponse, error) {
|
c.statusStsG = plugin.ResettableCached(func() (StatusSTSResponse, error) {
|
||||||
parameters := url.Values{
|
parameters := url.Values{
|
||||||
"user": {c.user},
|
"user": {c.user},
|
||||||
"password": {c.password},
|
"password": {c.password},
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/evcc-io/evcc/api"
|
"github.com/evcc-io/evcc/api"
|
||||||
"github.com/evcc-io/evcc/provider"
|
"github.com/evcc-io/evcc/plugin"
|
||||||
"github.com/evcc-io/evcc/util"
|
"github.com/evcc-io/evcc/util"
|
||||||
"github.com/evcc-io/evcc/util/request"
|
"github.com/evcc-io/evcc/util/request"
|
||||||
)
|
)
|
||||||
|
|
@ -91,7 +91,7 @@ func NewTqEmFromConfig(other map[string]interface{}) (api.Meter, error) {
|
||||||
return nil, errors.New("no serial")
|
return nil, errors.New("no serial")
|
||||||
}
|
}
|
||||||
|
|
||||||
dataG := provider.Cached(func() (tqemData, error) {
|
dataG := plugin.Cached(func() (tqemData, error) {
|
||||||
var res tqemData
|
var res tqemData
|
||||||
|
|
||||||
uri := fmt.Sprintf("%s/mum-webservice/data.php", base)
|
uri := fmt.Sprintf("%s/mum-webservice/data.php", base)
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/evcc-io/evcc/api"
|
"github.com/evcc-io/evcc/api"
|
||||||
"github.com/evcc-io/evcc/provider"
|
"github.com/evcc-io/evcc/plugin"
|
||||||
"github.com/evcc-io/evcc/util"
|
"github.com/evcc-io/evcc/util"
|
||||||
"github.com/evcc-io/evcc/util/request"
|
"github.com/evcc-io/evcc/util/request"
|
||||||
)
|
)
|
||||||
|
|
@ -115,7 +115,7 @@ func NewTqEm420FromConfig(other map[string]interface{}) (api.Meter, error) {
|
||||||
|
|
||||||
base := util.DefaultScheme(strings.TrimRight(cc.URI, "/"), "http")
|
base := util.DefaultScheme(strings.TrimRight(cc.URI, "/"), "http")
|
||||||
|
|
||||||
dataG := provider.Cached(func() (TqEm420Data, error) {
|
dataG := plugin.Cached(func() (TqEm420Data, error) {
|
||||||
var res TqEm420Data
|
var res TqEm420Data
|
||||||
|
|
||||||
headers := map[string]string{
|
headers := map[string]string{
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"dario.cat/mergo"
|
"dario.cat/mergo"
|
||||||
"github.com/evcc-io/evcc/provider/mqtt"
|
"github.com/evcc-io/evcc/plugin/mqtt"
|
||||||
"github.com/evcc-io/evcc/util"
|
"github.com/evcc-io/evcc/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package provider
|
package plugin
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package provider
|
package plugin
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package provider
|
package plugin
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
@ -9,7 +9,7 @@ import (
|
||||||
"github.com/evcc-io/evcc/util"
|
"github.com/evcc-io/evcc/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
type calcProvider struct {
|
type calcPlugin struct {
|
||||||
add, mul, div []func() (float64, error)
|
add, mul, div []func() (float64, error)
|
||||||
abs, sign func() (float64, error)
|
abs, sign func() (float64, error)
|
||||||
}
|
}
|
||||||
|
|
@ -19,7 +19,7 @@ func init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewCalcFromConfig creates calc provider
|
// NewCalcFromConfig creates calc provider
|
||||||
func NewCalcFromConfig(ctx context.Context, other map[string]interface{}) (Provider, error) {
|
func NewCalcFromConfig(ctx context.Context, other map[string]interface{}) (Plugin, error) {
|
||||||
var cc struct {
|
var cc struct {
|
||||||
Add []Config
|
Add []Config
|
||||||
Mul []Config
|
Mul []Config
|
||||||
|
|
@ -43,10 +43,10 @@ func NewCalcFromConfig(ctx context.Context, other map[string]interface{}) (Provi
|
||||||
return nil, errors.New("can only have either add, mul, div, abs or sign")
|
return nil, errors.New("can only have either add, mul, div, abs or sign")
|
||||||
}
|
}
|
||||||
|
|
||||||
o := &calcProvider{}
|
o := new(calcPlugin)
|
||||||
|
|
||||||
for idx, cc := range cc.Add {
|
for idx, cc := range cc.Add {
|
||||||
f, err := NewFloatGetterFromConfig(ctx, cc)
|
f, err := cc.FloatGetter(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("add[%d]: %w", idx, err)
|
return nil, fmt.Errorf("add[%d]: %w", idx, err)
|
||||||
}
|
}
|
||||||
|
|
@ -54,7 +54,7 @@ func NewCalcFromConfig(ctx context.Context, other map[string]interface{}) (Provi
|
||||||
}
|
}
|
||||||
|
|
||||||
for idx, cc := range cc.Mul {
|
for idx, cc := range cc.Mul {
|
||||||
f, err := NewFloatGetterFromConfig(ctx, cc)
|
f, err := cc.FloatGetter(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("mul[%d]: %w", idx, err)
|
return nil, fmt.Errorf("mul[%d]: %w", idx, err)
|
||||||
}
|
}
|
||||||
|
|
@ -62,57 +62,53 @@ func NewCalcFromConfig(ctx context.Context, other map[string]interface{}) (Provi
|
||||||
}
|
}
|
||||||
|
|
||||||
for idx, cc := range cc.Div {
|
for idx, cc := range cc.Div {
|
||||||
f, err := NewFloatGetterFromConfig(ctx, cc)
|
f, err := cc.FloatGetter(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("div[%d]: %w", idx, err)
|
return nil, fmt.Errorf("div[%d]: %w", idx, err)
|
||||||
}
|
}
|
||||||
o.div = append(o.div, f)
|
o.div = append(o.div, f)
|
||||||
}
|
}
|
||||||
|
|
||||||
if cc.Abs != nil {
|
var err error
|
||||||
f, err := NewFloatGetterFromConfig(ctx, *cc.Abs)
|
|
||||||
if err != nil {
|
o.abs, err = cc.Abs.FloatGetter(ctx)
|
||||||
return nil, fmt.Errorf("abs: %w", err)
|
if err != nil {
|
||||||
}
|
return nil, fmt.Errorf("abs: %w", err)
|
||||||
o.abs = f
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if cc.Sign != nil {
|
o.sign, err = cc.Sign.FloatGetter(ctx)
|
||||||
f, err := NewFloatGetterFromConfig(ctx, *cc.Sign)
|
if err != nil {
|
||||||
if err != nil {
|
return nil, fmt.Errorf("sign: %w", err)
|
||||||
return nil, fmt.Errorf("sign: %w", err)
|
|
||||||
}
|
|
||||||
o.sign = f
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return o, nil
|
return o, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ IntProvider = (*calcProvider)(nil)
|
var _ IntGetter = (*calcPlugin)(nil)
|
||||||
|
|
||||||
func (o *calcProvider) IntGetter() (func() (int64, error), error) {
|
func (o *calcPlugin) IntGetter() (func() (int64, error), error) {
|
||||||
return func() (int64, error) {
|
return func() (int64, error) {
|
||||||
f, err := o.floatGetter()
|
f, err := o.floatGetter()
|
||||||
return int64(f), err
|
return int64(f), err
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ StringProvider = (*calcProvider)(nil)
|
var _ StringGetter = (*calcPlugin)(nil)
|
||||||
|
|
||||||
func (o *calcProvider) StringGetter() (func() (string, error), error) {
|
func (o *calcPlugin) StringGetter() (func() (string, error), error) {
|
||||||
return func() (string, error) {
|
return func() (string, error) {
|
||||||
f, err := o.floatGetter()
|
f, err := o.floatGetter()
|
||||||
return fmt.Sprintf("%c", int(f)), err
|
return fmt.Sprintf("%c", int(f)), err
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ FloatProvider = (*calcProvider)(nil)
|
var _ FloatGetter = (*calcPlugin)(nil)
|
||||||
|
|
||||||
func (o *calcProvider) FloatGetter() (func() (float64, error), error) {
|
func (o *calcPlugin) FloatGetter() (func() (float64, error), error) {
|
||||||
return o.floatGetter, nil
|
return o.floatGetter, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *calcProvider) floatGetter() (float64, error) {
|
func (o *calcPlugin) floatGetter() (float64, error) {
|
||||||
var res float64
|
var res float64
|
||||||
|
|
||||||
switch {
|
switch {
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package provider
|
package plugin
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
@ -10,7 +10,7 @@ import (
|
||||||
"github.com/spf13/cast"
|
"github.com/spf13/cast"
|
||||||
)
|
)
|
||||||
|
|
||||||
type switchChargerProvider struct {
|
type switchChargerPlugin struct {
|
||||||
charger api.Charger
|
charger api.Charger
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -19,7 +19,7 @@ func init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewChargerEnableFromConfig creates type conversion provider
|
// NewChargerEnableFromConfig creates type conversion provider
|
||||||
func NewChargerEnableFromConfig(ctx context.Context, other map[string]interface{}) (Provider, error) {
|
func NewChargerEnableFromConfig(ctx context.Context, other map[string]interface{}) (Plugin, error) {
|
||||||
var cc struct {
|
var cc struct {
|
||||||
Config config.Typed
|
Config config.Typed
|
||||||
}
|
}
|
||||||
|
|
@ -33,34 +33,34 @@ func NewChargerEnableFromConfig(ctx context.Context, other map[string]interface{
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
o := &switchChargerProvider{
|
o := &switchChargerPlugin{
|
||||||
charger: charger,
|
charger: charger,
|
||||||
}
|
}
|
||||||
|
|
||||||
return o, nil
|
return o, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ FloatProvider = (*switchChargerProvider)(nil)
|
var _ FloatGetter = (*switchChargerPlugin)(nil)
|
||||||
|
|
||||||
func (o *switchChargerProvider) FloatGetter() (func() (float64, error), error) {
|
func (o *switchChargerPlugin) FloatGetter() (func() (float64, error), error) {
|
||||||
return func() (float64, error) {
|
return func() (float64, error) {
|
||||||
v, err := o.charger.Enabled()
|
v, err := o.charger.Enabled()
|
||||||
return cast.ToFloat64(v), err
|
return cast.ToFloat64(v), err
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ IntProvider = (*switchChargerProvider)(nil)
|
var _ IntGetter = (*switchChargerPlugin)(nil)
|
||||||
|
|
||||||
func (o *switchChargerProvider) IntGetter() (func() (int64, error), error) {
|
func (o *switchChargerPlugin) IntGetter() (func() (int64, error), error) {
|
||||||
return func() (int64, error) {
|
return func() (int64, error) {
|
||||||
v, err := o.charger.Enabled()
|
v, err := o.charger.Enabled()
|
||||||
return cast.ToInt64(v), err
|
return cast.ToInt64(v), err
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ SetIntProvider = (*switchChargerProvider)(nil)
|
var _ IntSetter = (*switchChargerPlugin)(nil)
|
||||||
|
|
||||||
func (o *switchChargerProvider) IntSetter(param string) (func(int64) error, error) {
|
func (o *switchChargerPlugin) IntSetter(param string) (func(int64) error, error) {
|
||||||
return func(val int64) error {
|
return func(val int64) error {
|
||||||
b, err := cast.ToBoolE(val)
|
b, err := cast.ToBoolE(val)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -70,17 +70,17 @@ func (o *switchChargerProvider) IntSetter(param string) (func(int64) error, erro
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ BoolProvider = (*switchChargerProvider)(nil)
|
var _ BoolGetter = (*switchChargerPlugin)(nil)
|
||||||
|
|
||||||
func (o *switchChargerProvider) BoolGetter() (func() (bool, error), error) {
|
func (o *switchChargerPlugin) BoolGetter() (func() (bool, error), error) {
|
||||||
return func() (bool, error) {
|
return func() (bool, error) {
|
||||||
return o.charger.Enabled()
|
return o.charger.Enabled()
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ SetBoolProvider = (*switchChargerProvider)(nil)
|
var _ BoolSetter = (*switchChargerPlugin)(nil)
|
||||||
|
|
||||||
func (o *switchChargerProvider) BoolSetter(param string) (func(bool) error, error) {
|
func (o *switchChargerPlugin) BoolSetter(param string) (func(bool) error, error) {
|
||||||
return func(val bool) error {
|
return func(val bool) error {
|
||||||
return o.charger.Enable(val)
|
return o.charger.Enable(val)
|
||||||
}, nil
|
}, nil
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package provider
|
package plugin
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
@ -13,13 +13,13 @@ func init() {
|
||||||
registry.AddCtx("openwb", NewCombinedFromConfig)
|
registry.AddCtx("openwb", NewCombinedFromConfig)
|
||||||
}
|
}
|
||||||
|
|
||||||
// combinedProvider implements status conversion from openWB to api.Status
|
// combinedPlugin implements status conversion from openWB to api.Status
|
||||||
type combinedProvider struct {
|
type combinedPlugin struct {
|
||||||
plugged, charging func() (bool, error)
|
plugged, charging func() (bool, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewCombinedFromConfig creates combined provider
|
// NewCombinedFromConfig creates combined provider
|
||||||
func NewCombinedFromConfig(ctx context.Context, other map[string]interface{}) (Provider, error) {
|
func NewCombinedFromConfig(ctx context.Context, other map[string]interface{}) (Plugin, error) {
|
||||||
var cc struct {
|
var cc struct {
|
||||||
Plugged, Charging Config
|
Plugged, Charging Config
|
||||||
}
|
}
|
||||||
|
|
@ -28,33 +28,33 @@ func NewCombinedFromConfig(ctx context.Context, other map[string]interface{}) (P
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
plugged, err := NewBoolGetterFromConfig(ctx, cc.Plugged)
|
plugged, err := cc.Plugged.BoolGetter(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("plugged: %w", err)
|
return nil, fmt.Errorf("plugged: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
charging, err := NewBoolGetterFromConfig(ctx, cc.Charging)
|
charging, err := cc.Charging.BoolGetter(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("charging: %w", err)
|
return nil, fmt.Errorf("charging: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
o := NewCombinedProvider(plugged, charging)
|
o := NewCombinedPlugin(plugged, charging)
|
||||||
|
|
||||||
return o, nil
|
return o, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewCombinedProvider creates provider for OpenWB status converted from MQTT topics
|
// NewCombinedPlugin creates provider for OpenWB status converted from MQTT topics
|
||||||
func NewCombinedProvider(plugged, charging func() (bool, error)) *combinedProvider {
|
func NewCombinedPlugin(plugged, charging func() (bool, error)) *combinedPlugin {
|
||||||
return &combinedProvider{
|
return &combinedPlugin{
|
||||||
plugged: plugged,
|
plugged: plugged,
|
||||||
charging: charging,
|
charging: charging,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ StringProvider = (*combinedProvider)(nil)
|
var _ StringGetter = (*combinedPlugin)(nil)
|
||||||
|
|
||||||
// StringGetter returns string from OpenWB charging/ plugged status
|
// StringGetter returns string from OpenWB charging/ plugged status
|
||||||
func (o *combinedProvider) StringGetter() (func() (string, error), error) {
|
func (o *combinedPlugin) StringGetter() (func() (string, error), error) {
|
||||||
return func() (string, error) {
|
return func() (string, error) {
|
||||||
charging, err := o.charging()
|
charging, err := o.charging()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
160
plugin/config.go
Normal file
160
plugin/config.go
Normal file
|
|
@ -0,0 +1,160 @@
|
||||||
|
package plugin
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
reg "github.com/evcc-io/evcc/util/registry"
|
||||||
|
)
|
||||||
|
|
||||||
|
var registry = reg.New[Plugin]("plugin")
|
||||||
|
|
||||||
|
// plugin types
|
||||||
|
type (
|
||||||
|
Plugin interface{}
|
||||||
|
Getters interface {
|
||||||
|
StringGetter
|
||||||
|
FloatGetter
|
||||||
|
IntGetter
|
||||||
|
BoolGetter
|
||||||
|
}
|
||||||
|
StringGetter interface {
|
||||||
|
StringGetter() (func() (string, error), error)
|
||||||
|
}
|
||||||
|
FloatGetter interface {
|
||||||
|
FloatGetter() (func() (float64, error), error)
|
||||||
|
}
|
||||||
|
IntGetter interface {
|
||||||
|
IntGetter() (func() (int64, error), error)
|
||||||
|
}
|
||||||
|
BoolGetter interface {
|
||||||
|
BoolGetter() (func() (bool, error), error)
|
||||||
|
}
|
||||||
|
StringSetter interface {
|
||||||
|
StringSetter(param string) (func(string) error, error)
|
||||||
|
}
|
||||||
|
FloatSetter interface {
|
||||||
|
FloatSetter(param string) (func(float64) error, error)
|
||||||
|
}
|
||||||
|
IntSetter interface {
|
||||||
|
IntSetter(param string) (func(int64) error, error)
|
||||||
|
}
|
||||||
|
BoolSetter interface {
|
||||||
|
BoolSetter(param string) (func(bool) error, error)
|
||||||
|
}
|
||||||
|
BytesSetter interface {
|
||||||
|
BytesSetter(param string) (func([]byte) error, error)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
// Config is the general plugin config
|
||||||
|
type Config struct {
|
||||||
|
Source string
|
||||||
|
Other map[string]any `mapstructure:",remain" yaml:",inline"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func plugin[T any](typ string, ctx context.Context, config *Config) (T, error) {
|
||||||
|
var zero T
|
||||||
|
|
||||||
|
if config == nil {
|
||||||
|
return zero, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
factory, err := registry.Get(config.Source)
|
||||||
|
if err != nil {
|
||||||
|
return zero, err
|
||||||
|
}
|
||||||
|
|
||||||
|
plugin, err := factory(ctx, config.Other)
|
||||||
|
if err != nil {
|
||||||
|
return zero, err
|
||||||
|
}
|
||||||
|
|
||||||
|
prov, ok := plugin.(T)
|
||||||
|
if !ok {
|
||||||
|
return zero, fmt.Errorf("invalid plugin source for type %s: %s", typ, config.Source)
|
||||||
|
}
|
||||||
|
|
||||||
|
return prov, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Config) IntGetter(ctx context.Context) (func() (int64, error), error) {
|
||||||
|
prov, err := plugin[IntGetter]("int", ctx, c)
|
||||||
|
if prov == nil || err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return prov.IntGetter()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Config) FloatGetter(ctx context.Context) (func() (float64, error), error) {
|
||||||
|
prov, err := plugin[FloatGetter]("float", ctx, c)
|
||||||
|
if prov == nil || err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return prov.FloatGetter()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Config) StringGetter(ctx context.Context) (func() (string, error), error) {
|
||||||
|
prov, err := plugin[StringGetter]("string", ctx, c)
|
||||||
|
if prov == nil || err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return prov.StringGetter()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Config) BoolGetter(ctx context.Context) (func() (bool, error), error) {
|
||||||
|
prov, err := plugin[BoolGetter]("bool", ctx, c)
|
||||||
|
if prov == nil || err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return prov.BoolGetter()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Config) IntSetter(ctx context.Context, param string) (func(int64) error, error) {
|
||||||
|
prov, err := plugin[IntSetter]("int", ctx, c)
|
||||||
|
if prov == nil || err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return prov.IntSetter(param)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Config) FloatSetter(ctx context.Context, param string) (func(float642 float64) error, error) {
|
||||||
|
prov, err := plugin[FloatSetter]("float", ctx, c)
|
||||||
|
if prov == nil || err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return prov.FloatSetter(param)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Config) StringSetter(ctx context.Context, param string) (func(string) error, error) {
|
||||||
|
prov, err := plugin[StringSetter]("string", ctx, c)
|
||||||
|
if prov == nil || err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return prov.StringSetter(param)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Config) BoolSetter(ctx context.Context, param string) (func(bool) error, error) {
|
||||||
|
prov, err := plugin[BoolSetter]("bool", ctx, c)
|
||||||
|
if prov == nil || err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return prov.BoolSetter(param)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Config) BytesSetter(ctx context.Context, param string) (func([]byte) error, error) {
|
||||||
|
prov, err := plugin[BytesSetter]("bytes", ctx, c)
|
||||||
|
if prov == nil || err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return prov.BytesSetter(param)
|
||||||
|
}
|
||||||
20
plugin/config_test.go
Normal file
20
plugin/config_test.go
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
package plugin
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestConfig(t *testing.T) {
|
||||||
|
var c *Config
|
||||||
|
|
||||||
|
g, err := c.BoolGetter(context.TODO())
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.Nil(t, g)
|
||||||
|
|
||||||
|
s, err := c.IntSetter(context.TODO(), "foo")
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.Nil(t, s)
|
||||||
|
}
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package provider
|
package plugin
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
@ -6,11 +6,11 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/evcc-io/evcc/provider/pipeline"
|
"github.com/evcc-io/evcc/plugin/pipeline"
|
||||||
"github.com/evcc-io/evcc/util"
|
"github.com/evcc-io/evcc/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
type constProvider struct {
|
type constPlugin struct {
|
||||||
ctx context.Context
|
ctx context.Context
|
||||||
str string
|
str string
|
||||||
set Config
|
set Config
|
||||||
|
|
@ -21,7 +21,7 @@ func init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewConstFromConfig creates const provider
|
// NewConstFromConfig creates const provider
|
||||||
func NewConstFromConfig(ctx context.Context, other map[string]interface{}) (Provider, error) {
|
func NewConstFromConfig(ctx context.Context, other map[string]interface{}) (Plugin, error) {
|
||||||
var cc struct {
|
var cc struct {
|
||||||
Value string
|
Value string
|
||||||
pipeline.Settings `mapstructure:",squash"`
|
pipeline.Settings `mapstructure:",squash"`
|
||||||
|
|
@ -32,7 +32,7 @@ func NewConstFromConfig(ctx context.Context, other map[string]interface{}) (Prov
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
p := &constProvider{
|
p := &constPlugin{
|
||||||
ctx: ctx,
|
ctx: ctx,
|
||||||
str: cc.Value,
|
str: cc.Value,
|
||||||
set: cc.Set,
|
set: cc.Set,
|
||||||
|
|
@ -41,17 +41,17 @@ func NewConstFromConfig(ctx context.Context, other map[string]interface{}) (Prov
|
||||||
return p, nil
|
return p, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ StringProvider = (*constProvider)(nil)
|
var _ StringGetter = (*constPlugin)(nil)
|
||||||
|
|
||||||
func (p *constProvider) StringGetter() (func() (string, error), error) {
|
func (p *constPlugin) StringGetter() (func() (string, error), error) {
|
||||||
return func() (string, error) {
|
return func() (string, error) {
|
||||||
return p.str, nil
|
return p.str, nil
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ IntProvider = (*constProvider)(nil)
|
var _ IntGetter = (*constPlugin)(nil)
|
||||||
|
|
||||||
func (p *constProvider) IntGetter() (func() (int64, error), error) {
|
func (p *constPlugin) IntGetter() (func() (int64, error), error) {
|
||||||
val, err := strconv.ParseInt(p.str, 10, 64)
|
val, err := strconv.ParseInt(p.str, 10, 64)
|
||||||
if err != nil && p.str == "" {
|
if err != nil && p.str == "" {
|
||||||
err = nil
|
err = nil
|
||||||
|
|
@ -62,9 +62,9 @@ func (p *constProvider) IntGetter() (func() (int64, error), error) {
|
||||||
}, err
|
}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ FloatProvider = (*constProvider)(nil)
|
var _ FloatGetter = (*constPlugin)(nil)
|
||||||
|
|
||||||
func (p *constProvider) FloatGetter() (func() (float64, error), error) {
|
func (p *constPlugin) FloatGetter() (func() (float64, error), error) {
|
||||||
val, err := strconv.ParseFloat(p.str, 64)
|
val, err := strconv.ParseFloat(p.str, 64)
|
||||||
if err != nil && p.str == "" {
|
if err != nil && p.str == "" {
|
||||||
err = nil
|
err = nil
|
||||||
|
|
@ -75,9 +75,9 @@ func (p *constProvider) FloatGetter() (func() (float64, error), error) {
|
||||||
}, err
|
}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ BoolProvider = (*constProvider)(nil)
|
var _ BoolGetter = (*constPlugin)(nil)
|
||||||
|
|
||||||
func (p *constProvider) BoolGetter() (func() (bool, error), error) {
|
func (p *constPlugin) BoolGetter() (func() (bool, error), error) {
|
||||||
val, err := strconv.ParseBool(p.str)
|
val, err := strconv.ParseBool(p.str)
|
||||||
if err != nil && p.str == "" {
|
if err != nil && p.str == "" {
|
||||||
err = nil
|
err = nil
|
||||||
|
|
@ -88,10 +88,10 @@ func (p *constProvider) BoolGetter() (func() (bool, error), error) {
|
||||||
}, err
|
}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ SetIntProvider = (*constProvider)(nil)
|
var _ IntSetter = (*constPlugin)(nil)
|
||||||
|
|
||||||
func (p *constProvider) IntSetter(param string) (func(int64) error, error) {
|
func (p *constPlugin) IntSetter(param string) (func(int64) error, error) {
|
||||||
set, err := NewIntSetterFromConfig(p.ctx, param, p.set)
|
set, err := p.set.IntSetter(p.ctx, param)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
@ -106,10 +106,10 @@ func (p *constProvider) IntSetter(param string) (func(int64) error, error) {
|
||||||
}, err
|
}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ SetFloatProvider = (*constProvider)(nil)
|
var _ FloatSetter = (*constPlugin)(nil)
|
||||||
|
|
||||||
func (p *constProvider) FloatSetter(param string) (func(float64) error, error) {
|
func (p *constPlugin) FloatSetter(param string) (func(float64) error, error) {
|
||||||
set, err := NewFloatSetterFromConfig(p.ctx, param, p.set)
|
set, err := p.set.FloatSetter(p.ctx, param)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
@ -124,10 +124,10 @@ func (p *constProvider) FloatSetter(param string) (func(float64) error, error) {
|
||||||
}, err
|
}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ SetBoolProvider = (*constProvider)(nil)
|
var _ BoolSetter = (*constPlugin)(nil)
|
||||||
|
|
||||||
func (p *constProvider) BoolSetter(param string) (func(bool) error, error) {
|
func (p *constPlugin) BoolSetter(param string) (func(bool) error, error) {
|
||||||
set, err := NewBoolSetterFromConfig(p.ctx, param, p.set)
|
set, err := p.set.BoolSetter(p.ctx, param)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
@ -142,10 +142,10 @@ func (p *constProvider) BoolSetter(param string) (func(bool) error, error) {
|
||||||
}, err
|
}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ SetBytesProvider = (*constProvider)(nil)
|
var _ BytesSetter = (*constPlugin)(nil)
|
||||||
|
|
||||||
func (p *constProvider) BytesSetter(param string) (func([]byte) error, error) {
|
func (p *constPlugin) BytesSetter(param string) (func([]byte) error, error) {
|
||||||
set, err := NewBytesSetterFromConfig(p.ctx, param, p.set)
|
set, err := p.set.BytesSetter(p.ctx, param)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package provider
|
package plugin
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
@ -12,7 +12,7 @@ func TestConst(t *testing.T) {
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
{
|
{
|
||||||
g, err := p.(StringProvider).StringGetter()
|
g, err := p.(StringGetter).StringGetter()
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
v, err := g()
|
v, err := g()
|
||||||
|
|
@ -21,7 +21,7 @@ func TestConst(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
g, err := p.(IntProvider).IntGetter()
|
g, err := p.(IntGetter).IntGetter()
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
v, err := g()
|
v, err := g()
|
||||||
|
|
@ -30,7 +30,7 @@ func TestConst(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
g, err := p.(FloatProvider).FloatGetter()
|
g, err := p.(FloatGetter).FloatGetter()
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
v, err := g()
|
v, err := g()
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package provider
|
package plugin
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
@ -8,7 +8,7 @@ import (
|
||||||
"github.com/evcc-io/evcc/util"
|
"github.com/evcc-io/evcc/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
type convertProvider struct {
|
type convertPlugin struct {
|
||||||
ctx context.Context
|
ctx context.Context
|
||||||
Convert string
|
Convert string
|
||||||
Set Config
|
Set Config
|
||||||
|
|
@ -19,8 +19,8 @@ func init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewConvertFromConfig creates type conversion provider
|
// NewConvertFromConfig creates type conversion provider
|
||||||
func NewConvertFromConfig(ctx context.Context, other map[string]interface{}) (Provider, error) {
|
func NewConvertFromConfig(ctx context.Context, other map[string]interface{}) (Plugin, error) {
|
||||||
cc := convertProvider{
|
cc := convertPlugin{
|
||||||
ctx: ctx,
|
ctx: ctx,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -31,12 +31,12 @@ func NewConvertFromConfig(ctx context.Context, other map[string]interface{}) (Pr
|
||||||
return &cc, nil
|
return &cc, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ SetFloatProvider = (*convertProvider)(nil)
|
var _ FloatSetter = (*convertPlugin)(nil)
|
||||||
|
|
||||||
func (o *convertProvider) FloatSetter(param string) (func(float64) error, error) {
|
func (o *convertPlugin) FloatSetter(param string) (func(float64) error, error) {
|
||||||
switch o.Convert {
|
switch o.Convert {
|
||||||
case "float2int":
|
case "float2int":
|
||||||
set, err := NewIntSetterFromConfig(o.ctx, param, o.Set)
|
set, err := o.Set.IntSetter(o.ctx, param)
|
||||||
|
|
||||||
return func(val float64) error {
|
return func(val float64) error {
|
||||||
return set(int64(val))
|
return set(int64(val))
|
||||||
|
|
@ -47,19 +47,19 @@ func (o *convertProvider) FloatSetter(param string) (func(float64) error, error)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ SetIntProvider = (*convertProvider)(nil)
|
var _ IntSetter = (*convertPlugin)(nil)
|
||||||
|
|
||||||
func (o *convertProvider) IntSetter(param string) (func(int64) error, error) {
|
func (o *convertPlugin) IntSetter(param string) (func(int64) error, error) {
|
||||||
switch o.Convert {
|
switch o.Convert {
|
||||||
case "int2float":
|
case "int2float":
|
||||||
set, err := NewFloatSetterFromConfig(o.ctx, param, o.Set)
|
set, err := o.Set.FloatSetter(o.ctx, param)
|
||||||
|
|
||||||
return func(val int64) error {
|
return func(val int64) error {
|
||||||
return set(float64(val))
|
return set(float64(val))
|
||||||
}, err
|
}, err
|
||||||
|
|
||||||
case "int2bytes":
|
case "int2bytes":
|
||||||
set, err := NewBytesSetterFromConfig(o.ctx, param, o.Set)
|
set, err := o.Set.BytesSetter(o.ctx, param)
|
||||||
|
|
||||||
return func(val int64) error {
|
return func(val int64) error {
|
||||||
b := make([]byte, 8)
|
b := make([]byte, 8)
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package provider
|
package plugin
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
@ -6,7 +6,7 @@ import (
|
||||||
"github.com/evcc-io/evcc/util"
|
"github.com/evcc-io/evcc/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
type errorProvider struct {
|
type errorPlugin struct {
|
||||||
err error
|
err error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -15,7 +15,7 @@ func init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewErrorFromConfig creates error provider
|
// NewErrorFromConfig creates error provider
|
||||||
func NewErrorFromConfig(other map[string]interface{}) (Provider, error) {
|
func NewErrorFromConfig(other map[string]interface{}) (Plugin, error) {
|
||||||
var cc struct {
|
var cc struct {
|
||||||
Error string
|
Error string
|
||||||
}
|
}
|
||||||
|
|
@ -29,16 +29,16 @@ func NewErrorFromConfig(other map[string]interface{}) (Provider, error) {
|
||||||
return nil, fmt.Errorf("unknown error: %s", cc.Error)
|
return nil, fmt.Errorf("unknown error: %s", cc.Error)
|
||||||
}
|
}
|
||||||
|
|
||||||
o := &errorProvider{
|
o := &errorPlugin{
|
||||||
err: err,
|
err: err,
|
||||||
}
|
}
|
||||||
|
|
||||||
return o, nil
|
return o, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ SetIntProvider = (*errorProvider)(nil)
|
var _ IntSetter = (*errorPlugin)(nil)
|
||||||
|
|
||||||
func (o *errorProvider) IntSetter(param string) (func(int64) error, error) {
|
func (o *errorPlugin) IntSetter(param string) (func(int64) error, error) {
|
||||||
return func(int64) error {
|
return func(int64) error {
|
||||||
return o.err
|
return o.err
|
||||||
}, nil
|
}, nil
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package provider
|
package plugin
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
@ -7,22 +7,22 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type getter struct {
|
type getter struct {
|
||||||
sp StringProvider
|
get StringGetter
|
||||||
scale float64
|
scale float64
|
||||||
}
|
}
|
||||||
|
|
||||||
func defaultGetters(sp StringProvider, scale float64) *getter {
|
func defaultGetters(get StringGetter, scale float64) *getter {
|
||||||
return &getter{
|
return &getter{
|
||||||
sp: sp,
|
get: get,
|
||||||
scale: scale,
|
scale: scale,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ FloatProvider = (*getter)(nil)
|
var _ FloatGetter = (*getter)(nil)
|
||||||
|
|
||||||
// FloatGetter parses float from exec result
|
// FloatGetter parses float from exec result
|
||||||
func (p *getter) FloatGetter() (func() (float64, error), error) {
|
func (p *getter) FloatGetter() (func() (float64, error), error) {
|
||||||
g, err := p.sp.StringGetter()
|
g, err := p.get.StringGetter()
|
||||||
|
|
||||||
return func() (float64, error) {
|
return func() (float64, error) {
|
||||||
s, err := g()
|
s, err := g()
|
||||||
|
|
@ -39,7 +39,7 @@ func (p *getter) FloatGetter() (func() (float64, error), error) {
|
||||||
}, err
|
}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ IntProvider = (*getter)(nil)
|
var _ IntGetter = (*getter)(nil)
|
||||||
|
|
||||||
// IntGetter parses int64 from exec result
|
// IntGetter parses int64 from exec result
|
||||||
func (p *getter) IntGetter() (func() (int64, error), error) {
|
func (p *getter) IntGetter() (func() (int64, error), error) {
|
||||||
|
|
@ -55,11 +55,11 @@ func (p *getter) IntGetter() (func() (int64, error), error) {
|
||||||
}, err
|
}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ BoolProvider = (*getter)(nil)
|
var _ BoolGetter = (*getter)(nil)
|
||||||
|
|
||||||
// BoolGetter parses bool from exec result. "on", "true" and 1 are considered truish.
|
// BoolGetter parses bool from exec result. "on", "true" and 1 are considered truish.
|
||||||
func (p *getter) BoolGetter() (func() (bool, error), error) {
|
func (p *getter) BoolGetter() (func() (bool, error), error) {
|
||||||
g, err := p.sp.StringGetter()
|
g, err := p.get.StringGetter()
|
||||||
|
|
||||||
return func() (bool, error) {
|
return func() (bool, error) {
|
||||||
s, err := g()
|
s, err := g()
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package provider
|
package plugin
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
@ -7,7 +7,7 @@ import (
|
||||||
"reflect"
|
"reflect"
|
||||||
|
|
||||||
"github.com/cenkalti/backoff/v4"
|
"github.com/cenkalti/backoff/v4"
|
||||||
"github.com/evcc-io/evcc/provider/golang"
|
"github.com/evcc-io/evcc/plugin/golang"
|
||||||
"github.com/evcc-io/evcc/util"
|
"github.com/evcc-io/evcc/util"
|
||||||
"github.com/traefik/yaegi/interp"
|
"github.com/traefik/yaegi/interp"
|
||||||
)
|
)
|
||||||
|
|
@ -21,11 +21,11 @@ type Go struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
registry.AddCtx("go", NewGoProviderFromConfig)
|
registry.AddCtx("go", NewGoPluginFromConfig)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewGoProviderFromConfig creates a Go provider
|
// NewGoPluginFromConfig creates a Go provider
|
||||||
func NewGoProviderFromConfig(ctx context.Context, other map[string]interface{}) (Provider, error) {
|
func NewGoPluginFromConfig(ctx context.Context, other map[string]interface{}) (Plugin, error) {
|
||||||
var cc struct {
|
var cc struct {
|
||||||
VM string
|
VM string
|
||||||
Script string
|
Script string
|
||||||
|
|
@ -62,7 +62,7 @@ func NewGoProviderFromConfig(ctx context.Context, other map[string]interface{})
|
||||||
return p, nil
|
return p, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ FloatProvider = (*Go)(nil)
|
var _ FloatGetter = (*Go)(nil)
|
||||||
|
|
||||||
// FloatGetter parses float from request
|
// FloatGetter parses float from request
|
||||||
func (p *Go) FloatGetter() (func() (float64, error), error) {
|
func (p *Go) FloatGetter() (func() (float64, error), error) {
|
||||||
|
|
@ -81,7 +81,7 @@ func (p *Go) FloatGetter() (func() (float64, error), error) {
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ IntProvider = (*Go)(nil)
|
var _ IntGetter = (*Go)(nil)
|
||||||
|
|
||||||
// IntGetter parses int64 from request
|
// IntGetter parses int64 from request
|
||||||
func (p *Go) IntGetter() (func() (int64, error), error) {
|
func (p *Go) IntGetter() (func() (int64, error), error) {
|
||||||
|
|
@ -100,7 +100,7 @@ func (p *Go) IntGetter() (func() (int64, error), error) {
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ StringProvider = (*Go)(nil)
|
var _ StringGetter = (*Go)(nil)
|
||||||
|
|
||||||
// StringGetter parses string from request
|
// StringGetter parses string from request
|
||||||
func (p *Go) StringGetter() (func() (string, error), error) {
|
func (p *Go) StringGetter() (func() (string, error), error) {
|
||||||
|
|
@ -119,7 +119,7 @@ func (p *Go) StringGetter() (func() (string, error), error) {
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ BoolProvider = (*Go)(nil)
|
var _ BoolGetter = (*Go)(nil)
|
||||||
|
|
||||||
// BoolGetter parses bool from request
|
// BoolGetter parses bool from request
|
||||||
func (p *Go) BoolGetter() (func() (bool, error), error) {
|
func (p *Go) BoolGetter() (func() (bool, error), error) {
|
||||||
|
|
@ -192,7 +192,7 @@ func (p *Go) setParam(param string, val any) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ SetIntProvider = (*Go)(nil)
|
var _ IntSetter = (*Go)(nil)
|
||||||
|
|
||||||
// IntSetter sends int request
|
// IntSetter sends int request
|
||||||
func (p *Go) IntSetter(param string) (func(int64) error, error) {
|
func (p *Go) IntSetter(param string) (func(int64) error, error) {
|
||||||
|
|
@ -201,7 +201,7 @@ func (p *Go) IntSetter(param string) (func(int64) error, error) {
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ SetFloatProvider = (*Go)(nil)
|
var _ FloatSetter = (*Go)(nil)
|
||||||
|
|
||||||
// FloatSetter sends float request
|
// FloatSetter sends float request
|
||||||
func (p *Go) FloatSetter(param string) (func(float64) error, error) {
|
func (p *Go) FloatSetter(param string) (func(float64) error, error) {
|
||||||
|
|
@ -210,7 +210,7 @@ func (p *Go) FloatSetter(param string) (func(float64) error, error) {
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ SetStringProvider = (*Go)(nil)
|
var _ StringSetter = (*Go)(nil)
|
||||||
|
|
||||||
// StringSetter sends string request
|
// StringSetter sends string request
|
||||||
func (p *Go) StringSetter(param string) (func(string) error, error) {
|
func (p *Go) StringSetter(param string) (func(string) error, error) {
|
||||||
|
|
@ -219,7 +219,7 @@ func (p *Go) StringSetter(param string) (func(string) error, error) {
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ SetBoolProvider = (*Go)(nil)
|
var _ BoolSetter = (*Go)(nil)
|
||||||
|
|
||||||
// BoolSetter sends bool request
|
// BoolSetter sends bool request
|
||||||
func (p *Go) BoolSetter(param string) (func(bool) error, error) {
|
func (p *Go) BoolSetter(param string) (func(bool) error, error) {
|
||||||
|
|
@ -4,7 +4,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/evcc-io/evcc/provider/golang/stdlib"
|
"github.com/evcc-io/evcc/plugin/golang/stdlib"
|
||||||
"github.com/traefik/yaegi/interp"
|
"github.com/traefik/yaegi/interp"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package provider
|
package plugin
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package provider
|
package plugin
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
@ -8,7 +8,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/evcc-io/evcc/provider/pipeline"
|
"github.com/evcc-io/evcc/plugin/pipeline"
|
||||||
"github.com/evcc-io/evcc/util"
|
"github.com/evcc-io/evcc/util"
|
||||||
"github.com/evcc-io/evcc/util/request"
|
"github.com/evcc-io/evcc/util/request"
|
||||||
"github.com/evcc-io/evcc/util/transport"
|
"github.com/evcc-io/evcc/util/transport"
|
||||||
|
|
@ -31,7 +31,7 @@ type HTTP struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
registry.AddCtx("http", NewHTTPProviderFromConfig)
|
registry.AddCtx("http", NewHTTPPluginFromConfig)
|
||||||
}
|
}
|
||||||
|
|
||||||
var mc = httpcache.NewMemoryCache()
|
var mc = httpcache.NewMemoryCache()
|
||||||
|
|
@ -41,8 +41,8 @@ type Auth struct {
|
||||||
Type, User, Password string
|
Type, User, Password string
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewHTTPProviderFromConfig creates a HTTP provider
|
// NewHTTPPluginFromConfig creates a HTTP provider
|
||||||
func NewHTTPProviderFromConfig(ctx context.Context, other map[string]interface{}) (Provider, error) {
|
func NewHTTPPluginFromConfig(ctx context.Context, other map[string]interface{}) (Plugin, error) {
|
||||||
cc := struct {
|
cc := struct {
|
||||||
URI, Method string
|
URI, Method string
|
||||||
Headers map[string]string
|
Headers map[string]string
|
||||||
|
|
@ -217,7 +217,7 @@ func (p *HTTP) set(param string, val interface{}) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ SetIntProvider = (*HTTP)(nil)
|
var _ IntSetter = (*HTTP)(nil)
|
||||||
|
|
||||||
// IntSetter sends int request
|
// IntSetter sends int request
|
||||||
func (p *HTTP) IntSetter(param string) (func(int64) error, error) {
|
func (p *HTTP) IntSetter(param string) (func(int64) error, error) {
|
||||||
|
|
@ -226,7 +226,7 @@ func (p *HTTP) IntSetter(param string) (func(int64) error, error) {
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ SetFloatProvider = (*HTTP)(nil)
|
var _ FloatSetter = (*HTTP)(nil)
|
||||||
|
|
||||||
// FloatSetter sends int request
|
// FloatSetter sends int request
|
||||||
func (p *HTTP) FloatSetter(param string) (func(float64) error, error) {
|
func (p *HTTP) FloatSetter(param string) (func(float64) error, error) {
|
||||||
|
|
@ -235,7 +235,7 @@ func (p *HTTP) FloatSetter(param string) (func(float64) error, error) {
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ SetStringProvider = (*HTTP)(nil)
|
var _ StringSetter = (*HTTP)(nil)
|
||||||
|
|
||||||
// StringSetter sends string request
|
// StringSetter sends string request
|
||||||
func (p *HTTP) StringSetter(param string) (func(string) error, error) {
|
func (p *HTTP) StringSetter(param string) (func(string) error, error) {
|
||||||
|
|
@ -244,7 +244,7 @@ func (p *HTTP) StringSetter(param string) (func(string) error, error) {
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ SetBoolProvider = (*HTTP)(nil)
|
var _ BoolSetter = (*HTTP)(nil)
|
||||||
|
|
||||||
// BoolSetter sends bool request
|
// BoolSetter sends bool request
|
||||||
func (p *HTTP) BoolSetter(param string) (func(bool) error, error) {
|
func (p *HTTP) BoolSetter(param string) (func(bool) error, error) {
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package provider
|
package plugin
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package provider
|
package plugin
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
@ -7,7 +7,7 @@ import (
|
||||||
"github.com/evcc-io/evcc/util"
|
"github.com/evcc-io/evcc/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ignoreProvider struct {
|
type ignorePlugin struct {
|
||||||
ctx context.Context
|
ctx context.Context
|
||||||
err string
|
err string
|
||||||
set Config
|
set Config
|
||||||
|
|
@ -18,7 +18,7 @@ func init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewIgnoreFromConfig creates const provider
|
// NewIgnoreFromConfig creates const provider
|
||||||
func NewIgnoreFromConfig(ctx context.Context, other map[string]interface{}) (Provider, error) {
|
func NewIgnoreFromConfig(ctx context.Context, other map[string]interface{}) (Plugin, error) {
|
||||||
var cc struct {
|
var cc struct {
|
||||||
Error string
|
Error string
|
||||||
Set Config
|
Set Config
|
||||||
|
|
@ -28,7 +28,7 @@ func NewIgnoreFromConfig(ctx context.Context, other map[string]interface{}) (Pro
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
o := &ignoreProvider{
|
o := &ignorePlugin{
|
||||||
ctx: ctx,
|
ctx: ctx,
|
||||||
err: cc.Error,
|
err: cc.Error,
|
||||||
set: cc.Set,
|
set: cc.Set,
|
||||||
|
|
@ -37,7 +37,7 @@ func NewIgnoreFromConfig(ctx context.Context, other map[string]interface{}) (Pro
|
||||||
return o, nil
|
return o, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ SetIntProvider = (*ignoreProvider)(nil)
|
var _ IntSetter = (*ignorePlugin)(nil)
|
||||||
|
|
||||||
func ignoreError[T any](fun func(T) error, match string) func(T) error {
|
func ignoreError[T any](fun func(T) error, match string) func(T) error {
|
||||||
return func(val T) error {
|
return func(val T) error {
|
||||||
|
|
@ -48,8 +48,8 @@ func ignoreError[T any](fun func(T) error, match string) func(T) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *ignoreProvider) IntSetter(param string) (func(int64) error, error) {
|
func (o *ignorePlugin) IntSetter(param string) (func(int64) error, error) {
|
||||||
set, err := NewIntSetterFromConfig(o.ctx, param, o.set)
|
set, err := o.set.IntSetter(o.ctx, param)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
@ -57,10 +57,10 @@ func (o *ignoreProvider) IntSetter(param string) (func(int64) error, error) {
|
||||||
return ignoreError(set, o.err), nil
|
return ignoreError(set, o.err), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ SetFloatProvider = (*ignoreProvider)(nil)
|
var _ FloatSetter = (*ignorePlugin)(nil)
|
||||||
|
|
||||||
func (o *ignoreProvider) FloatSetter(param string) (func(float64) error, error) {
|
func (o *ignorePlugin) FloatSetter(param string) (func(float64) error, error) {
|
||||||
set, err := NewFloatSetterFromConfig(o.ctx, param, o.set)
|
set, err := o.set.FloatSetter(o.ctx, param)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
@ -68,10 +68,10 @@ func (o *ignoreProvider) FloatSetter(param string) (func(float64) error, error)
|
||||||
return ignoreError(set, o.err), nil
|
return ignoreError(set, o.err), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ SetBoolProvider = (*ignoreProvider)(nil)
|
var _ BoolSetter = (*ignorePlugin)(nil)
|
||||||
|
|
||||||
func (o *ignoreProvider) BoolSetter(param string) (func(bool) error, error) {
|
func (o *ignorePlugin) BoolSetter(param string) (func(bool) error, error) {
|
||||||
set, err := NewBoolSetterFromConfig(o.ctx, param, o.set)
|
set, err := o.set.BoolSetter(o.ctx, param)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
@ -79,10 +79,10 @@ func (o *ignoreProvider) BoolSetter(param string) (func(bool) error, error) {
|
||||||
return ignoreError(set, o.err), nil
|
return ignoreError(set, o.err), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ SetBytesProvider = (*ignoreProvider)(nil)
|
var _ BytesSetter = (*ignorePlugin)(nil)
|
||||||
|
|
||||||
func (o *ignoreProvider) BytesSetter(param string) (func([]byte) error, error) {
|
func (o *ignorePlugin) BytesSetter(param string) (func([]byte) error, error) {
|
||||||
set, err := NewBytesSetterFromConfig(o.ctx, param, o.set)
|
set, err := o.set.BytesSetter(o.ctx, param)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
@ -1,11 +1,11 @@
|
||||||
package provider
|
package plugin
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/cenkalti/backoff/v4"
|
"github.com/cenkalti/backoff/v4"
|
||||||
"github.com/evcc-io/evcc/provider/javascript"
|
"github.com/evcc-io/evcc/plugin/javascript"
|
||||||
"github.com/evcc-io/evcc/util"
|
"github.com/evcc-io/evcc/util"
|
||||||
"github.com/robertkrimen/otto"
|
"github.com/robertkrimen/otto"
|
||||||
"github.com/spf13/cast"
|
"github.com/spf13/cast"
|
||||||
|
|
@ -20,11 +20,11 @@ type Javascript struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
registry.AddCtx("js", NewJavascriptProviderFromConfig)
|
registry.AddCtx("js", NewJavascriptPluginFromConfig)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewJavascriptProviderFromConfig creates a Javascript provider
|
// NewJavascriptPluginFromConfig creates a Javascript provider
|
||||||
func NewJavascriptProviderFromConfig(ctx context.Context, other map[string]interface{}) (Provider, error) {
|
func NewJavascriptPluginFromConfig(ctx context.Context, other map[string]interface{}) (Plugin, error) {
|
||||||
var cc struct {
|
var cc struct {
|
||||||
VM string
|
VM string
|
||||||
Script string
|
Script string
|
||||||
|
|
@ -61,7 +61,7 @@ func NewJavascriptProviderFromConfig(ctx context.Context, other map[string]inter
|
||||||
return p, nil
|
return p, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ FloatProvider = (*Javascript)(nil)
|
var _ FloatGetter = (*Javascript)(nil)
|
||||||
|
|
||||||
// FloatGetter parses float from request
|
// FloatGetter parses float from request
|
||||||
func (p *Javascript) FloatGetter() (func() (float64, error), error) {
|
func (p *Javascript) FloatGetter() (func() (float64, error), error) {
|
||||||
|
|
@ -75,7 +75,7 @@ func (p *Javascript) FloatGetter() (func() (float64, error), error) {
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ IntProvider = (*Javascript)(nil)
|
var _ IntGetter = (*Javascript)(nil)
|
||||||
|
|
||||||
// IntGetter parses int64 from request
|
// IntGetter parses int64 from request
|
||||||
func (p *Javascript) IntGetter() (func() (int64, error), error) {
|
func (p *Javascript) IntGetter() (func() (int64, error), error) {
|
||||||
|
|
@ -89,7 +89,7 @@ func (p *Javascript) IntGetter() (func() (int64, error), error) {
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ StringProvider = (*Javascript)(nil)
|
var _ StringGetter = (*Javascript)(nil)
|
||||||
|
|
||||||
// StringGetter parses string from request
|
// StringGetter parses string from request
|
||||||
func (p *Javascript) StringGetter() (func() (string, error), error) {
|
func (p *Javascript) StringGetter() (func() (string, error), error) {
|
||||||
|
|
@ -103,7 +103,7 @@ func (p *Javascript) StringGetter() (func() (string, error), error) {
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ BoolProvider = (*Javascript)(nil)
|
var _ BoolGetter = (*Javascript)(nil)
|
||||||
|
|
||||||
// BoolGetter parses bool from request
|
// BoolGetter parses bool from request
|
||||||
func (p *Javascript) BoolGetter() (func() (bool, error), error) {
|
func (p *Javascript) BoolGetter() (func() (bool, error), error) {
|
||||||
|
|
@ -185,7 +185,7 @@ func (p *Javascript) setParamSync(param string, val any) error {
|
||||||
return p.setParam(param, val)
|
return p.setParam(param, val)
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ SetIntProvider = (*Javascript)(nil)
|
var _ IntSetter = (*Javascript)(nil)
|
||||||
|
|
||||||
// IntSetter sends int request
|
// IntSetter sends int request
|
||||||
func (p *Javascript) IntSetter(param string) (func(int64) error, error) {
|
func (p *Javascript) IntSetter(param string) (func(int64) error, error) {
|
||||||
|
|
@ -194,7 +194,7 @@ func (p *Javascript) IntSetter(param string) (func(int64) error, error) {
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ SetFloatProvider = (*Javascript)(nil)
|
var _ FloatSetter = (*Javascript)(nil)
|
||||||
|
|
||||||
// FloatSetter sends float request
|
// FloatSetter sends float request
|
||||||
func (p *Javascript) FloatSetter(param string) (func(float64) error, error) {
|
func (p *Javascript) FloatSetter(param string) (func(float64) error, error) {
|
||||||
|
|
@ -203,7 +203,7 @@ func (p *Javascript) FloatSetter(param string) (func(float64) error, error) {
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ SetStringProvider = (*Javascript)(nil)
|
var _ StringSetter = (*Javascript)(nil)
|
||||||
|
|
||||||
// StringSetter sends string request
|
// StringSetter sends string request
|
||||||
func (p *Javascript) StringSetter(param string) (func(string) error, error) {
|
func (p *Javascript) StringSetter(param string) (func(string) error, error) {
|
||||||
|
|
@ -212,7 +212,7 @@ func (p *Javascript) StringSetter(param string) (func(string) error, error) {
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ SetBoolProvider = (*Javascript)(nil)
|
var _ BoolSetter = (*Javascript)(nil)
|
||||||
|
|
||||||
// BoolSetter sends bool request
|
// BoolSetter sends bool request
|
||||||
func (p *Javascript) BoolSetter(param string) (func(bool) error, error) {
|
func (p *Javascript) BoolSetter(param string) (func(bool) error, error) {
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package provider
|
package plugin
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
@ -7,7 +7,7 @@ import (
|
||||||
"github.com/evcc-io/evcc/util"
|
"github.com/evcc-io/evcc/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
type mapProvider struct {
|
type mapPlugin struct {
|
||||||
ctx context.Context
|
ctx context.Context
|
||||||
values map[int64]int64
|
values map[int64]int64
|
||||||
get, set Config
|
get, set Config
|
||||||
|
|
@ -18,7 +18,7 @@ func init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewMapFromConfig creates type conversion provider
|
// NewMapFromConfig creates type conversion provider
|
||||||
func NewMapFromConfig(ctx context.Context, other map[string]interface{}) (Provider, error) {
|
func NewMapFromConfig(ctx context.Context, other map[string]interface{}) (Plugin, error) {
|
||||||
var cc struct {
|
var cc struct {
|
||||||
Values map[int64]int64
|
Values map[int64]int64
|
||||||
Get, Set Config
|
Get, Set Config
|
||||||
|
|
@ -32,7 +32,7 @@ func NewMapFromConfig(ctx context.Context, other map[string]interface{}) (Provid
|
||||||
return nil, fmt.Errorf("missing values")
|
return nil, fmt.Errorf("missing values")
|
||||||
}
|
}
|
||||||
|
|
||||||
o := &mapProvider{
|
o := &mapPlugin{
|
||||||
ctx: ctx,
|
ctx: ctx,
|
||||||
get: cc.Get,
|
get: cc.Get,
|
||||||
set: cc.Set,
|
set: cc.Set,
|
||||||
|
|
@ -42,10 +42,10 @@ func NewMapFromConfig(ctx context.Context, other map[string]interface{}) (Provid
|
||||||
return o, nil
|
return o, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ IntProvider = (*mapProvider)(nil)
|
var _ IntGetter = (*mapPlugin)(nil)
|
||||||
|
|
||||||
func (o *mapProvider) IntGetter() (func() (int64, error), error) {
|
func (o *mapPlugin) IntGetter() (func() (int64, error), error) {
|
||||||
get, err := NewIntGetterFromConfig(o.ctx, o.get)
|
get, err := o.get.IntGetter(o.ctx)
|
||||||
|
|
||||||
return func() (int64, error) {
|
return func() (int64, error) {
|
||||||
val, err := get()
|
val, err := get()
|
||||||
|
|
@ -62,10 +62,10 @@ func (o *mapProvider) IntGetter() (func() (int64, error), error) {
|
||||||
}, err
|
}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ SetIntProvider = (*mapProvider)(nil)
|
var _ IntSetter = (*mapPlugin)(nil)
|
||||||
|
|
||||||
func (o *mapProvider) IntSetter(param string) (func(int64) error, error) {
|
func (o *mapPlugin) IntSetter(param string) (func(int64) error, error) {
|
||||||
set, err := NewIntSetterFromConfig(o.ctx, param, o.set)
|
set, err := o.set.IntSetter(o.ctx, param)
|
||||||
|
|
||||||
return func(val int64) error {
|
return func(val int64) error {
|
||||||
m, ok := o.values[val]
|
m, ok := o.values[val]
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package provider
|
package plugin
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
|
@ -26,7 +26,7 @@ func init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewModbusFromConfig creates Modbus plugin
|
// NewModbusFromConfig creates Modbus plugin
|
||||||
func NewModbusFromConfig(ctx context.Context, other map[string]interface{}) (Provider, error) {
|
func NewModbusFromConfig(ctx context.Context, other map[string]interface{}) (Plugin, error) {
|
||||||
cc := struct {
|
cc := struct {
|
||||||
modbus.Settings `mapstructure:",squash"`
|
modbus.Settings `mapstructure:",squash"`
|
||||||
Register modbus.Register
|
Register modbus.Register
|
||||||
|
|
@ -91,7 +91,7 @@ func (m *Modbus) readBytes(op modbus.RegisterOperation) ([]byte, error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ FloatProvider = (*Modbus)(nil)
|
var _ FloatGetter = (*Modbus)(nil)
|
||||||
|
|
||||||
// FloatGetter implements func() (float64, error)
|
// FloatGetter implements func() (float64, error)
|
||||||
func (m *Modbus) FloatGetter() (func() (f float64, err error), error) {
|
func (m *Modbus) FloatGetter() (func() (f float64, err error), error) {
|
||||||
|
|
@ -115,7 +115,7 @@ func (m *Modbus) FloatGetter() (func() (f float64, err error), error) {
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ IntProvider = (*Modbus)(nil)
|
var _ IntGetter = (*Modbus)(nil)
|
||||||
|
|
||||||
// IntGetter implements IntProvider
|
// IntGetter implements IntProvider
|
||||||
func (m *Modbus) IntGetter() (func() (int64, error), error) {
|
func (m *Modbus) IntGetter() (func() (int64, error), error) {
|
||||||
|
|
@ -127,7 +127,7 @@ func (m *Modbus) IntGetter() (func() (int64, error), error) {
|
||||||
}, err
|
}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ StringProvider = (*Modbus)(nil)
|
var _ StringGetter = (*Modbus)(nil)
|
||||||
|
|
||||||
// StringGetter implements StringProvider
|
// StringGetter implements StringProvider
|
||||||
func (m *Modbus) StringGetter() (func() (string, error), error) {
|
func (m *Modbus) StringGetter() (func() (string, error), error) {
|
||||||
|
|
@ -146,7 +146,7 @@ func (m *Modbus) StringGetter() (func() (string, error), error) {
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ BoolProvider = (*Modbus)(nil)
|
var _ BoolGetter = (*Modbus)(nil)
|
||||||
|
|
||||||
// BoolGetter implements BoolProvider
|
// BoolGetter implements BoolProvider
|
||||||
func (m *Modbus) BoolGetter() (func() (bool, error), error) {
|
func (m *Modbus) BoolGetter() (func() (bool, error), error) {
|
||||||
|
|
@ -198,16 +198,16 @@ func (m *Modbus) writeFunc() (func(float64) error, error) {
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ SetFloatProvider = (*Modbus)(nil)
|
var _ FloatSetter = (*Modbus)(nil)
|
||||||
|
|
||||||
// FloatSetter implements SetFloatProvider
|
// FloatSetter implements FloatSetter
|
||||||
func (m *Modbus) FloatSetter(_ string) (func(float64) error, error) {
|
func (m *Modbus) FloatSetter(_ string) (func(float64) error, error) {
|
||||||
return m.writeFunc()
|
return m.writeFunc()
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ SetIntProvider = (*Modbus)(nil)
|
var _ IntSetter = (*Modbus)(nil)
|
||||||
|
|
||||||
// IntSetter implements SetIntProvider
|
// IntSetter implements IntSetter
|
||||||
func (m *Modbus) IntSetter(_ string) (func(int64) error, error) {
|
func (m *Modbus) IntSetter(_ string) (func(int64) error, error) {
|
||||||
fun, err := m.writeFunc()
|
fun, err := m.writeFunc()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -219,9 +219,9 @@ func (m *Modbus) IntSetter(_ string) (func(int64) error, error) {
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ SetBoolProvider = (*Modbus)(nil)
|
var _ BoolSetter = (*Modbus)(nil)
|
||||||
|
|
||||||
// BoolSetter implements SetBoolProvider
|
// BoolSetter implements BoolSetter
|
||||||
func (m *Modbus) BoolSetter(param string) (func(bool) error, error) {
|
func (m *Modbus) BoolSetter(param string) (func(bool) error, error) {
|
||||||
set, err := m.IntSetter(param)
|
set, err := m.IntSetter(param)
|
||||||
|
|
||||||
|
|
@ -235,9 +235,9 @@ func (m *Modbus) BoolSetter(param string) (func(bool) error, error) {
|
||||||
}, err
|
}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ SetBytesProvider = (*Modbus)(nil)
|
var _ BytesSetter = (*Modbus)(nil)
|
||||||
|
|
||||||
// BytesSetter implements SetBytesProvider
|
// BytesSetter implements BytesSetter
|
||||||
func (m *Modbus) BytesSetter(_ string) (func([]byte) error, error) {
|
func (m *Modbus) BytesSetter(_ string) (func([]byte) error, error) {
|
||||||
op, err := m.reg.Operation()
|
op, err := m.reg.Operation()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -1,11 +1,11 @@
|
||||||
package provider
|
package plugin
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/evcc-io/evcc/provider/mqtt"
|
"github.com/evcc-io/evcc/plugin/mqtt"
|
||||||
"github.com/evcc-io/evcc/provider/pipeline"
|
"github.com/evcc-io/evcc/plugin/pipeline"
|
||||||
"github.com/evcc-io/evcc/util"
|
"github.com/evcc-io/evcc/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -22,11 +22,11 @@ type Mqtt struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
registry.AddCtx("mqtt", NewMqttFromConfig)
|
registry.AddCtx("mqtt", NewMqttPluginFromConfig)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewMqttFromConfig creates Mqtt provider
|
// NewMqttPluginFromConfig creates Mqtt provider
|
||||||
func NewMqttFromConfig(ctx context.Context, other map[string]interface{}) (Provider, error) {
|
func NewMqttPluginFromConfig(ctx context.Context, other map[string]interface{}) (Plugin, error) {
|
||||||
cc := struct {
|
cc := struct {
|
||||||
mqtt.Config `mapstructure:",squash"`
|
mqtt.Config `mapstructure:",squash"`
|
||||||
Topic, Payload string // Payload only applies to setters
|
Topic, Payload string // Payload only applies to setters
|
||||||
|
|
@ -120,7 +120,7 @@ func (m *Mqtt) StringGetter() (func() (string, error), error) {
|
||||||
return h.value, err
|
return h.value, err
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ SetIntProvider = (*Mqtt)(nil)
|
var _ IntSetter = (*Mqtt)(nil)
|
||||||
|
|
||||||
// IntSetter publishes topic with parameter replaced by int value
|
// IntSetter publishes topic with parameter replaced by int value
|
||||||
func (m *Mqtt) IntSetter(param string) (func(int64) error, error) {
|
func (m *Mqtt) IntSetter(param string) (func(int64) error, error) {
|
||||||
|
|
@ -134,7 +134,7 @@ func (m *Mqtt) IntSetter(param string) (func(int64) error, error) {
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ SetFloatProvider = (*Mqtt)(nil)
|
var _ FloatSetter = (*Mqtt)(nil)
|
||||||
|
|
||||||
// FloatSetter publishes topic with parameter replaced by float value
|
// FloatSetter publishes topic with parameter replaced by float value
|
||||||
func (m *Mqtt) FloatSetter(param string) (func(float64) error, error) {
|
func (m *Mqtt) FloatSetter(param string) (func(float64) error, error) {
|
||||||
|
|
@ -148,7 +148,7 @@ func (m *Mqtt) FloatSetter(param string) (func(float64) error, error) {
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ SetBoolProvider = (*Mqtt)(nil)
|
var _ BoolSetter = (*Mqtt)(nil)
|
||||||
|
|
||||||
// BoolSetter invokes script with parameter replaced by bool value
|
// BoolSetter invokes script with parameter replaced by bool value
|
||||||
func (m *Mqtt) BoolSetter(param string) (func(bool) error, error) {
|
func (m *Mqtt) BoolSetter(param string) (func(bool) error, error) {
|
||||||
|
|
@ -162,7 +162,7 @@ func (m *Mqtt) BoolSetter(param string) (func(bool) error, error) {
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ SetStringProvider = (*Mqtt)(nil)
|
var _ StringSetter = (*Mqtt)(nil)
|
||||||
|
|
||||||
// StringSetter invokes script with parameter replaced by string value
|
// StringSetter invokes script with parameter replaced by string value
|
||||||
func (m *Mqtt) StringSetter(param string) (func(string) error, error) {
|
func (m *Mqtt) StringSetter(param string) (func(string) error, error) {
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
package provider
|
package plugin
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/evcc-io/evcc/provider/pipeline"
|
"github.com/evcc-io/evcc/plugin/pipeline"
|
||||||
"github.com/evcc-io/evcc/util"
|
"github.com/evcc-io/evcc/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package provider
|
package plugin
|
||||||
|
|
||||||
import "encoding/json"
|
import "encoding/json"
|
||||||
|
|
||||||
|
|
@ -11,7 +11,7 @@ func NewTimeoutHandler(ticker func() (string, error)) *TimeoutHandler {
|
||||||
return &TimeoutHandler{ticker}
|
return &TimeoutHandler{ticker}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *TimeoutHandler) BoolGetter(p BoolProvider) (func() (bool, error), error) {
|
func (h *TimeoutHandler) BoolGetter(p BoolGetter) (func() (bool, error), error) {
|
||||||
g, err := p.BoolGetter()
|
g, err := p.BoolGetter()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
@ -25,7 +25,7 @@ func (h *TimeoutHandler) BoolGetter(p BoolProvider) (func() (bool, error), error
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *TimeoutHandler) FloatGetter(p FloatProvider) (func() (float64, error), error) {
|
func (h *TimeoutHandler) FloatGetter(p FloatGetter) (func() (float64, error), error) {
|
||||||
g, err := p.FloatGetter()
|
g, err := p.FloatGetter()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
@ -39,7 +39,7 @@ func (h *TimeoutHandler) FloatGetter(p FloatProvider) (func() (float64, error),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *TimeoutHandler) StringGetter(p StringProvider) (func() (string, error), error) {
|
func (h *TimeoutHandler) StringGetter(p StringGetter) (func() (string, error), error) {
|
||||||
g, err := p.StringGetter()
|
g, err := p.StringGetter()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
@ -53,7 +53,7 @@ func (h *TimeoutHandler) StringGetter(p StringProvider) (func() (string, error),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *TimeoutHandler) JsonGetter(p StringProvider) (func(any) error, error) {
|
func (h *TimeoutHandler) JsonGetter(p StringGetter) (func(any) error, error) {
|
||||||
g, err := p.StringGetter()
|
g, err := p.StringGetter()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package provider
|
package plugin
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
@ -26,7 +26,7 @@ func init() {
|
||||||
registry.Add("prometheus", NewPrometheusFromConfig)
|
registry.Add("prometheus", NewPrometheusFromConfig)
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewPrometheusFromConfig(other map[string]interface{}) (Provider, error) {
|
func NewPrometheusFromConfig(other map[string]interface{}) (Plugin, error) {
|
||||||
cc := struct {
|
cc := struct {
|
||||||
Uri, Query string
|
Uri, Query string
|
||||||
Timeout time.Duration
|
Timeout time.Duration
|
||||||
|
|
@ -83,7 +83,7 @@ func (p *Prometheus) Query() (model.Value, error) {
|
||||||
return res, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ FloatProvider = (*Prometheus)(nil)
|
var _ FloatGetter = (*Prometheus)(nil)
|
||||||
|
|
||||||
// FloatGetter expects scalar value from query response as float
|
// FloatGetter expects scalar value from query response as float
|
||||||
func (p *Prometheus) FloatGetter() (func() (float64, error), error) {
|
func (p *Prometheus) FloatGetter() (func() (float64, error), error) {
|
||||||
|
|
@ -102,7 +102,7 @@ func (p *Prometheus) FloatGetter() (func() (float64, error), error) {
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ IntProvider = (*Prometheus)(nil)
|
var _ IntGetter = (*Prometheus)(nil)
|
||||||
|
|
||||||
// IntGetter expects scalar value from query response as int
|
// IntGetter expects scalar value from query response as int
|
||||||
func (p *Prometheus) IntGetter() (func() (int64, error), error) {
|
func (p *Prometheus) IntGetter() (func() (int64, error), error) {
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package provider
|
package plugin
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
@ -8,7 +8,7 @@ import (
|
||||||
"github.com/evcc-io/evcc/util"
|
"github.com/evcc-io/evcc/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
type randomProvider struct {
|
type randomPlugin struct {
|
||||||
ctx context.Context
|
ctx context.Context
|
||||||
set Config
|
set Config
|
||||||
}
|
}
|
||||||
|
|
@ -18,7 +18,7 @@ func init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewRandomFromConfig creates random provider
|
// NewRandomFromConfig creates random provider
|
||||||
func NewRandomFromConfig(ctx context.Context, other map[string]interface{}) (Provider, error) {
|
func NewRandomFromConfig(ctx context.Context, other map[string]interface{}) (Plugin, error) {
|
||||||
var cc struct {
|
var cc struct {
|
||||||
Set Config
|
Set Config
|
||||||
}
|
}
|
||||||
|
|
@ -27,7 +27,7 @@ func NewRandomFromConfig(ctx context.Context, other map[string]interface{}) (Pro
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
o := &randomProvider{
|
o := &randomPlugin{
|
||||||
ctx: ctx,
|
ctx: ctx,
|
||||||
set: cc.Set,
|
set: cc.Set,
|
||||||
}
|
}
|
||||||
|
|
@ -35,10 +35,10 @@ func NewRandomFromConfig(ctx context.Context, other map[string]interface{}) (Pro
|
||||||
return o, nil
|
return o, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ SetIntProvider = (*randomProvider)(nil)
|
var _ IntSetter = (*randomPlugin)(nil)
|
||||||
|
|
||||||
func (o *randomProvider) IntSetter(param string) (func(int64) error, error) {
|
func (o *randomPlugin) IntSetter(param string) (func(int64) error, error) {
|
||||||
set, err := NewIntSetterFromConfig(o.ctx, param, o.set)
|
set, err := o.set.IntSetter(o.ctx, param)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package provider
|
package plugin
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
@ -7,7 +7,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/evcc-io/evcc/provider/pipeline"
|
"github.com/evcc-io/evcc/plugin/pipeline"
|
||||||
"github.com/evcc-io/evcc/util"
|
"github.com/evcc-io/evcc/util"
|
||||||
"github.com/evcc-io/evcc/util/request"
|
"github.com/evcc-io/evcc/util/request"
|
||||||
"github.com/kballard/go-shellquote"
|
"github.com/kballard/go-shellquote"
|
||||||
|
|
@ -27,11 +27,11 @@ type Script struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
registry.Add("script", NewScriptProviderFromConfig)
|
registry.Add("script", NewScriptPluginFromConfig)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewScriptProviderFromConfig creates a script provider.
|
// NewScriptPluginFromConfig creates a script plugin.
|
||||||
func NewScriptProviderFromConfig(other map[string]interface{}) (Provider, error) {
|
func NewScriptPluginFromConfig(other map[string]interface{}) (Plugin, error) {
|
||||||
cc := struct {
|
cc := struct {
|
||||||
Cmd string
|
Cmd string
|
||||||
pipeline.Settings `mapstructure:",squash"`
|
pipeline.Settings `mapstructure:",squash"`
|
||||||
|
|
@ -47,7 +47,7 @@ func NewScriptProviderFromConfig(other map[string]interface{}) (Provider, error)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
p, err := NewScriptProvider(cc.Cmd, cc.Timeout, cc.Scale, cc.Cache)
|
p, err := NewScripPlugin(cc.Cmd, cc.Timeout, cc.Scale, cc.Cache)
|
||||||
p.getter = defaultGetters(p, cc.Scale)
|
p.getter = defaultGetters(p, cc.Scale)
|
||||||
|
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
|
@ -59,9 +59,9 @@ func NewScriptProviderFromConfig(other map[string]interface{}) (Provider, error)
|
||||||
return p, err
|
return p, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewScriptProvider creates a script provider.
|
// NewScriptProvider creates a script plugin.
|
||||||
// Script execution is aborted after given timeout.
|
// Script execution is aborted after given timeout.
|
||||||
func NewScriptProvider(script string, timeout time.Duration, scale float64, cache time.Duration) (*Script, error) {
|
func NewScripPlugin(script string, timeout time.Duration, scale float64, cache time.Duration) (*Script, error) {
|
||||||
if strings.TrimSpace(script) == "" {
|
if strings.TrimSpace(script) == "" {
|
||||||
return nil, errors.New("script is required")
|
return nil, errors.New("script is required")
|
||||||
}
|
}
|
||||||
|
|
@ -140,21 +140,21 @@ func scriptSetter[T any](p *Script, param string) (func(T) error, error) {
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ SetIntProvider = (*Script)(nil)
|
var _ IntSetter = (*Script)(nil)
|
||||||
|
|
||||||
// IntSetter invokes script with parameter replaced by int value
|
// IntSetter invokes script with parameter replaced by int value
|
||||||
func (p *Script) IntSetter(param string) (func(int64) error, error) {
|
func (p *Script) IntSetter(param string) (func(int64) error, error) {
|
||||||
return scriptSetter[int64](p, param)
|
return scriptSetter[int64](p, param)
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ SetBoolProvider = (*Script)(nil)
|
var _ BoolSetter = (*Script)(nil)
|
||||||
|
|
||||||
// BoolSetter invokes script with parameter replaced by bool value
|
// BoolSetter invokes script with parameter replaced by bool value
|
||||||
func (p *Script) BoolSetter(param string) (func(bool) error, error) {
|
func (p *Script) BoolSetter(param string) (func(bool) error, error) {
|
||||||
return scriptSetter[bool](p, param)
|
return scriptSetter[bool](p, param)
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ SetStringProvider = (*Script)(nil)
|
var _ StringSetter = (*Script)(nil)
|
||||||
|
|
||||||
// StringSetter returns a function that invokes a script with parameter by a string value
|
// StringSetter returns a function that invokes a script with parameter by a string value
|
||||||
func (p *Script) StringSetter(param string) (func(string) error, error) {
|
func (p *Script) StringSetter(param string) (func(string) error, error) {
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package provider
|
package plugin
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
@ -6,7 +6,7 @@ import (
|
||||||
"github.com/evcc-io/evcc/util"
|
"github.com/evcc-io/evcc/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
type sequenceProvider struct {
|
type sequencePlugin struct {
|
||||||
ctx context.Context
|
ctx context.Context
|
||||||
set []Config
|
set []Config
|
||||||
}
|
}
|
||||||
|
|
@ -16,7 +16,7 @@ func init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewSequenceFromConfig creates sequence provider
|
// NewSequenceFromConfig creates sequence provider
|
||||||
func NewSequenceFromConfig(ctx context.Context, other map[string]interface{}) (Provider, error) {
|
func NewSequenceFromConfig(ctx context.Context, other map[string]interface{}) (Plugin, error) {
|
||||||
var cc struct {
|
var cc struct {
|
||||||
Set []Config
|
Set []Config
|
||||||
}
|
}
|
||||||
|
|
@ -25,7 +25,7 @@ func NewSequenceFromConfig(ctx context.Context, other map[string]interface{}) (P
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
o := &sequenceProvider{
|
o := &sequencePlugin{
|
||||||
ctx: ctx,
|
ctx: ctx,
|
||||||
set: cc.Set,
|
set: cc.Set,
|
||||||
}
|
}
|
||||||
|
|
@ -33,12 +33,12 @@ func NewSequenceFromConfig(ctx context.Context, other map[string]interface{}) (P
|
||||||
return o, nil
|
return o, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ SetIntProvider = (*sequenceProvider)(nil)
|
var _ IntSetter = (*sequencePlugin)(nil)
|
||||||
|
|
||||||
func (o *sequenceProvider) IntSetter(param string) (func(int64) error, error) {
|
func (o *sequencePlugin) IntSetter(param string) (func(int64) error, error) {
|
||||||
set := make([]func(int64) error, 0, len(o.set))
|
set := make([]func(int64) error, 0, len(o.set))
|
||||||
for _, cc := range o.set {
|
for _, cc := range o.set {
|
||||||
s, err := NewIntSetterFromConfig(o.ctx, param, cc)
|
s, err := cc.IntSetter(o.ctx, param)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
@ -55,12 +55,12 @@ func (o *sequenceProvider) IntSetter(param string) (func(int64) error, error) {
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ SetFloatProvider = (*sequenceProvider)(nil)
|
var _ FloatSetter = (*sequencePlugin)(nil)
|
||||||
|
|
||||||
func (o *sequenceProvider) FloatSetter(param string) (func(float64) error, error) {
|
func (o *sequencePlugin) FloatSetter(param string) (func(float64) error, error) {
|
||||||
set := make([]func(float64) error, 0, len(o.set))
|
set := make([]func(float64) error, 0, len(o.set))
|
||||||
for _, cc := range o.set {
|
for _, cc := range o.set {
|
||||||
s, err := NewFloatSetterFromConfig(o.ctx, param, cc)
|
s, err := cc.FloatSetter(o.ctx, param)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
@ -77,12 +77,12 @@ func (o *sequenceProvider) FloatSetter(param string) (func(float64) error, error
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ SetBoolProvider = (*sequenceProvider)(nil)
|
var _ BoolSetter = (*sequencePlugin)(nil)
|
||||||
|
|
||||||
func (o *sequenceProvider) BoolSetter(param string) (func(bool) error, error) {
|
func (o *sequencePlugin) BoolSetter(param string) (func(bool) error, error) {
|
||||||
set := make([]func(bool) error, 0, len(o.set))
|
set := make([]func(bool) error, 0, len(o.set))
|
||||||
for _, cc := range o.set {
|
for _, cc := range o.set {
|
||||||
s, err := NewBoolSetterFromConfig(o.ctx, param, cc)
|
s, err := cc.BoolSetter(o.ctx, param)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
package provider
|
package plugin
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/evcc-io/evcc/provider/sma"
|
"github.com/evcc-io/evcc/plugin/sma"
|
||||||
"github.com/evcc-io/evcc/util"
|
"github.com/evcc-io/evcc/util"
|
||||||
"gitlab.com/bboehmke/sunny"
|
"gitlab.com/bboehmke/sunny"
|
||||||
)
|
)
|
||||||
|
|
@ -21,7 +21,7 @@ func init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewSMAFromConfig creates SMA provider
|
// NewSMAFromConfig creates SMA provider
|
||||||
func NewSMAFromConfig(other map[string]interface{}) (Provider, error) {
|
func NewSMAFromConfig(other map[string]interface{}) (Plugin, error) {
|
||||||
cc := struct {
|
cc := struct {
|
||||||
URI, Password, Interface string
|
URI, Password, Interface string
|
||||||
Serial uint32
|
Serial uint32
|
||||||
|
|
@ -41,19 +41,19 @@ func NewSMAFromConfig(other map[string]interface{}) (Provider, error) {
|
||||||
return nil, fmt.Errorf("failed to get discoverer failed: %w", err)
|
return nil, fmt.Errorf("failed to get discoverer failed: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
provider := &SMA{
|
o := &SMA{
|
||||||
scale: cc.Scale,
|
scale: cc.Scale,
|
||||||
}
|
}
|
||||||
switch {
|
switch {
|
||||||
case cc.URI != "":
|
case cc.URI != "":
|
||||||
provider.device, err = discoverer.DeviceByIP(cc.URI, cc.Password)
|
o.device, err = discoverer.DeviceByIP(cc.URI, cc.Password)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
case cc.Serial > 0:
|
case cc.Serial > 0:
|
||||||
provider.device = discoverer.DeviceBySerial(cc.Serial, cc.Password)
|
o.device = discoverer.DeviceBySerial(cc.Serial, cc.Password)
|
||||||
if provider.device == nil {
|
if o.device == nil {
|
||||||
return nil, fmt.Errorf("device not found: %d", cc.Serial)
|
return nil, fmt.Errorf("device not found: %d", cc.Serial)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -61,15 +61,12 @@ func NewSMAFromConfig(other map[string]interface{}) (Provider, error) {
|
||||||
return nil, errors.New("missing uri or serial")
|
return nil, errors.New("missing uri or serial")
|
||||||
}
|
}
|
||||||
|
|
||||||
provider.value, err = sunny.ValueIDString(cc.Value)
|
o.value, err = sunny.ValueIDString(cc.Value)
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return provider, err
|
return o, err
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ FloatProvider = (*SMA)(nil)
|
var _ FloatGetter = (*SMA)(nil)
|
||||||
|
|
||||||
// FloatGetter creates handler for float64
|
// FloatGetter creates handler for float64
|
||||||
func (p *SMA) FloatGetter() (func() (float64, error), error) {
|
func (p *SMA) FloatGetter() (func() (float64, error), error) {
|
||||||
|
|
@ -83,7 +80,7 @@ func (p *SMA) FloatGetter() (func() (float64, error), error) {
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ IntProvider = (*SMA)(nil)
|
var _ IntGetter = (*SMA)(nil)
|
||||||
|
|
||||||
// IntGetter creates handler for int64
|
// IntGetter creates handler for int64
|
||||||
func (p *SMA) IntGetter() (func() (int64, error), error) {
|
func (p *SMA) IntGetter() (func() (int64, error), error) {
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package provider
|
package plugin
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
@ -8,7 +8,7 @@ import (
|
||||||
|
|
||||||
"github.com/coder/websocket"
|
"github.com/coder/websocket"
|
||||||
"github.com/evcc-io/evcc/api"
|
"github.com/evcc-io/evcc/api"
|
||||||
"github.com/evcc-io/evcc/provider/pipeline"
|
"github.com/evcc-io/evcc/plugin/pipeline"
|
||||||
"github.com/evcc-io/evcc/util"
|
"github.com/evcc-io/evcc/util"
|
||||||
"github.com/evcc-io/evcc/util/request"
|
"github.com/evcc-io/evcc/util/request"
|
||||||
"github.com/evcc-io/evcc/util/transport"
|
"github.com/evcc-io/evcc/util/transport"
|
||||||
|
|
@ -28,12 +28,12 @@ type Socket struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
registry.Add("ws", NewSocketProviderFromConfig)
|
registry.Add("ws", NewSocketPluginFromConfig)
|
||||||
registry.Add("websocket", NewSocketProviderFromConfig)
|
registry.Add("websocket", NewSocketPluginFromConfig)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewSocketProviderFromConfig creates a HTTP provider
|
// NewSocketPluginFromConfig creates a HTTP provider
|
||||||
func NewSocketProviderFromConfig(other map[string]interface{}) (Provider, error) {
|
func NewSocketPluginFromConfig(other map[string]interface{}) (Plugin, error) {
|
||||||
cc := struct {
|
cc := struct {
|
||||||
URI string
|
URI string
|
||||||
Headers map[string]string
|
Headers map[string]string
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package provider
|
package plugin
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
@ -12,7 +12,7 @@ import (
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestSocketProvider(t *testing.T) {
|
func TestSockePlugin(t *testing.T) {
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
|
ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
|
|
@ -40,7 +40,7 @@ func TestSocketProvider(t *testing.T) {
|
||||||
defer srv.Close()
|
defer srv.Close()
|
||||||
|
|
||||||
addr := "ws://" + srv.Listener.Addr().String()
|
addr := "ws://" + srv.Listener.Addr().String()
|
||||||
p, err := NewSocketProviderFromConfig(map[string]any{
|
p, err := NewSocketPluginFromConfig(map[string]any{
|
||||||
"uri": addr,
|
"uri": addr,
|
||||||
"jq": `.data | select(.uuid=="bar") .tuples[0][1]`,
|
"jq": `.data | select(.uuid=="bar") .tuples[0][1]`,
|
||||||
})
|
})
|
||||||
|
|
@ -48,7 +48,7 @@ func TestSocketProvider(t *testing.T) {
|
||||||
|
|
||||||
<-p.(*Socket).val.Done()
|
<-p.(*Socket).val.Done()
|
||||||
|
|
||||||
g, err := p.(IntProvider).IntGetter()
|
g, err := p.(IntGetter).IntGetter()
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
i, err := g()
|
i, err := g()
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package provider
|
package plugin
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
|
@ -28,7 +28,7 @@ func init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewModbusSunspecFromConfig creates Modbus plugin
|
// NewModbusSunspecFromConfig creates Modbus plugin
|
||||||
func NewModbusSunspecFromConfig(other map[string]interface{}) (Provider, error) {
|
func NewModbusSunspecFromConfig(other map[string]interface{}) (Plugin, error) {
|
||||||
cc := struct {
|
cc := struct {
|
||||||
modbus.Settings `mapstructure:",squash"`
|
modbus.Settings `mapstructure:",squash"`
|
||||||
Value []string
|
Value []string
|
||||||
|
|
@ -137,14 +137,14 @@ func (m *ModbusSunspec) floatGetter() (f float64, err error) {
|
||||||
return m.scale * res, nil
|
return m.scale * res, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ FloatProvider = (*Modbus)(nil)
|
var _ FloatGetter = (*Modbus)(nil)
|
||||||
|
|
||||||
// FloatGetter executes configured modbus read operation and implements func() (float64, error)
|
// FloatGetter executes configured modbus read operation and implements func() (float64, error)
|
||||||
func (m *ModbusSunspec) FloatGetter() (func() (f float64, err error), error) {
|
func (m *ModbusSunspec) FloatGetter() (func() (f float64, err error), error) {
|
||||||
return m.floatGetter, nil
|
return m.floatGetter, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ IntProvider = (*Modbus)(nil)
|
var _ IntGetter = (*Modbus)(nil)
|
||||||
|
|
||||||
// IntGetter executes configured modbus read operation and implements IntProvider
|
// IntGetter executes configured modbus read operation and implements IntProvider
|
||||||
func (m *ModbusSunspec) IntGetter() (func() (int64, error), error) {
|
func (m *ModbusSunspec) IntGetter() (func() (int64, error), error) {
|
||||||
|
|
@ -176,9 +176,9 @@ func (m *ModbusSunspec) blockPoint() (block sunspec.Block, point sunspec.Point,
|
||||||
return block, point, err
|
return block, point, err
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ SetFloatProvider = (*Modbus)(nil)
|
var _ FloatSetter = (*Modbus)(nil)
|
||||||
|
|
||||||
// FloatSetter executes configured modbus write operation and implements SetFloatProvider
|
// FloatSetter executes configured modbus write operation and implements FloatSetter
|
||||||
func (m *ModbusSunspec) FloatSetter(_ string) (func(float64) error, error) {
|
func (m *ModbusSunspec) FloatSetter(_ string) (func(float64) error, error) {
|
||||||
block, point, err := m.blockPoint()
|
block, point, err := m.blockPoint()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -206,9 +206,9 @@ func (m *ModbusSunspec) FloatSetter(_ string) (func(float64) error, error) {
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ SetIntProvider = (*Modbus)(nil)
|
var _ IntSetter = (*Modbus)(nil)
|
||||||
|
|
||||||
// IntSetter executes configured modbus write operation and implements SetIntProvider
|
// IntSetter executes configured modbus write operation and implements IntSetter
|
||||||
func (m *ModbusSunspec) IntSetter(_ string) (func(int64) error, error) {
|
func (m *ModbusSunspec) IntSetter(_ string) (func(int64) error, error) {
|
||||||
block, point, err := m.blockPoint()
|
block, point, err := m.blockPoint()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package provider
|
package plugin
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package provider
|
package plugin
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
@ -13,7 +13,7 @@ type Case struct {
|
||||||
Set Config
|
Set Config
|
||||||
}
|
}
|
||||||
|
|
||||||
type switchProvider struct {
|
type switchPlugin struct {
|
||||||
ctx context.Context
|
ctx context.Context
|
||||||
cases []Case
|
cases []Case
|
||||||
dflt *Config
|
dflt *Config
|
||||||
|
|
@ -24,7 +24,7 @@ func init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewSwitchFromConfig creates switch provider
|
// NewSwitchFromConfig creates switch provider
|
||||||
func NewSwitchFromConfig(ctx context.Context, other map[string]interface{}) (Provider, error) {
|
func NewSwitchFromConfig(ctx context.Context, other map[string]interface{}) (Plugin, error) {
|
||||||
var cc struct {
|
var cc struct {
|
||||||
Switch []Case
|
Switch []Case
|
||||||
Default *Config
|
Default *Config
|
||||||
|
|
@ -42,7 +42,7 @@ func NewSwitchFromConfig(ctx context.Context, other map[string]interface{}) (Pro
|
||||||
cases[c.Case] = struct{}{}
|
cases[c.Case] = struct{}{}
|
||||||
}
|
}
|
||||||
|
|
||||||
o := &switchProvider{
|
o := &switchPlugin{
|
||||||
ctx: ctx,
|
ctx: ctx,
|
||||||
cases: cc.Switch,
|
cases: cc.Switch,
|
||||||
dflt: cc.Default,
|
dflt: cc.Default,
|
||||||
|
|
@ -51,24 +51,21 @@ func NewSwitchFromConfig(ctx context.Context, other map[string]interface{}) (Pro
|
||||||
return o, nil
|
return o, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ SetIntProvider = (*switchProvider)(nil)
|
var _ IntSetter = (*switchPlugin)(nil)
|
||||||
|
|
||||||
func (o *switchProvider) IntSetter(param string) (func(int64) error, error) {
|
func (o *switchPlugin) IntSetter(param string) (func(int64) error, error) {
|
||||||
set := make([]func(int64) error, 0, len(o.cases))
|
set := make([]func(int64) error, 0, len(o.cases))
|
||||||
for _, cc := range o.cases {
|
for _, cc := range o.cases {
|
||||||
s, err := NewIntSetterFromConfig(o.ctx, param, cc.Set)
|
s, err := cc.Set.IntSetter(o.ctx, param)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
set = append(set, s)
|
set = append(set, s)
|
||||||
}
|
}
|
||||||
|
|
||||||
var dflt func(int64) error
|
dflt, err := o.dflt.IntSetter(o.ctx, param)
|
||||||
if o.dflt != nil {
|
if err != nil {
|
||||||
var err error
|
return nil, err
|
||||||
if dflt, err = NewIntSetterFromConfig(o.ctx, param, *o.dflt); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return func(val int64) error {
|
return func(val int64) error {
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package provider
|
package plugin
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
@ -16,11 +16,11 @@ func init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// TimeSeriesFromConfig creates timeseries provider
|
// TimeSeriesFromConfig creates timeseries provider
|
||||||
func TimeSeriesFromConfig(_ context.Context, _ map[string]interface{}) (Provider, error) {
|
func TimeSeriesFromConfig(_ context.Context, _ map[string]interface{}) (Plugin, error) {
|
||||||
return new(timeseriesProvider), nil
|
return new(timeseriesProvider), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ StringProvider = (*timeseriesProvider)(nil)
|
var _ StringGetter = (*timeseriesProvider)(nil)
|
||||||
|
|
||||||
func (p *timeseriesProvider) StringGetter() (func() (string, error), error) {
|
func (p *timeseriesProvider) StringGetter() (func() (string, error), error) {
|
||||||
return func() (string, error) {
|
return func() (string, error) {
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package provider
|
package plugin
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
@ -29,28 +29,28 @@ func configureInputs(ctx context.Context, inConfig []transformationConfig) ([]in
|
||||||
|
|
||||||
switch strings.ToLower(cc.Type) {
|
switch strings.ToLower(cc.Type) {
|
||||||
case "bool":
|
case "bool":
|
||||||
ff, err := NewBoolGetterFromConfig(ctx, cc.Config)
|
ff, err := cc.Config.BoolGetter(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("%s: %w", cc.Name, err)
|
return nil, fmt.Errorf("%s: %w", cc.Name, err)
|
||||||
}
|
}
|
||||||
f = func() (any, error) { return ff() }
|
f = func() (any, error) { return ff() }
|
||||||
|
|
||||||
case "int":
|
case "int":
|
||||||
ff, err := NewIntGetterFromConfig(ctx, cc.Config)
|
ff, err := cc.Config.IntGetter(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("%s: %w", cc.Name, err)
|
return nil, fmt.Errorf("%s: %w", cc.Name, err)
|
||||||
}
|
}
|
||||||
f = func() (any, error) { return ff() }
|
f = func() (any, error) { return ff() }
|
||||||
|
|
||||||
case "float":
|
case "float":
|
||||||
ff, err := NewFloatGetterFromConfig(ctx, cc.Config)
|
ff, err := cc.Config.FloatGetter(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("%s: %w", cc.Name, err)
|
return nil, fmt.Errorf("%s: %w", cc.Name, err)
|
||||||
}
|
}
|
||||||
f = func() (any, error) { return ff() }
|
f = func() (any, error) { return ff() }
|
||||||
|
|
||||||
case "string":
|
case "string":
|
||||||
ff, err := NewStringGetterFromConfig(ctx, cc.Config)
|
ff, err := cc.Config.StringGetter(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("%s: %w", cc.Name, err)
|
return nil, fmt.Errorf("%s: %w", cc.Name, err)
|
||||||
}
|
}
|
||||||
|
|
@ -76,7 +76,7 @@ func configureOutputs(ctx context.Context, outConfig []transformationConfig) ([]
|
||||||
|
|
||||||
switch strings.ToLower(cc.Type) {
|
switch strings.ToLower(cc.Type) {
|
||||||
case "bool":
|
case "bool":
|
||||||
ff, err := NewBoolSetterFromConfig(ctx, cc.Name, cc.Config)
|
ff, err := cc.Config.BoolSetter(ctx, cc.Name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("%s: %w", cc.Name, err)
|
return nil, fmt.Errorf("%s: %w", cc.Name, err)
|
||||||
}
|
}
|
||||||
|
|
@ -86,7 +86,7 @@ func configureOutputs(ctx context.Context, outConfig []transformationConfig) ([]
|
||||||
}
|
}
|
||||||
|
|
||||||
case "int":
|
case "int":
|
||||||
ff, err := NewIntSetterFromConfig(ctx, cc.Name, cc.Config)
|
ff, err := cc.Config.IntSetter(ctx, cc.Name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("%s: %w", cc.Name, err)
|
return nil, fmt.Errorf("%s: %w", cc.Name, err)
|
||||||
}
|
}
|
||||||
|
|
@ -96,7 +96,7 @@ func configureOutputs(ctx context.Context, outConfig []transformationConfig) ([]
|
||||||
}
|
}
|
||||||
|
|
||||||
case "float":
|
case "float":
|
||||||
ff, err := NewFloatSetterFromConfig(ctx, cc.Name, cc.Config)
|
ff, err := cc.Config.FloatSetter(ctx, cc.Name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("%s: %w", cc.Name, err)
|
return nil, fmt.Errorf("%s: %w", cc.Name, err)
|
||||||
}
|
}
|
||||||
|
|
@ -106,7 +106,7 @@ func configureOutputs(ctx context.Context, outConfig []transformationConfig) ([]
|
||||||
}
|
}
|
||||||
|
|
||||||
case "string":
|
case "string":
|
||||||
ff, err := NewStringSetterFromConfig(ctx, cc.Name, cc.Config)
|
ff, err := cc.Config.StringSetter(ctx, cc.Name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("%s: %w", cc.Name, err)
|
return nil, fmt.Errorf("%s: %w", cc.Name, err)
|
||||||
}
|
}
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package provider
|
package plugin
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
@ -9,7 +9,7 @@ import (
|
||||||
"github.com/evcc-io/evcc/util"
|
"github.com/evcc-io/evcc/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
type watchdogProvider struct {
|
type watchdogPlugin struct {
|
||||||
mu sync.Mutex
|
mu sync.Mutex
|
||||||
ctx context.Context
|
ctx context.Context
|
||||||
log *util.Logger
|
log *util.Logger
|
||||||
|
|
@ -24,7 +24,7 @@ func init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewWatchDogFromConfig creates watchDog provider
|
// NewWatchDogFromConfig creates watchDog provider
|
||||||
func NewWatchDogFromConfig(ctx context.Context, other map[string]interface{}) (Provider, error) {
|
func NewWatchDogFromConfig(ctx context.Context, other map[string]interface{}) (Plugin, error) {
|
||||||
var cc struct {
|
var cc struct {
|
||||||
Reset *string
|
Reset *string
|
||||||
Set Config
|
Set Config
|
||||||
|
|
@ -35,7 +35,7 @@ func NewWatchDogFromConfig(ctx context.Context, other map[string]interface{}) (P
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
o := &watchdogProvider{
|
o := &watchdogPlugin{
|
||||||
ctx: ctx,
|
ctx: ctx,
|
||||||
log: contextLogger(ctx, util.NewLogger("watchdog")),
|
log: contextLogger(ctx, util.NewLogger("watchdog")),
|
||||||
reset: cc.Reset,
|
reset: cc.Reset,
|
||||||
|
|
@ -46,7 +46,7 @@ func NewWatchDogFromConfig(ctx context.Context, other map[string]interface{}) (P
|
||||||
return o, nil
|
return o, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *watchdogProvider) wdt(ctx context.Context, set func() error) {
|
func (o *watchdogPlugin) wdt(ctx context.Context, set func() error) {
|
||||||
for tick := time.Tick(o.timeout); ; {
|
for tick := time.Tick(o.timeout); ; {
|
||||||
select {
|
select {
|
||||||
case <-tick:
|
case <-tick:
|
||||||
|
|
@ -59,9 +59,9 @@ func (o *watchdogProvider) wdt(ctx context.Context, set func() error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// setter is the generic setter function for watchdogProvider
|
// setter is the generic setter function for watchdogPlugin
|
||||||
// it is currently not possible to write this as a method
|
// it is currently not possible to write this as a method
|
||||||
func setter[T comparable](o *watchdogProvider, set func(T) error, reset *T) func(T) error {
|
func setter[T comparable](o *watchdogPlugin, set func(T) error, reset *T) func(T) error {
|
||||||
return func(val T) error {
|
return func(val T) error {
|
||||||
o.mu.Lock()
|
o.mu.Lock()
|
||||||
|
|
||||||
|
|
@ -87,10 +87,10 @@ func setter[T comparable](o *watchdogProvider, set func(T) error, reset *T) func
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ SetIntProvider = (*watchdogProvider)(nil)
|
var _ IntSetter = (*watchdogPlugin)(nil)
|
||||||
|
|
||||||
func (o *watchdogProvider) IntSetter(param string) (func(int64) error, error) {
|
func (o *watchdogPlugin) IntSetter(param string) (func(int64) error, error) {
|
||||||
set, err := NewIntSetterFromConfig(o.ctx, param, o.set)
|
set, err := o.set.IntSetter(o.ctx, param)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
@ -107,10 +107,10 @@ func (o *watchdogProvider) IntSetter(param string) (func(int64) error, error) {
|
||||||
return setter(o, set, reset), nil
|
return setter(o, set, reset), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ SetFloatProvider = (*watchdogProvider)(nil)
|
var _ FloatSetter = (*watchdogPlugin)(nil)
|
||||||
|
|
||||||
func (o *watchdogProvider) FloatSetter(param string) (func(float64) error, error) {
|
func (o *watchdogPlugin) FloatSetter(param string) (func(float64) error, error) {
|
||||||
set, err := NewFloatSetterFromConfig(o.ctx, param, o.set)
|
set, err := o.set.FloatSetter(o.ctx, param)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
@ -127,10 +127,10 @@ func (o *watchdogProvider) FloatSetter(param string) (func(float64) error, error
|
||||||
return setter(o, set, reset), nil
|
return setter(o, set, reset), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ SetBoolProvider = (*watchdogProvider)(nil)
|
var _ BoolSetter = (*watchdogPlugin)(nil)
|
||||||
|
|
||||||
func (o *watchdogProvider) BoolSetter(param string) (func(bool) error, error) {
|
func (o *watchdogPlugin) BoolSetter(param string) (func(bool) error, error) {
|
||||||
set, err := NewBoolSetterFromConfig(o.ctx, param, o.set)
|
set, err := o.set.BoolSetter(o.ctx, param)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
@ -1,165 +0,0 @@
|
||||||
package provider
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
reg "github.com/evcc-io/evcc/util/registry"
|
|
||||||
)
|
|
||||||
|
|
||||||
var registry = reg.New[Provider]("plugin")
|
|
||||||
|
|
||||||
// provider types
|
|
||||||
type (
|
|
||||||
Provider interface{}
|
|
||||||
Getters interface {
|
|
||||||
StringProvider
|
|
||||||
FloatProvider
|
|
||||||
IntProvider
|
|
||||||
BoolProvider
|
|
||||||
}
|
|
||||||
StringProvider interface {
|
|
||||||
StringGetter() (func() (string, error), error)
|
|
||||||
}
|
|
||||||
FloatProvider interface {
|
|
||||||
FloatGetter() (func() (float64, error), error)
|
|
||||||
}
|
|
||||||
IntProvider interface {
|
|
||||||
IntGetter() (func() (int64, error), error)
|
|
||||||
}
|
|
||||||
BoolProvider interface {
|
|
||||||
BoolGetter() (func() (bool, error), error)
|
|
||||||
}
|
|
||||||
SetStringProvider interface {
|
|
||||||
StringSetter(param string) (func(string) error, error)
|
|
||||||
}
|
|
||||||
SetFloatProvider interface {
|
|
||||||
FloatSetter(param string) (func(float64) error, error)
|
|
||||||
}
|
|
||||||
SetIntProvider interface {
|
|
||||||
IntSetter(param string) (func(int64) error, error)
|
|
||||||
}
|
|
||||||
SetBoolProvider interface {
|
|
||||||
BoolSetter(param string) (func(bool) error, error)
|
|
||||||
}
|
|
||||||
SetBytesProvider interface {
|
|
||||||
BytesSetter(param string) (func([]byte) error, error)
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
// Config is the general provider config
|
|
||||||
type Config struct {
|
|
||||||
Source string
|
|
||||||
Other map[string]any `mapstructure:",remain" yaml:",inline"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func provider[T any](typ string, ctx context.Context, config Config) (T, error) {
|
|
||||||
var zero T
|
|
||||||
|
|
||||||
factory, err := registry.Get(config.Source)
|
|
||||||
if err != nil {
|
|
||||||
return zero, err
|
|
||||||
}
|
|
||||||
|
|
||||||
provider, err := factory(ctx, config.Other)
|
|
||||||
if err != nil {
|
|
||||||
return zero, err
|
|
||||||
}
|
|
||||||
|
|
||||||
prov, ok := provider.(T)
|
|
||||||
if !ok {
|
|
||||||
return zero, fmt.Errorf("invalid plugin source for type %s: %s", typ, config.Source)
|
|
||||||
}
|
|
||||||
|
|
||||||
return prov, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewIntGetterFromConfig creates a IntGetter from config
|
|
||||||
func NewIntGetterFromConfig(ctx context.Context, config Config) (func() (int64, error), error) {
|
|
||||||
prov, err := provider[IntProvider]("int", ctx, config)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return prov.IntGetter()
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewFloatGetterFromConfig creates a FloatGetter from config
|
|
||||||
func NewFloatGetterFromConfig(ctx context.Context, config Config) (func() (float64, error), error) {
|
|
||||||
prov, err := provider[FloatProvider]("float", ctx, config)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return prov.FloatGetter()
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewStringGetterFromConfig creates a StringGetter from config
|
|
||||||
func NewStringGetterFromConfig(ctx context.Context, config Config) (func() (string, error), error) {
|
|
||||||
prov, err := provider[StringProvider]("string", ctx, config)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return prov.StringGetter()
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewBoolGetterFromConfig creates a BoolGetter from config
|
|
||||||
func NewBoolGetterFromConfig(ctx context.Context, config Config) (func() (bool, error), error) {
|
|
||||||
prov, err := provider[BoolProvider]("bool", ctx, config)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return prov.BoolGetter()
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewIntSetterFromConfig creates a IntSetter from config
|
|
||||||
func NewIntSetterFromConfig(ctx context.Context, param string, config Config) (func(int64) error, error) {
|
|
||||||
prov, err := provider[SetIntProvider]("int", ctx, config)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return prov.IntSetter(param)
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewFloatSetterFromConfig creates a FloatSetter from config
|
|
||||||
func NewFloatSetterFromConfig(ctx context.Context, param string, config Config) (func(float642 float64) error, error) {
|
|
||||||
prov, err := provider[SetFloatProvider]("float", ctx, config)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return prov.FloatSetter(param)
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewStringSetterFromConfig creates a StringSetter from config
|
|
||||||
func NewStringSetterFromConfig(ctx context.Context, param string, config Config) (func(string) error, error) {
|
|
||||||
prov, err := provider[SetStringProvider]("string", ctx, config)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return prov.StringSetter(param)
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewBoolSetterFromConfig creates a BoolSetter from config
|
|
||||||
func NewBoolSetterFromConfig(ctx context.Context, param string, config Config) (func(bool) error, error) {
|
|
||||||
prov, err := provider[SetBoolProvider]("bool", ctx, config)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return prov.BoolSetter(param)
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewBytesSetterFromConfig creates a BytesSetter from config
|
|
||||||
func NewBytesSetterFromConfig(ctx context.Context, param string, config Config) (func([]byte) error, error) {
|
|
||||||
prov, err := provider[SetBytesProvider]("bytes", ctx, config)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return prov.BytesSetter(param)
|
|
||||||
}
|
|
||||||
|
|
@ -8,7 +8,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/evcc-io/evcc/api"
|
"github.com/evcc-io/evcc/api"
|
||||||
"github.com/evcc-io/evcc/provider"
|
"github.com/evcc-io/evcc/plugin"
|
||||||
"github.com/evcc-io/evcc/util"
|
"github.com/evcc-io/evcc/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -19,7 +19,7 @@ func init() {
|
||||||
// NewConfigurableFromConfig creates Messenger from config
|
// NewConfigurableFromConfig creates Messenger from config
|
||||||
func NewConfigurableFromConfig(ctx context.Context, other map[string]interface{}) (Messenger, error) {
|
func NewConfigurableFromConfig(ctx context.Context, other map[string]interface{}) (Messenger, error) {
|
||||||
var cc struct {
|
var cc struct {
|
||||||
Send provider.Config
|
Send plugin.Config
|
||||||
Encoding string
|
Encoding string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -27,7 +27,7 @@ func NewConfigurableFromConfig(ctx context.Context, other map[string]interface{}
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
send, err := provider.NewStringSetterFromConfig(ctx, "send", cc.Send)
|
send, err := cc.Send.StringSetter(ctx, "send")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ import (
|
||||||
"github.com/evcc-io/evcc/core/loadpoint"
|
"github.com/evcc-io/evcc/core/loadpoint"
|
||||||
"github.com/evcc-io/evcc/core/site"
|
"github.com/evcc-io/evcc/core/site"
|
||||||
"github.com/evcc-io/evcc/core/vehicle"
|
"github.com/evcc-io/evcc/core/vehicle"
|
||||||
"github.com/evcc-io/evcc/provider/mqtt"
|
"github.com/evcc-io/evcc/plugin/mqtt"
|
||||||
"github.com/evcc-io/evcc/util"
|
"github.com/evcc-io/evcc/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/evcc-io/evcc/provider/golang/stdlib"
|
"github.com/evcc-io/evcc/plugin/golang/stdlib"
|
||||||
"github.com/traefik/yaegi/interp"
|
"github.com/traefik/yaegi/interp"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ import (
|
||||||
|
|
||||||
"github.com/cenkalti/backoff/v4"
|
"github.com/cenkalti/backoff/v4"
|
||||||
"github.com/evcc-io/evcc/api"
|
"github.com/evcc-io/evcc/api"
|
||||||
"github.com/evcc-io/evcc/provider"
|
"github.com/evcc-io/evcc/plugin"
|
||||||
"github.com/evcc-io/evcc/util"
|
"github.com/evcc-io/evcc/util"
|
||||||
"github.com/jinzhu/now"
|
"github.com/jinzhu/now"
|
||||||
)
|
)
|
||||||
|
|
@ -32,8 +32,8 @@ func init() {
|
||||||
func NewConfigurableFromConfig(ctx context.Context, other map[string]interface{}) (api.Tariff, error) {
|
func NewConfigurableFromConfig(ctx context.Context, other map[string]interface{}) (api.Tariff, error) {
|
||||||
cc := struct {
|
cc := struct {
|
||||||
embed `mapstructure:",squash"`
|
embed `mapstructure:",squash"`
|
||||||
Price *provider.Config
|
Price *plugin.Config
|
||||||
Forecast *provider.Config
|
Forecast *plugin.Config
|
||||||
Type api.TariffType `mapstructure:"tariff"`
|
Type api.TariffType `mapstructure:"tariff"`
|
||||||
Cache time.Duration
|
Cache time.Duration
|
||||||
}{
|
}{
|
||||||
|
|
@ -52,26 +52,17 @@ func NewConfigurableFromConfig(ctx context.Context, other map[string]interface{}
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
priceG, err := cc.Price.FloatGetter(ctx)
|
||||||
err error
|
if err != nil {
|
||||||
priceG func() (float64, error)
|
return nil, fmt.Errorf("price: %w", err)
|
||||||
forecastG func() (string, error)
|
}
|
||||||
)
|
if priceG != nil {
|
||||||
|
priceG = plugin.Cached(priceG, cc.Cache)
|
||||||
if cc.Price != nil {
|
|
||||||
priceG, err = provider.NewFloatGetterFromConfig(ctx, *cc.Price)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("price: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
priceG = provider.Cached(priceG, cc.Cache)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if cc.Forecast != nil {
|
forecastG, err := cc.Forecast.StringGetter(ctx)
|
||||||
forecastG, err = provider.NewStringGetterFromConfig(ctx, *cc.Forecast)
|
if err != nil {
|
||||||
if err != nil {
|
return nil, fmt.Errorf("forecast: %w", err)
|
||||||
return nil, fmt.Errorf("forecast: %w", err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
t := &Tariff{
|
t := &Tariff{
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/evcc-io/evcc/api"
|
"github.com/evcc-io/evcc/api"
|
||||||
"github.com/evcc-io/evcc/provider"
|
"github.com/evcc-io/evcc/plugin"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Provider implements the vehicle api
|
// Provider implements the vehicle api
|
||||||
|
|
@ -16,7 +16,7 @@ type Provider struct {
|
||||||
// NewProvider creates a vehicle api provider
|
// NewProvider creates a vehicle api provider
|
||||||
func NewProvider(api *API, user int64, vin string, cache time.Duration) *Provider {
|
func NewProvider(api *API, user int64, vin string, cache time.Duration) *Provider {
|
||||||
impl := &Provider{
|
impl := &Provider{
|
||||||
statusG: provider.Cached(func() (StatusResponse, error) {
|
statusG: plugin.Cached(func() (StatusResponse, error) {
|
||||||
return api.Status(user, vin)
|
return api.Status(user, vin)
|
||||||
}, cache),
|
}, cache),
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/evcc-io/evcc/api"
|
"github.com/evcc-io/evcc/api"
|
||||||
"github.com/evcc-io/evcc/provider"
|
"github.com/evcc-io/evcc/plugin"
|
||||||
)
|
)
|
||||||
|
|
||||||
const refreshTimeout = 2 * time.Minute
|
const refreshTimeout = 2 * time.Minute
|
||||||
|
|
@ -28,13 +28,13 @@ func NewProvider(api *API, vehicle Vehicle, expiry, cache time.Duration) *Provid
|
||||||
expiry: expiry,
|
expiry: expiry,
|
||||||
}
|
}
|
||||||
|
|
||||||
v.statusG = provider.Cached(func() (BluelinkVehicleStatus, error) {
|
v.statusG = plugin.Cached(func() (BluelinkVehicleStatus, error) {
|
||||||
return v.status(
|
return v.status(
|
||||||
func() (BluelinkVehicleStatusLatest, error) { return api.StatusLatest(vehicle) },
|
func() (BluelinkVehicleStatusLatest, error) { return api.StatusLatest(vehicle) },
|
||||||
)
|
)
|
||||||
}, cache)
|
}, cache)
|
||||||
|
|
||||||
v.statusLG = provider.Cached(func() (BluelinkVehicleStatusLatest, error) {
|
v.statusLG = plugin.Cached(func() (BluelinkVehicleStatusLatest, error) {
|
||||||
return api.StatusLatest(vehicle)
|
return api.StatusLatest(vehicle)
|
||||||
}, cache)
|
}, cache)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/evcc-io/evcc/api"
|
"github.com/evcc-io/evcc/api"
|
||||||
"github.com/evcc-io/evcc/provider"
|
"github.com/evcc-io/evcc/plugin"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Provider implements the vehicle api
|
// Provider implements the vehicle api
|
||||||
|
|
@ -16,7 +16,7 @@ type Provider struct {
|
||||||
// NewProvider creates a vehicle api provider
|
// NewProvider creates a vehicle api provider
|
||||||
func NewProvider(api *API, vin string, cache time.Duration) *Provider {
|
func NewProvider(api *API, vin string, cache time.Duration) *Provider {
|
||||||
impl := &Provider{
|
impl := &Provider{
|
||||||
statusG: provider.Cached(func() (VehicleStatus, error) {
|
statusG: plugin.Cached(func() (VehicleStatus, error) {
|
||||||
return api.Status(vin)
|
return api.Status(vin)
|
||||||
}, cache),
|
}, cache),
|
||||||
actionS: func(action string) error {
|
actionS: func(action string) error {
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/evcc-io/evcc/api"
|
"github.com/evcc-io/evcc/api"
|
||||||
"github.com/evcc-io/evcc/provider"
|
"github.com/evcc-io/evcc/plugin"
|
||||||
"github.com/evcc-io/evcc/util"
|
"github.com/evcc-io/evcc/util"
|
||||||
"github.com/evcc-io/evcc/util/request"
|
"github.com/evcc-io/evcc/util/request"
|
||||||
"github.com/joeshaw/carwings"
|
"github.com/joeshaw/carwings"
|
||||||
|
|
@ -90,8 +90,8 @@ func NewCarWingsFromConfig(other map[string]interface{}) (api.Vehicle, error) {
|
||||||
return nil, fmt.Errorf("login failed: %w", err)
|
return nil, fmt.Errorf("login failed: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
v.statusG = provider.Cached(v.status, cc.Cache)
|
v.statusG = plugin.Cached(v.status, cc.Cache)
|
||||||
v.climateG = provider.Cached(v.session.ClimateControlStatus, cc.Cache)
|
v.climateG = plugin.Cached(v.session.ClimateControlStatus, cc.Cache)
|
||||||
|
|
||||||
return v, nil
|
return v, nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue