redmatic-homekit
Version:
HAP-Nodejs based Node-RED nodes to create HomeKit Accessories
29 lines (25 loc) • 1.32 kB
JavaScript
const Accessory = require('./lib/accessory');
module.exports = class HmWds100 extends Accessory {
init(config) {
this.addService('TemperatureSensor', config.name)
.setProps('CurrentTemperature', {minValue: -40, maxValue: 80})
.get('CurrentTemperature', config.deviceAddress + ':1.TEMPERATURE')
.get('StatusLowBattery', config.deviceAddress + ':0.LOWBAT', (value, c) => {
return value ? c.BATTERY_LEVEL_LOW : c.BATTERY_LEVEL_NORMAL;
});
if (this.option('HumiditySensor')) {
this.addService('HumiditySensor', config.name)
.get('CurrentRelativeHumidity', config.deviceAddress + ':1.HUMIDITY')
.get('StatusLowBattery', config.deviceAddress + ':0.LOWBAT', (value, c) => {
return value ? c.BATTERY_LEVEL_LOW : c.BATTERY_LEVEL_NORMAL;
});
}
if (this.option('LightSensor')) {
this.addService('LightSensor', config.name)
.get('CurrentAmbientLightLevel', config.deviceAddress + ':1.BRIGHTNESS', this.lux)
.get('StatusLowBattery', config.deviceAddress + ':0.LOWBAT', (value, c) => {
return value ? c.BATTERY_LEVEL_LOW : c.BATTERY_LEVEL_NORMAL;
});
}
}
};