Skip to content

Commit

Permalink
Changed dummySwitch to stateful
Browse files Browse the repository at this point in the history
  • Loading branch information
seydx authored Mar 22, 2021
1 parent 00972b2 commit 494e40e
Showing 1 changed file with 26 additions and 11 deletions.
37 changes: 26 additions & 11 deletions src/accessories/switch.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,8 @@ class SwitchAccessory {
serviceSubSwitch = this.accessory.addService(this.api.hap.Service.Switch, sub.name, sub.sub);
}

if(sub.name !== 'Central'){

serviceSubSwitch.getCharacteristic(this.api.hap.Characteristic.On)
.updateValue(false);

} else {

if(sub.name === 'Central') {

//Modes
if(!serviceSubSwitch.testCharacteristic(this.api.hap.Characteristic.AutoThermostats))
serviceSubSwitch.addCharacteristic(this.api.hap.Characteristic.AutoThermostats);
Expand Down Expand Up @@ -181,10 +176,30 @@ class SwitchAccessory {

}

serviceSubSwitch.getCharacteristic(this.api.hap.Characteristic.On)
.onSet(this.deviceHandler.setStates.bind(this, this.accessory, this.accessories, sub.name));

} else if(sub.name === 'Dummy') {

this.accessory.context.dummyState = this.accessory.context.dummyState || false;

serviceSubSwitch.getCharacteristic(this.api.hap.Characteristic.On)
.onGet(() => {
return this.accessory.context.dummyState;
})
.onSet(state => {
Logger.info('Dummy: ' + state, this.accessory.displayName);
this.accessory.context.dummyState = state;
})
.updateValue(this.accessory.context.dummyState);

} else {

serviceSubSwitch.getCharacteristic(this.api.hap.Characteristic.On)
.onSet(this.deviceHandler.setStates.bind(this, this.accessory, this.accessories, sub.name))
.updateValue(false);

}

serviceSubSwitch.getCharacteristic(this.api.hap.Characteristic.On)
.onSet(this.deviceHandler.setStates.bind(this, this.accessory, this.accessories, sub.name));

});

Expand Down Expand Up @@ -243,4 +258,4 @@ class SwitchAccessory {

}

module.exports = SwitchAccessory;
module.exports = SwitchAccessory;

0 comments on commit 494e40e

Please sign in to comment.