Skip to content

Commit

Permalink
Added Adaptive Lighting support
Browse files Browse the repository at this point in the history
  • Loading branch information
tom-23 committed Jan 24, 2021
1 parent 15ce9e1 commit 903e517
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 4 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
package-lock.json
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 5 additions & 0 deletions lib/BaseAccessory.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
16 changes: 15 additions & 1 deletion lib/RGBTWLightAccessory.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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]);

Expand Down Expand Up @@ -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;
8 changes: 7 additions & 1 deletion lib/TWLightAccessory.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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]);

Expand Down

0 comments on commit 903e517

Please sign in to comment.