forked from ShellRechargeSolutionsEU/docile-charge-point
-
Notifications
You must be signed in to change notification settings - Fork 0
/
remote-transaction.scala
49 lines (34 loc) · 1.47 KB
/
remote-transaction.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
say("Booting...")
bootNotification()
say("Setting EVSE 1 available")
statusNotification() // EVSE 1 available
say("Waiting for remote start")
val req = expectIncoming(requestMatching { case r: RequestStartTransactionRequest => r }.respondingWith(RequestStartTransactionResponse(RequestStartStopStatus.Accepted, transactionId = Some("zlunk"))))
say ("Received request to start, starting transaction...")
statusNotification(connectorStatus = ConnectorStatus.Occupied, evseId = req.evseId.get)
val (tx, startReq) = startTransaction(
transactionData = Transaction(
id = "zlunk",
chargingState = None,
timeSpentCharging = Some(0),
stoppedReason = None,
remoteStartId = Some(1)
),
triggerReason = TriggerReason.RemoteStart,
idToken = Some(req.idToken.copy(additionalInfo = None))
)
sendSync(startReq)
prompt("Press ENTER to plug in cable")
sendSync(tx.plugInCable())
say("Starting to deliver energy...")
sendSync(tx.startEnergyOffer())
say("Waiting for remote stop")
val stopReq = expectIncoming(requestMatching { case r: RequestStopTransactionRequest => r }.respondingWith(RequestStopTransactionResponse(status = RequestStartStopStatus.Accepted)))
if (stopReq.transactionId == "zlunk") {
say("Stop request received, stopping")
sendSync(tx.end(stoppedReason = Reason.Remote, triggerReason = TriggerReason.RemoteStop))
statusNotification(connectorStatus = ConnectorStatus.Available)
} else {
fail("Received unexpected request")
}
// vim: set ts=4 sw=4 et: