Skip to content

Commit

Permalink
Ocpp: handle empty charging schedule (evcc-io#16002)
Browse files Browse the repository at this point in the history
  • Loading branch information
andig authored Sep 9, 2024
1 parent 4e9fb2f commit 7457dd8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
16 changes: 7 additions & 9 deletions charger/ocpp/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,19 +100,17 @@ func (conn *Connector) SetChargingProfile(profile *types.ChargingProfile) error

// getScheduleLimit queries the current or power limit the charge point is currently set to offer
func (conn *Connector) GetScheduleLimit(duration int) (float64, error) {
var limit float64
schedule, err := Instance().GetCompositeScheduleRequest(conn.cp.ID(), conn.id, duration)
if err != nil {
return 0, err
}

if err == nil {
if schedule != nil && len(schedule.ChargingSchedulePeriod) > 0 {
// return first (current) period limit
limit = schedule.ChargingSchedulePeriod[0].Limit
} else {
err = fmt.Errorf("invalid ChargingSchedule")
}
// return first (current) period limit
if schedule != nil && schedule.ChargingSchedule != nil && len(schedule.ChargingSchedule.ChargingSchedulePeriod) > 0 {
return schedule.ChargingSchedule.ChargingSchedulePeriod[0].Limit, nil
}

return limit, err
return 0, fmt.Errorf("invalid ChargingSchedule")
}

// WatchDog triggers meter values messages if older than timeout.
Expand Down
6 changes: 3 additions & 3 deletions charger/ocpp/cs_core.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,16 @@ func (cs *CS) SetChargingProfileRequest(id string, connector int, profile *types
return wait(err, rc)
}

func (cs *CS) GetCompositeScheduleRequest(id string, connector int, duration int) (*types.ChargingSchedule, error) {
var schedule *types.ChargingSchedule
func (cs *CS) GetCompositeScheduleRequest(id string, connector int, duration int) (*smartcharging.GetCompositeScheduleConfirmation, error) {
var schedule *smartcharging.GetCompositeScheduleConfirmation
rc := make(chan error, 1)

err := cs.GetCompositeSchedule(id, func(request *smartcharging.GetCompositeScheduleConfirmation, err error) {
if err == nil && request != nil && request.Status != smartcharging.GetCompositeScheduleStatusAccepted {
err = errors.New(string(request.Status))
}

schedule = request.ChargingSchedule
schedule = request

rc <- err
}, connector, duration)
Expand Down

0 comments on commit 7457dd8

Please sign in to comment.