diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..25c8fdb --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +node_modules +package-lock.json \ No newline at end of file diff --git a/index.js b/index.js index efaf19f..8d33287 100644 --- a/index.js +++ b/index.js @@ -48,12 +48,12 @@ const CLASS_DEF = { oildiffuser: OilDiffuserAccessory }; -let Characteristic, PlatformAccessory, Service, Categories, UUID; +let Characteristic, PlatformAccessory, Service, Categories, AdaptiveLightingController, UUID; module.exports = function(homebridge) { ({ platformAccessory: PlatformAccessory, - hap: {Characteristic, Service, Accessory: {Categories}, uuid: UUID} + hap: {Characteristic, Service, AdaptiveLightingController, Accessory: {Categories}, uuid: UUID} } = homebridge); homebridge.registerPlatform(PLUGIN_NAME, PLATFORM_NAME, TuyaLan, true); diff --git a/lib/BaseAccessory.js b/lib/BaseAccessory.js index fece92b..fc87b82 100644 --- a/lib/BaseAccessory.js +++ b/lib/BaseAccessory.js @@ -252,6 +252,11 @@ class BaseAccessory { b: Math.round(b) }; } + + // Checks homebridge version to see if Adaptive Lighting is supported + adaptiveLightingSupport() { + return (this.platform.api.versionGreaterOrEqual && this.platform.api.versionGreaterOrEqual('v1.3.0-beta.23')) + } } module.exports = BaseAccessory; \ No newline at end of file diff --git a/lib/RGBTWLightAccessory.js b/lib/RGBTWLightAccessory.js index d78a317..7602a57 100644 --- a/lib/RGBTWLightAccessory.js +++ b/lib/RGBTWLightAccessory.js @@ -19,7 +19,7 @@ class RGBTWLightAccessory extends BaseAccessory { } _registerCharacteristics(dps) { - const {Service, Characteristic} = this.hap; + const {Service, Characteristic, AdaptiveLightingController} = this.hap; const service = this.accessory.getService(Service.Lightbulb); this._checkServiceName(service, this.device.context.name); @@ -79,6 +79,12 @@ class RGBTWLightAccessory extends BaseAccessory { this.characteristicSaturation = characteristicSaturation; this.characteristicColorTemperature = characteristicColorTemperature; + if (this.adaptiveLightingSupport()) { + this.adaptiveLightingController = new AdaptiveLightingController(service); + this.accessory.configureController(this.adaptiveLightingController); + this.accessory.adaptiveLightingController = this.adaptiveLightingController; + } + this.device.on('change', (changes, state) => { if (changes.hasOwnProperty(this.dpPower) && characteristicOn.value !== changes[this.dpPower]) characteristicOn.updateValue(changes[this.dpPower]); @@ -221,6 +227,14 @@ class RGBTWLightAccessory extends BaseAccessory { this.setMultiState({[this.dpMode]: this.cmdColor, [this.dpColor]: newValue}, callEachBack); } + + getControllers() { + if (!this.adaptiveLightingController) { + return []; + } else { + return [this.adaptiveLightingController]; + } + } } module.exports = RGBTWLightAccessory; \ No newline at end of file diff --git a/lib/TWLightAccessory.js b/lib/TWLightAccessory.js index af85a29..b168254 100644 --- a/lib/TWLightAccessory.js +++ b/lib/TWLightAccessory.js @@ -19,7 +19,7 @@ class TWLightAccessory extends BaseAccessory { } _registerCharacteristics(dps) { - const {Service, Characteristic} = this.hap; + const {Service, Characteristic, AdaptiveLightingController} = this.hap; const service = this.accessory.getService(Service.Lightbulb); this._checkServiceName(service, this.device.context.name); @@ -48,6 +48,12 @@ class TWLightAccessory extends BaseAccessory { this.characteristicColorTemperature = characteristicColorTemperature; + if (this.adaptiveLightingSupport()) { + this.adaptiveLightingController = new AdaptiveLightingController(service); + this.accessory.configureController(this.adaptiveLightingController); + this.accessory.adaptiveLightingController = this.adaptiveLightingController; + } + this.device.on('change', (changes, state) => { if (changes.hasOwnProperty(this.dpPower) && characteristicOn.value !== changes[this.dpPower]) characteristicOn.updateValue(changes[this.dpPower]);