Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
# Conflicts:
#	package-lock.json
#	package.json
  • Loading branch information
moifort committed Jul 10, 2023
2 parents 309eadd + 0f6d2ff commit 519c38a
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/platformAccessory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,11 @@ export class CeilingFanAccessory {
// Fan state
this.fanService.getCharacteristic(this.platform.Characteristic.On)
.onSet(async (value: CharacteristicValue) => {
this.state.fanOn = value.valueOf() as boolean;
await device.set({dps: 60, set: value.valueOf() as boolean, shouldWaitForResponse: false});
const receivedValue = value.valueOf() as boolean;
// If we receive the switch on the fan and its already on, we turn off the fan (to manage single action switch)
// 1 click = fan on, 1 click again = fan off
this.state.fanOn = this.state.fanOn && receivedValue ? false : receivedValue;
await device.set({dps: 60, set: this.state.fanOn, shouldWaitForResponse: false});
})
.onGet(() => this.state.fanOn);
const stateHook = (data: DPSObject) => {
Expand Down Expand Up @@ -142,8 +145,11 @@ export class CeilingFanAccessory {
this.lightService.setCharacteristic(this.platform.Characteristic.Name, accessory.context.device.name);
this.lightService.getCharacteristic(this.platform.Characteristic.On)
.onSet(async (value: CharacteristicValue) => {
this.state.lightOn = value.valueOf() as boolean;
await device.set({dps: 20, set: value.valueOf() as boolean, shouldWaitForResponse: false});
const receivedValue = value.valueOf() as boolean;
// If we receive the switch on the fan, we need to turn off the light (to manage single action switch)
// 1 click = fan on, 1 click again = light off
this.state.lightOn = this.state.lightOn && receivedValue ? false : receivedValue;
await device.set({dps: 20, set: this.state.lightOn, shouldWaitForResponse: false});
await device.refresh({});
})
.onGet(() => this.state.lightOn);
Expand Down

0 comments on commit 519c38a

Please sign in to comment.