28 lines
638 B
Go
28 lines
638 B
Go
package curtailer
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"strings"
|
|
|
|
"github.com/evcc-io/evcc/api"
|
|
"github.com/evcc-io/evcc/util"
|
|
reg "github.com/evcc-io/evcc/util/registry"
|
|
)
|
|
|
|
var registry = reg.New[api.Curtailer]("curtailer")
|
|
|
|
// NewFromConfig creates curtailer from configuration
|
|
func NewFromConfig(ctx context.Context, typ string, other map[string]any) (api.Curtailer, error) {
|
|
factory, err := registry.Get(strings.ToLower(typ))
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
v, err := factory(ctx, other)
|
|
if err != nil {
|
|
err = fmt.Errorf("cannot create curtailer type '%s': %w", util.TypeWithTemplateName(typ, other), err)
|
|
}
|
|
|
|
return v, err
|
|
}
|