UNPKG

homebridge-virtual-accessories

Version:
37 lines 1.69 kB
import { Accessory } from '../accessories/accessory.js'; /** * Sensor - Abstract accessory */ export class MeasurementSensor extends Accessory { valueMeasured; states = { SensorValue: 0, SensorUnits: '', }; constructor(platform, accessory, accessoryConfiguration) { super(platform, accessory, accessoryConfiguration); // First configure the device based on the accessory details this.states.SensorValue = this.getDefaultValue(); this.states.SensorUnits = this.accessoryConfiguration.measurement.units; this.valueMeasured = this.getMeasurementCharacteristic(); const sensorService = this.getService(); this.service = this.accessory.getService(sensorService) || this.accessory.addService(sensorService); this.service.setCharacteristic(this.platform.Characteristic.Name, this.accessoryConfiguration.accessoryName); // Update the initial state of the accessory this.log.debug(`[${this.accessoryConfiguration.accessoryName}] Setting Sensor Current Value: ${this.states.SensorValue}`); this.service.updateCharacteristic(this.valueMeasured, (this.states.SensorValue)); // register handlers this.service.getCharacteristic(this.valueMeasured) .onGet(this.getValueMeasured.bind(this)); } // Handlers async getValueMeasured() { const sensorValue = this.states.SensorValue; this.log.debug(`[${this.accessoryConfiguration.accessoryName}] Getting Sensor Current State: ${sensorValue}`); return sensorValue; } getJsonState() { return JSON.stringify({}); } } //# sourceMappingURL=measurementSensor.js.map