@switchbot/homebridge-switchbot 3.7.1-beta.17 → 3.7.1-beta.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/device/bot.ts CHANGED
@@ -775,55 +775,78 @@ export class Bot extends deviceBase {
775
775
  * Handle requests to set the "On" characteristic
776
776
  */
777
777
  async OnSet(value: CharacteristicValue): Promise<void> {
778
- if (this.botDeviceType === 'garagedoor') {
779
- this.debugLog(`Set TargetDoorState: ${value}`)
780
- if (value === this.hap.Characteristic.TargetDoorState.CLOSED) {
781
- this.On = false
782
- } else {
783
- this.On = true
784
- }
785
- } else if (
786
- this.botDeviceType === 'door'
787
- || this.botDeviceType === 'window'
788
- || this.botDeviceType === 'windowcovering'
789
- ) {
790
- this.debugLog(`Set TargetPosition: ${value}`)
791
- if (value === 0) {
792
- this.On = false
793
- } else {
794
- this.On = true
795
- }
796
- } else if (this.botDeviceType === 'lock') {
797
- this.debugLog(`Set LockTargetState: ${value}`)
798
- if (value === this.hap.Characteristic.LockTargetState.SECURED) {
799
- this.On = false
800
- } else {
801
- this.On = true
802
- }
803
- } else if (this.botDeviceType === 'faucet') {
804
- this.debugLog(`Set Active: ${value}`)
805
- if (value === this.hap.Characteristic.Active.INACTIVE) {
806
- this.On = false
807
- } else {
808
- this.On = true
809
- }
810
- } else if (this.botDeviceType === 'stateful') {
811
- this.debugLog(`Set ProgrammableSwitchOutputState: ${value}`)
812
- if (value === 0) {
813
- this.On = false
814
- } else {
815
- this.On = true
816
- }
778
+ if (this.On === undefined) {
779
+ this.On = false
780
+ this.accessory.context.On = this.On
817
781
  } else {
818
- this.debugLog(`Set On: ${value}`)
819
- if (this.device.bot?.mode === 'multipress') {
820
- if (value === true) {
782
+ this.On = this.accessory.context.On
783
+ }
784
+
785
+ const deviceTypeActions: { [key: string]: () => Promise<void> } = {
786
+ switch: async () => {
787
+ if (this.Switch) {
788
+ await this.debugLog(`Set On: ${value}`)
789
+ this.On = value !== false
790
+ }
791
+ },
792
+ garagedoor: async () => {
793
+ if (this.GarageDoor) {
794
+ await this.debugLog(`Set TargetDoorState: ${value}`)
795
+ this.On = value !== this.hap.Characteristic.TargetDoorState.CLOSED
796
+ }
797
+ },
798
+ door: async () => {
799
+ if (this.Door) {
800
+ await this.debugLog(`Set TargetPosition: ${value}`)
801
+ this.On = value !== 0
802
+ }
803
+ },
804
+ window: async () => {
805
+ if (this.Window) {
806
+ await this.debugLog(`Set TargetPosition: ${value}`)
807
+ this.On = value !== 0
808
+ }
809
+ },
810
+ windowcovering: async () => {
811
+ if (this.WindowCovering) {
812
+ await this.debugLog(`Set TargetPosition: ${value}`)
813
+ this.On = value !== 0
814
+ }
815
+ },
816
+ lock: async () => {
817
+ if (this.LockMechanism) {
818
+ await this.debugLog(`Set LockTargetState: ${value}`)
819
+ this.On = value !== this.hap.Characteristic.LockTargetState.SECURED
820
+ }
821
+ },
822
+ faucet: async () => {
823
+ if (this.Faucet) {
824
+ await this.debugLog(`Set Active: ${value}`)
825
+ this.On = value !== this.hap.Characteristic.Active.INACTIVE
826
+ }
827
+ },
828
+ stateful: async () => {
829
+ if (this.StatefulProgrammableSwitch) {
830
+ await this.debugLog(`Set ProgrammableSwitchOutputState: ${value}`)
831
+ this.On = value !== 0
832
+ }
833
+ },
834
+ default: async () => {
835
+ if (this.Outlet) {
836
+ await this.debugLog(`Set On: ${value}`)
837
+ this.On = value !== false
838
+ }
839
+ if (this.device.bot?.mode === 'multipress' && this.On) {
821
840
  this.multiPressCount++
822
- this.debugLog(`set to Multi-Press. Multi-Press count: ${this.multiPressCount}`)
841
+ await this.debugLog(`multiPressCount: ${this.multiPressCount}`)
823
842
  }
824
- }
825
- this.On = value as boolean
843
+ },
826
844
  }
845
+
846
+ const action = deviceTypeActions[this.botDeviceType] || deviceTypeActions.default
847
+ await action()
848
+
849
+ this.accessory.context.On = this.On
827
850
  this.doBotUpdate.next()
828
851
  }
829
852
 
package/src/platform.ts CHANGED
@@ -31,7 +31,7 @@ import { queueScheduler } from 'rxjs'
31
31
  import { request } from 'undici'
32
32
 
33
33
  import { BlindTilt } from './device/blindtilt.js'
34
- import { Bot } from './device/bot.js'
34
+ import { Bot } from './device/bot-old.js'
35
35
  import { CeilingLight } from './device/ceilinglight.js'
36
36
  import { ColorBulb } from './device/colorbulb.js'
37
37
  import { Contact } from './device/contact.js'