evcc-io/charger/config/config.go
2025-10-31 15:25:53 +00:00

27 lines
565 B
Go

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