homebridge-virtual-accessories
Version:
Virtual HomeKit accessories for Homebridge.
41 lines • 1.87 kB
JavaScript
import { MeasurementSensor } from './measurementSensor.js';
import { InvalidSensorValueType, SensorValueUpdateNotAllowed } from '../errors.js';
/**
* HumiditySensor - Sensor implementation
*/
export class HumiditySensor extends MeasurementSensor {
static ACCESSORY_TYPE_NAME = 'HumiditySensor';
static DEFAULT_RELATIVE_HUMIDITY = 50;
constructor(platform, accessory, accessoryConfiguration) {
super(platform, accessory, accessoryConfiguration);
}
getService() {
return this.platform.Service.HumiditySensor;
}
getMeasurementCharacteristic() {
return this.platform.Characteristic.CurrentRelativeHumidity;
}
getDefaultValue() {
return HumiditySensor.DEFAULT_RELATIVE_HUMIDITY;
}
getAccessoryTypeName() {
return HumiditySensor.ACCESSORY_TYPE_NAME;
}
// Updatable Sensor interface
updateMeasurementSensor(value, accessoryId) {
this.log.debug(`[${this.accessoryConfiguration.accessoryName}] Request update humidity sensor to ${value}%`);
if (accessoryId !== this.accessoryConfiguration.accessoryID) {
this.log.error(`[${this.accessoryConfiguration.accessoryName}] Accessory Id ${accessoryId} is not valid for this accessory`);
throw new SensorValueUpdateNotAllowed(`Invalid accessory id: ${accessoryId}`);
}
else if (typeof value !== 'number') {
this.log.error(`[${this.accessoryConfiguration.accessoryName}] Value ${value} is not valid for Humidifier/Dehumidifier sensor`);
throw new InvalidSensorValueType(`Invalid sensor value: ${value}`);
}
else {
this.log.debug(`[${this.accessoryConfiguration.accessoryName}] Updating humidity sensor to ${value}%`);
this.states.SensorValue = value;
}
}
}
//# sourceMappingURL=virtualSensorHumidity.js.map