homebridge-hilo
Version:
Plugin Homebridge (non officiel) pour la passerelle et les appareils Hilo de Hydro-Québec | Unofficial Homebridge plugin for Hydro-Québec Hilo bridge and devices
34 lines (30 loc) • 1.05 kB
text/typescript
import { API, Logging, PlatformAccessory, Service } from "homebridge";
import { getLogger } from "../logger";
import { DeviceAccessory } from "./types";
import { Device } from "../graphql/graphql";
export abstract class HiloDevice<T extends Device> {
protected service: Service | null = null;
constructor(
protected readonly accessory: PlatformAccessory<DeviceAccessory<T>>,
protected readonly api: API,
protected readonly logger: Logging = getLogger(),
) {
accessory
.getService(this.api.hap.Service.AccessoryInformation)!
.setCharacteristic(this.api.hap.Characteristic.Manufacturer, "Hilo")
.setCharacteristic(
this.api.hap.Characteristic.Model,
accessory.context.device.type,
)
.setCharacteristic(
this.api.hap.Characteristic.SerialNumber,
accessory.context.graphqlDevice.physicalAddress,
);
}
get device(): T {
return this.accessory.context.graphqlDevice;
}
updateDevice(device: T) {
this.accessory.context.graphqlDevice = device;
}
}