homebridge-freeathome-local-api
Version:
Control your free@home setup using the local API provided by your System Access Point
45 lines • 2.17 kB
JavaScript
import { FreeAtHomeAccessory } from "./freeAtHomeAccessory.js";
import { getDataPointByPairingID } from "./util.js";
const pidCurrentLightLevel = 1027;
/** A brightness sensor integrated in the free@home weather station. */
export class WeatherStationBrightnessSensorAccessory extends FreeAtHomeAccessory {
platform;
accessory;
service;
currentLightLevel;
pdCurrentLightLevel;
/**
* Constructs a new brightness sensor accessory instance.
* @param platform The free@home Homebridge platform controlling the accessory
* @param accessory The platform accessory.
*/
constructor(platform, accessory) {
super(platform, accessory);
this.platform = platform;
this.accessory = accessory;
// Resolve data points
if (!this.accessory.context.channel.outputs)
throw new Error("Channel lacks expected input or output data points.");
this.pdCurrentLightLevel = getDataPointByPairingID(this.accessory.context.channel.outputs, pidCurrentLightLevel);
// set initial state
this.currentLightLevel = parseFloat(this.accessory.context.channel.outputs[this.pdCurrentLightLevel].value ??
"0.0001");
// get the LightSensor service if it exists, otherwise create a new service instance
this.service =
this.accessory.getService(this.platform.Service.LightSensor) ||
this.accessory.addService(this.platform.Service.LightSensor);
// register handlers for the Current Ambient Light Level characteristic
this.service
.getCharacteristic(this.platform.Characteristic.CurrentAmbientLightLevel)
.onGet(() => this.currentLightLevel);
}
updateDatapoint(datapoint, value) {
// ignore unknown data points
if (datapoint !== this.pdCurrentLightLevel)
return;
// do the update
this.currentLightLevel = parseFloat(value);
this.doUpdateDatapoint("Brightness Sensor", this.service, this.platform.Characteristic.CurrentAmbientLightLevel, this.currentLightLevel);
}
}
//# sourceMappingURL=brightnessSensorAccessory.js.map