Skip to content

Commit

Permalink
Switch to Outlet
Browse files Browse the repository at this point in the history
Gain OutletinUse characteristic.
  • Loading branch information
loa committed Sep 22, 2024
1 parent e716688 commit c0b33d0
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/platformAccessory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ export class GaroAccessory {
);

this.service =
this.accessory.getService(this.platform.Service.Switch) ||
this.accessory.addService(this.platform.Service.Switch);
this.accessory.getService(this.platform.Service.Outlet) ||
this.accessory.addService(this.platform.Service.Outlet);

this.service.setCharacteristic(
this.platform.Characteristic.Name,
Expand All @@ -41,6 +41,10 @@ export class GaroAccessory {
.getCharacteristic(this.platform.Characteristic.On)
.onSet(this.setOn.bind(this))
.onGet(this.getOn.bind(this));

this.service
.getCharacteristic(this.platform.Characteristic.OutletInUse)
.onGet(this.getInUse.bind(this));
}

async setOn(value: CharacteristicValue) {
Expand All @@ -65,4 +69,17 @@ export class GaroAccessory {

return isOn;
}

async getInUse(): Promise<CharacteristicValue> {
const response = await fetch(
`${this.accessory.context.device.address}/servlet/rest/chargebox/status`,
);
const data = (await response.json()) as GaroStatusResponse;

const inUse = data.mainCharger.connector !== 'INITIALIZATION';

this.platform.log.debug(`Get Characteristic OutletInUse (${data.mainCharger.connector}) ->`, inUse);

return inUse;
}
}
8 changes: 8 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,12 @@ export interface GaroPlatformConfigDevice {
export interface GaroStatusResponse {
serialNumber: number;
mode: string;
mainCharger: GaroStatusResponseCharger;
}


export interface GaroStatusResponseCharger {
reference: 'Primary' | 'Secondary';
serialNumber: number;
connector: 'INITIALIZATION' | 'CONNECTED' | 'CHARGING' | 'CHARGING_FINISHED';
}

0 comments on commit c0b33d0

Please sign in to comment.