-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #112 from e-flux-platform/madic-lafon
Add MADIC/LAFON model
- Loading branch information
Showing
5 changed files
with
110 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
src/lib/ChargeStation/configurations/madic-lafon-ocpp-16.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import DefaultOCPP16 from 'lib/ChargeStation/configurations/default-ocpp-16'; | ||
import { EventTypes as e } from 'lib/ChargeStation/eventHandlers/event-types'; | ||
import sendAuthorizeOrStartTransaction from 'lib/ChargeStation/eventHandlers/ocpp-16/send-authorize-or-start-transaction'; | ||
import overrideSessionUid from 'lib/ChargeStation/eventHandlers/ocpp-16/madic-lafon/override-session-uid'; | ||
import sendStopTransactionWithCost from 'lib/ChargeStation/eventHandlers/ocpp-16/madic-lafon/session-stop-initiated'; | ||
|
||
export default { | ||
...DefaultOCPP16, | ||
[e.SessionStartInitiated]: [ | ||
overrideSessionUid, | ||
sendAuthorizeOrStartTransaction, | ||
], | ||
[e.SessionStopInitiated]: [sendStopTransactionWithCost], | ||
}; |
15 changes: 15 additions & 0 deletions
15
src/lib/ChargeStation/eventHandlers/ocpp-16/madic-lafon/override-session-uid.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { ChargeStationEventHandler } from 'lib/ChargeStation/eventHandlers'; | ||
import { AuthorizationType } from 'lib/settings'; | ||
|
||
const overrideSessionUid: ChargeStationEventHandler = async (params) => { | ||
const { session, chargepoint } = params; | ||
if (session.options.authorizationType !== AuthorizationType.CreditCard) { | ||
return; // retain current idTag | ||
} | ||
|
||
session.options.uid = chargepoint.configuration.getVariableValue( | ||
'IDTagBankCard' | ||
) as string; | ||
}; | ||
|
||
export default overrideSessionUid; |
59 changes: 59 additions & 0 deletions
59
src/lib/ChargeStation/eventHandlers/ocpp-16/madic-lafon/session-stop-initiated.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { sleep } from 'utils/csv'; | ||
import { ChargeStationEventHandler } from 'lib/ChargeStation/eventHandlers'; | ||
import { StopTransactionRequest } from 'schemas/ocpp/1.6/StopTransaction'; | ||
|
||
const sendStopTransactionWithCost: ChargeStationEventHandler = async ({ | ||
chargepoint, | ||
session, | ||
}) => { | ||
chargepoint.sessions[session.connectorId].isStoppingSession = true; | ||
chargepoint.sessions[session.connectorId].tickInterval?.stop(); | ||
|
||
await sleep(1000); | ||
|
||
// Calculations below are just general approximations of how costs may be applied. | ||
const priceTime = chargepoint.configuration.getVariableValue( | ||
'ChargePriceTime' | ||
) as number; | ||
const priceEnergy = chargepoint.configuration.getVariableValue( | ||
'ChargePriceEnergy' | ||
) as number; | ||
|
||
const startTime = session.startTime; | ||
const stopTime = session.stopTime as Date; | ||
const durationMinutes = | ||
(stopTime.getTime() - startTime.getTime()) / 1000 / 60; | ||
|
||
const durationCost = durationMinutes * priceTime; | ||
const kWhCost = session.kwhElapsed * priceEnergy; | ||
const sessionCost = durationCost + kWhCost; | ||
|
||
chargepoint.writeCall<StopTransactionRequest>( | ||
'StopTransaction', | ||
{ | ||
idTag: session.options.uid, | ||
meterStop: Math.round(session.kwhElapsed * 1000), | ||
timestamp: stopTime.toISOString(), | ||
reason: 'EVDisconnected', | ||
transactionId: Number(session.transactionId), | ||
transactionData: [ | ||
{ | ||
timestamp: stopTime.toISOString(), | ||
sampledValue: [ | ||
{ | ||
value: sessionCost.toFixed(2), | ||
context: 'Transaction.End', | ||
location: 'Body', | ||
unit: 'Celcius', | ||
format: 'Raw', | ||
measurand: 'Temperature', | ||
}, | ||
], | ||
}, | ||
], | ||
}, | ||
session | ||
); | ||
}; | ||
|
||
export default sendStopTransactionWithCost; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters