Class: Ocpp::Rails::ChangeAvailabilityJob

Inherits:
ApplicationJob
  • Object
show all
Defined in:
app/jobs/ocpp/rails/change_availability_job.rb

Instance Method Summary collapse

Instance Method Details

#perform(charge_point_id, connector_id, type) ⇒ Object

connector_id/type are the OCPP ChangeAvailability.req fields; type is "Operative" or "Inoperative", and connectorId 0 targets the whole charge point rather than a single connector.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'app/jobs/ocpp/rails/change_availability_job.rb', line 9

def perform(charge_point_id, connector_id, type)
  charge_point = ChargePoint.find(charge_point_id)
  message_id = SecureRandom.uuid

  payload = {
    connectorId: connector_id.to_i,
    type: type
  }

  message = Protocol.build_call(message_id, "ChangeAvailability", payload)

  Message.create!(
    charge_point: charge_point,
    message_id: message_id,
    direction: "outbound",
    action: "ChangeAvailability",
    message_type: "CALL",
    payload: payload,
    status: "pending"
  )

  send_to_charge_point(charge_point, message)
end