From 24470313ae80c9dfa78bbbcfcfae12c52c03bdef Mon Sep 17 00:00:00 2001 From: Thibaut Mottet Date: Sun, 9 Jul 2023 20:41:50 +0200 Subject: [PATCH 1/3] Add single switch action --- src/platformAccessory.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/platformAccessory.ts b/src/platformAccessory.ts index 4d725c5..f638d8f 100644 --- a/src/platformAccessory.ts +++ b/src/platformAccessory.ts @@ -46,8 +46,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 light (to manage single action switch) + // 1 click = fan on, 1 click again = light 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) => { @@ -111,8 +114,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); From 698cdd6ca159727d24b05610ed6da036d4b24dfe Mon Sep 17 00:00:00 2001 From: Thibaut Mottet Date: Sun, 9 Jul 2023 20:42:04 +0200 Subject: [PATCH 2/3] 0.0.66 --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index a774bd8..0de2b7b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "homebridge-create-ceiling-fan", - "version": "0.0.65", + "version": "0.0.66", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "homebridge-create-ceiling-fan", - "version": "0.0.65", + "version": "0.0.66", "license": "Apache-2.0", "dependencies": { "ts-pattern": "^4.3.0", diff --git a/package.json b/package.json index 628e2c4..724baee 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "private": false, "displayName": "Hombridge Create Ceiling Fan", "name": "homebridge-create-ceiling-fan", - "version": "0.0.65", + "version": "0.0.66", "description": "Free the full potential of your ceiling fan with Homebridge", "license": "Apache-2.0", "repository": { From 0f6d2ffb4028c0426f6d0789c0f37a2ee01b5aa4 Mon Sep 17 00:00:00 2001 From: Thibaut Mottet Date: Sun, 9 Jul 2023 20:58:11 +0200 Subject: [PATCH 3/3] Add single switch action --- src/platformAccessory.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/platformAccessory.ts b/src/platformAccessory.ts index f638d8f..301d51d 100644 --- a/src/platformAccessory.ts +++ b/src/platformAccessory.ts @@ -47,8 +47,8 @@ export class CeilingFanAccessory { this.fanService.getCharacteristic(this.platform.Characteristic.On) .onSet(async (value: CharacteristicValue) => { const receivedValue = value.valueOf() as boolean; - // If we receive the switch on the fan and its already on, we turn off the light (to manage single action switch) - // 1 click = fan on, 1 click again = light off + // 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}); })