Add SmartCharging profile (#800)
This commit is contained in:
parent
a28231da38
commit
7ed6332913
6 changed files with 74 additions and 31 deletions
|
|
@ -7,6 +7,7 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/andig/evcc/core"
|
||||
"github.com/andig/evcc/hems/ocpp/profile"
|
||||
"github.com/andig/evcc/util"
|
||||
"github.com/denisbrodbeck/machineid"
|
||||
|
||||
|
|
@ -17,22 +18,16 @@ import (
|
|||
|
||||
// OCPP is an OCPP client
|
||||
type OCPP struct {
|
||||
log *util.Logger
|
||||
cache *util.Cache
|
||||
site site
|
||||
cp ocpp16.ChargePoint
|
||||
configuration ConfigMap
|
||||
}
|
||||
|
||||
// site is the minimal interface for accessing site methods
|
||||
type site interface {
|
||||
LoadPoints() []core.LoadPointAPI
|
||||
log *util.Logger
|
||||
cache *util.Cache
|
||||
site core.SiteAPI
|
||||
cp ocpp16.ChargePoint
|
||||
}
|
||||
|
||||
const retryTimeout = 5 * time.Second
|
||||
|
||||
// New generates OCPP chargepoint client
|
||||
func New(conf map[string]interface{}, site site, cache *util.Cache) (*OCPP, error) {
|
||||
func New(conf map[string]interface{}, site core.SiteAPI, cache *util.Cache) (*OCPP, error) {
|
||||
cc := struct {
|
||||
URI string
|
||||
StationID string
|
||||
|
|
@ -58,16 +53,17 @@ func New(conf map[string]interface{}, site site, cache *util.Cache) (*OCPP, erro
|
|||
cp := ocpp16.NewChargePoint(cc.StationID, nil, ws)
|
||||
|
||||
s := &OCPP{
|
||||
log: log,
|
||||
cache: cache,
|
||||
site: site,
|
||||
cp: cp,
|
||||
configuration: getDefaultConfig(),
|
||||
log: log,
|
||||
cache: cache,
|
||||
site: site,
|
||||
cp: cp,
|
||||
}
|
||||
|
||||
err := cp.Start(cc.URI)
|
||||
if err == nil {
|
||||
cp.SetCoreHandler(s)
|
||||
cp.SetCoreHandler(profile.NewCore(log, profile.GetDefaultConfig()))
|
||||
cp.SetSmartChargingHandler(profile.NewSmartCharging(log))
|
||||
|
||||
go s.errorHandler(ws.Errors())
|
||||
go s.errorHandler(cp.Errors())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
package ocpp
|
||||
package profile
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
|
|
@ -93,7 +93,7 @@ func (c ConfigMap) set(key string, readonly bool, value string) {
|
|||
}
|
||||
}
|
||||
|
||||
func getDefaultConfig() ConfigMap {
|
||||
func GetDefaultConfig() ConfigMap {
|
||||
intBase := 10
|
||||
|
||||
var cfg ConfigMap = make(map[string]core.ConfigurationKey)
|
||||
|
|
@ -1,30 +1,43 @@
|
|||
package ocpp
|
||||
package profile
|
||||
|
||||
import (
|
||||
"github.com/andig/evcc/util"
|
||||
"github.com/lorenzodonini/ocpp-go/ocpp1.6/core"
|
||||
"github.com/lorenzodonini/ocpp-go/ocpp1.6/types"
|
||||
)
|
||||
|
||||
type Core struct {
|
||||
log *util.Logger
|
||||
configuration ConfigMap
|
||||
}
|
||||
|
||||
func NewCore(log *util.Logger, config ConfigMap) *Core {
|
||||
return &Core{
|
||||
log: log,
|
||||
configuration: config,
|
||||
}
|
||||
}
|
||||
|
||||
// OnChangeAvailability handles the CS message
|
||||
func (s *OCPP) OnChangeAvailability(request *core.ChangeAvailabilityRequest) (confirmation *core.ChangeAvailabilityConfirmation, err error) {
|
||||
func (s *Core) OnChangeAvailability(request *core.ChangeAvailabilityRequest) (confirmation *core.ChangeAvailabilityConfirmation, err error) {
|
||||
s.log.TRACE.Printf("recv: %s %+v", request.GetFeatureName(), request)
|
||||
return core.NewChangeAvailabilityConfirmation(core.AvailabilityStatusRejected), nil
|
||||
}
|
||||
|
||||
// OnUnlockConnector handles the CS message
|
||||
func (s *OCPP) OnUnlockConnector(request *core.UnlockConnectorRequest) (confirmation *core.UnlockConnectorConfirmation, err error) {
|
||||
func (s *Core) OnUnlockConnector(request *core.UnlockConnectorRequest) (confirmation *core.UnlockConnectorConfirmation, err error) {
|
||||
s.log.TRACE.Printf("recv: %s %+v", request.GetFeatureName(), request)
|
||||
return core.NewUnlockConnectorConfirmation(core.UnlockStatusUnlocked), nil
|
||||
}
|
||||
|
||||
// OnRemoteStartTransaction handles the CS message
|
||||
func (s *OCPP) OnRemoteStartTransaction(request *core.RemoteStartTransactionRequest) (confirmation *core.RemoteStartTransactionConfirmation, err error) {
|
||||
func (s *Core) OnRemoteStartTransaction(request *core.RemoteStartTransactionRequest) (confirmation *core.RemoteStartTransactionConfirmation, err error) {
|
||||
s.log.TRACE.Printf("recv: %s %+v", request.GetFeatureName(), request)
|
||||
return core.NewRemoteStartTransactionConfirmation(types.RemoteStartStopStatusRejected), nil
|
||||
}
|
||||
|
||||
// OnRemoteStopTransaction handles the CS message
|
||||
func (s *OCPP) OnRemoteStopTransaction(request *core.RemoteStopTransactionRequest) (confirmation *core.RemoteStopTransactionConfirmation, err error) {
|
||||
func (s *Core) OnRemoteStopTransaction(request *core.RemoteStopTransactionRequest) (confirmation *core.RemoteStopTransactionConfirmation, err error) {
|
||||
s.log.TRACE.Printf("recv: %s %+v", request.GetFeatureName(), request)
|
||||
return core.NewRemoteStopTransactionConfirmation(types.RemoteStartStopStatusRejected), nil
|
||||
}
|
||||
|
|
@ -1,9 +1,9 @@
|
|||
package ocpp
|
||||
package profile
|
||||
|
||||
import "github.com/lorenzodonini/ocpp-go/ocpp1.6/core"
|
||||
|
||||
// OnGetConfiguration handles the CS message
|
||||
func (s *OCPP) OnGetConfiguration(request *core.GetConfigurationRequest) (confirmation *core.GetConfigurationConfirmation, err error) {
|
||||
func (s *Core) OnGetConfiguration(request *core.GetConfigurationRequest) (confirmation *core.GetConfigurationConfirmation, err error) {
|
||||
s.log.TRACE.Printf("recv: %s %+v", request.GetFeatureName(), request)
|
||||
|
||||
var resultKeys []core.ConfigurationKey
|
||||
|
|
@ -34,7 +34,7 @@ func (s *OCPP) OnGetConfiguration(request *core.GetConfigurationRequest) (confir
|
|||
}
|
||||
|
||||
// OnChangeConfiguration handles the CS message
|
||||
func (s *OCPP) OnChangeConfiguration(request *core.ChangeConfigurationRequest) (confirmation *core.ChangeConfigurationConfirmation, err error) {
|
||||
func (s *Core) OnChangeConfiguration(request *core.ChangeConfigurationRequest) (confirmation *core.ChangeConfigurationConfirmation, err error) {
|
||||
s.log.TRACE.Printf("recv: %s %+v", request.GetFeatureName(), request)
|
||||
return core.NewChangeConfigurationConfirmation(core.ConfigurationStatusAccepted), nil
|
||||
}
|
||||
|
|
@ -1,23 +1,23 @@
|
|||
package ocpp
|
||||
package profile
|
||||
|
||||
import (
|
||||
"github.com/lorenzodonini/ocpp-go/ocpp1.6/core"
|
||||
)
|
||||
|
||||
// OnClearCache handles the CS message
|
||||
func (s *OCPP) OnClearCache(request *core.ClearCacheRequest) (confirmation *core.ClearCacheConfirmation, err error) {
|
||||
func (s *Core) OnClearCache(request *core.ClearCacheRequest) (confirmation *core.ClearCacheConfirmation, err error) {
|
||||
s.log.TRACE.Printf("recv: %s", request.GetFeatureName())
|
||||
return core.NewClearCacheConfirmation(core.ClearCacheStatusAccepted), nil
|
||||
}
|
||||
|
||||
// OnDataTransfer handles the CS message
|
||||
func (s *OCPP) OnDataTransfer(request *core.DataTransferRequest) (confirmation *core.DataTransferConfirmation, err error) {
|
||||
func (s *Core) OnDataTransfer(request *core.DataTransferRequest) (confirmation *core.DataTransferConfirmation, err error) {
|
||||
s.log.TRACE.Printf("recv: %s %+v", request.GetFeatureName(), request)
|
||||
return core.NewDataTransferConfirmation(core.DataTransferStatusAccepted), nil
|
||||
}
|
||||
|
||||
// OnReset handles the CS message
|
||||
func (s *OCPP) OnReset(request *core.ResetRequest) (confirmation *core.ResetConfirmation, err error) {
|
||||
func (s *Core) OnReset(request *core.ResetRequest) (confirmation *core.ResetConfirmation, err error) {
|
||||
s.log.TRACE.Printf("recv: %s %+v", request.GetFeatureName(), request)
|
||||
return core.NewResetConfirmation(core.ResetStatusAccepted), nil
|
||||
}
|
||||
34
hems/ocpp/profile/smartcharging.go
Normal file
34
hems/ocpp/profile/smartcharging.go
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
package profile
|
||||
|
||||
import (
|
||||
"github.com/andig/evcc/util"
|
||||
sc "github.com/lorenzodonini/ocpp-go/ocpp1.6/smartcharging"
|
||||
)
|
||||
|
||||
type SmartCharging struct {
|
||||
log *util.Logger
|
||||
}
|
||||
|
||||
func NewSmartCharging(log *util.Logger) *SmartCharging {
|
||||
return &SmartCharging{
|
||||
log: log,
|
||||
}
|
||||
}
|
||||
|
||||
// OnSetChargingProfile handles the CS message
|
||||
func (s *SmartCharging) OnSetChargingProfile(request *sc.SetChargingProfileRequest) (confirmation *sc.SetChargingProfileConfirmation, err error) {
|
||||
s.log.TRACE.Printf("recv: %s %+v", request.GetFeatureName(), request)
|
||||
return sc.NewSetChargingProfileConfirmation(sc.ChargingProfileStatusRejected), nil
|
||||
}
|
||||
|
||||
// OnClearChargingProfile handles the CS message
|
||||
func (s *SmartCharging) OnClearChargingProfile(request *sc.ClearChargingProfileRequest) (confirmation *sc.ClearChargingProfileConfirmation, err error) {
|
||||
s.log.TRACE.Printf("recv: %s %+v", request.GetFeatureName(), request)
|
||||
return sc.NewClearChargingProfileConfirmation(sc.ClearChargingProfileStatusUnknown), nil
|
||||
}
|
||||
|
||||
// OnGetCompositeSchedule handles the CS message
|
||||
func (s *SmartCharging) OnGetCompositeSchedule(request *sc.GetCompositeScheduleRequest) (confirmation *sc.GetCompositeScheduleConfirmation, err error) {
|
||||
s.log.TRACE.Printf("recv: %s %+v", request.GetFeatureName(), request)
|
||||
return sc.NewGetCompositeScheduleConfirmation(sc.GetCompositeScheduleStatusRejected), nil
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue