forked from reinierl/docile-charge-point
-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathdo-a-transaction.scala
57 lines (47 loc) · 1.61 KB
/
do-a-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
50
51
52
53
54
55
56
57
val chargeTokenId = "04EC2CC2552280"
val auth = authorize(chargeTokenId).idTag
if (auth.status == AuthorizationStatus.Accepted) {
statusNotification(status = ChargePointStatus.Occupied(Some(OccupancyKind.Preparing)))
val startTransactionTimestamp = java.time.ZonedDateTime.now
val stopTransactionTimestamp = startTransactionTimestamp.plusMinutes(10)
val connectorScope = ConnectorScope(0) // meaning the 1st EVSE
val transId = startTransaction(
meterStart = 300,
idTag = chargeTokenId,
connector = connectorScope,
timestamp = startTransactionTimestamp
).transactionId
statusNotification(
status = ChargePointStatus.Occupied(Some(OccupancyKind.Charging)),
scope = connectorScope,
timestamp = Some(startTransactionTimestamp)
)
prompt("Press ENTER to stop charging")
// sleep(randomize(1.second))
// statusNotification(
// status = ChargePointStatus.Faulted(
// errorCode = Some(com.thenewmotion.ocpp.messages.v1x.ChargePointErrorCode.OtherError),
// vendorErrorCode = Some("349")
// ),
// scope = connectorScope,
// timestamp = Some(stopTransactionTimestamp)
// )
statusNotification(
status = ChargePointStatus.Occupied(Some(OccupancyKind.Finishing)),
scope = connectorScope,
timestamp = Some(stopTransactionTimestamp)
)
stopTransaction(
transactionId = transId,
meterStop = 310,
idTag = Some(chargeTokenId),
timestamp = stopTransactionTimestamp
)
statusNotification(
status = ChargePointStatus.Available(),
scope = connectorScope,
timestamp = Some(stopTransactionTimestamp)
)
} else {
fail("Not authorized")
}