Skip to content

Commit

Permalink
Merge pull request #22 from juherr/feature/ocpp-configuration
Browse files Browse the repository at this point in the history
Feature: implements missing action from Core profile
  • Loading branch information
shiv3 authored Nov 29, 2024
2 parents d7735e5 + acf1dba commit d68c4f1
Show file tree
Hide file tree
Showing 7 changed files with 670 additions and 54 deletions.
13 changes: 7 additions & 6 deletions src/components/Connector.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, {useState, useEffect} from "react";
import {ChargePoint} from "../cp/ChargePoint.ts";
import * as ocpp from "../cp/OcppTypes";
import { OCPPAvailability } from "../cp/OcppTypes";

interface ConnectorProps {
id: number;
Expand All @@ -13,8 +14,8 @@ const Connector: React.FC<ConnectorProps> = ({id: connector_id, cp,idTag}) => {
const [connectorStatus, setConnectorStatus] = useState<ocpp.OCPPStatus>(
ocpp.OCPPStatus.Unavailable
);
const [availability, setAvailability] = useState<string>(
ocpp.OCPPAvailability.Operative
const [availability, setAvailability] = useState<OCPPAvailability>(
"Operative"
);
const [meterValue, setMeterValue] = useState<number>(0);
const [tagId, setIdTag] = useState<string>(idTag);
Expand Down Expand Up @@ -223,12 +224,12 @@ const ConnectorStatus: React.FC<{ status: string }> = ({status}) => {
return <span className={statusColor(status)}>{status}</span>;
};

const ConnectorAvailability: React.FC<{ availability: string }> = ({availability,}) => {
const availabilityColor = (a: string) => {
const ConnectorAvailability: React.FC<{ availability: OCPPAvailability }> = ({availability,}) => {
const availabilityColor = (a: OCPPAvailability) => {
switch (a) {
case ocpp.OCPPAvailability.Operative:
case "Operative":
return "text-green-500";
case ocpp.OCPPAvailability.Inoperative:
case "Inoperative":
return "text-red-500";
default:
return "text-black";
Expand Down
33 changes: 17 additions & 16 deletions src/cp/ChargePoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export class ChargePoint {
| null = null;
private _availabilityChangeCallbacks: Map<
number,
(availability: string) => void
(availability: OCPPAvailability) => void
> = new Map();

constructor(id: string,
Expand Down Expand Up @@ -121,7 +121,7 @@ export class ChargePoint {

setAvailabilityChangeCallback(
connectorId: number,
callback: (availability: string) => void
callback: (availability: OCPPAvailability) => void
): void {
this._availabilityChangeCallbacks.set(connectorId, callback);
}
Expand Down Expand Up @@ -320,23 +320,24 @@ export class ChargePoint {

public updateConnectorAvailability(
connectorId: number,
newAvailability: string
): void {
newAvailability: OCPPAvailability
): boolean {
const connector = this.getConnector(connectorId);
if (connector) {
connector.availability! = newAvailability;
if (newAvailability === OCPPAvailability.Inoperative) {
this.updateConnectorStatus(connectorId, OCPPStatus.Unavailable);
} else if (newAvailability === OCPPAvailability.Operative) {
this.updateConnectorStatus(connectorId, OCPPStatus.Available);
}
const callback = this._availabilityChangeCallbacks.get(connectorId);
if (callback) {
callback(newAvailability);
}
} else {
if (!connector) {
this._logger.error(`Connector ${connectorId} not found`);
return false;
}
connector.availability = newAvailability;
if (newAvailability === "Inoperative") {
this.updateConnectorStatus(connectorId, OCPPStatus.Unavailable);
} else if (newAvailability === "Operative") {
this.updateConnectorStatus(connectorId, OCPPStatus.Available);
}
const callback = this._availabilityChangeCallbacks.get(connectorId);
if (callback) {
callback(newAvailability);
}
return true;
}

public setTransactionID(connectorId: number, transactionId: number): void {
Expand Down
Loading

0 comments on commit d68c4f1

Please sign in to comment.