Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ocpp: use setProfile=0 for suspend #12861

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Ocpp: use setProfile=0 for suspend
  • Loading branch information
andig committed Feb 25, 2024
commit c2ff3c8dd6b2a7d7d64db0e889180adabcf945c1
38 changes: 16 additions & 22 deletions charger/ocpp.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,8 +335,8 @@ func (c *OCPP) Enable(enable bool) (err error) {

if enable {
if txn > 0 {
// we have the transaction id, treat as enabled
return nil
// we have the transaction id, switch from 0A to last current
return c.updatePeriod(c.current)
}

err = ocpp.Instance().RemoteStartTransaction(c.conn.ChargePoint().ID(), func(resp *core.RemoteStartTransactionConfirmation, err error) {
Expand All @@ -350,31 +350,25 @@ func (c *OCPP) Enable(enable bool) (err error) {
request.ConnectorId = &connector
request.ChargingProfile = c.getTxChargingProfile(c.current, 0)
})
} else {
// if no transaction is running, the vehicle may have stopped it (which is ok) or an unknown transaction is running
if txn == 0 {
// we cannot tell if a transaction is really running, so we check the status
status, err := c.Status()
if err != nil {
return err
}
if status == api.StatusC {
return errors.New("cannot disable: unknown transaction running")
}

return nil
}
return c.wait(err, rc)
}

err = ocpp.Instance().RemoteStopTransaction(c.conn.ChargePoint().ID(), func(resp *core.RemoteStopTransactionConfirmation, err error) {
if err == nil && resp != nil && resp.Status != types.RemoteStartStopStatusAccepted {
err = errors.New(string(resp.Status))
}
// if no transaction is running, the vehicle may have stopped it (which is ok) or an unknown transaction is running
if txn == 0 {
// we cannot tell if a transaction is really running, so we check the status
status, err := c.Status()
if err != nil {
return err
}
if status == api.StatusC {
return errors.New("cannot disable: unknown transaction running")
}

rc <- err
}, txn)
return nil
}

return c.wait(err, rc)
return c.updatePeriod(0)
}

func (c *OCPP) setChargingProfile(profile *types.ChargingProfile) error {
Expand Down