UNPKG

homebridge-zigbee-v2

Version:

ZigBee Platform plugin for HomeBridge

81 lines (72 loc) 2.17 kB
const HomeKitDevice = require('../HomeKitDevice') class AqaraTunableWhiteBulb extends HomeKitDevice { static get description() { return { model: 'lumi.light.aqcn02', manufacturer: 'LUMI', name: 'Aqara Bulb', } } getAvailbleServices() { return [{ name: 'Bulb', type: 'Lightbulb', }] } onDeviceReady() { const lightingColorCtrlAttrs = this.zigbee.endpoint(1).clusters.lightingColorCtrl.attrs this.brightnessTimeout = null const onCharacteristic = this.getServiceCharacteristic('Bulb', 'On') const colorTemperature = this.getServiceCharacteristic('Bulb', 'ColorTemperature') const brightnessCharacteristic = this.getServiceCharacteristic('Bulb', 'Brightness') colorTemperature.setProps({ minValue: lightingColorCtrlAttrs.colorTempPhysicalMin, maxValue: lightingColorCtrlAttrs.colorTempPhysicalMax, }) onCharacteristic.on('set', (value) => { this.clearTimeout(this.brightnessTimeout) if (value) { this.brightnessTimeout = this.setTimeout(() => { brightnessCharacteristic.setValue(brightnessCharacteristic.value) }, 500) } }) this.mountServiceCharacteristic({ endpoint: 1, cluster: 'genOnOff', service: 'Bulb', characteristic: 'On', reportMinInt: 1, reportMaxInt: 300, reportChange: 1, parser: 'onOff', }) this.mountServiceCharacteristic({ endpoint: 1, cluster: 'genLevelCtrl', service: 'Bulb', characteristic: 'Brightness', reportMinInt: 1, reportMaxInt: 300, reportChange: 1, parser: 'dim', }) this.mountServiceCharacteristic({ endpoint: 1, cluster: 'lightingColorCtrl', service: 'Bulb', characteristic: 'ColorTemperature', reportMinInt: 1, reportMaxInt: 300, reportChange: 1, parser: 'colorTemperature', reportParser: value => Math.round(value), getParser: value => Math.round(value), setParser: value => ({ colortemp: Math.round(value), transtime: 5, }), }) } } module.exports = AqaraTunableWhiteBulb