@switchbot/homebridge-switchbot 2.14.0 → 3.0.0-beta.0

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.
Files changed (154) hide show
  1. package/.github/npm-version-script.cjs +81 -0
  2. package/.github/workflows/dependabot.yml +10 -11
  3. package/CHANGELOG.md +11 -2
  4. package/LICENSE +1 -1
  5. package/config.schema.json +1 -0
  6. package/dist/device/blindtilt.d.ts +9 -5
  7. package/dist/device/blindtilt.d.ts.map +1 -1
  8. package/dist/device/blindtilt.js +151 -91
  9. package/dist/device/blindtilt.js.map +1 -1
  10. package/dist/device/bot.d.ts +9 -5
  11. package/dist/device/bot.d.ts.map +1 -1
  12. package/dist/device/bot.js +234 -184
  13. package/dist/device/bot.js.map +1 -1
  14. package/dist/device/ceilinglight.d.ts +9 -5
  15. package/dist/device/ceilinglight.d.ts.map +1 -1
  16. package/dist/device/ceilinglight.js +110 -64
  17. package/dist/device/ceilinglight.js.map +1 -1
  18. package/dist/device/colorbulb.d.ts +9 -5
  19. package/dist/device/colorbulb.d.ts.map +1 -1
  20. package/dist/device/colorbulb.js +121 -69
  21. package/dist/device/colorbulb.js.map +1 -1
  22. package/dist/device/contact.d.ts +9 -5
  23. package/dist/device/contact.d.ts.map +1 -1
  24. package/dist/device/contact.js +111 -66
  25. package/dist/device/contact.js.map +1 -1
  26. package/dist/device/curtain.d.ts +9 -5
  27. package/dist/device/curtain.d.ts.map +1 -1
  28. package/dist/device/curtain.js +164 -107
  29. package/dist/device/curtain.js.map +1 -1
  30. package/dist/device/hub.d.ts +9 -5
  31. package/dist/device/hub.d.ts.map +1 -1
  32. package/dist/device/hub.js +87 -51
  33. package/dist/device/hub.js.map +1 -1
  34. package/dist/device/humidifier.d.ts +9 -5
  35. package/dist/device/humidifier.d.ts.map +1 -1
  36. package/dist/device/humidifier.js +133 -90
  37. package/dist/device/humidifier.js.map +1 -1
  38. package/dist/device/iosensor.d.ts +9 -5
  39. package/dist/device/iosensor.d.ts.map +1 -1
  40. package/dist/device/iosensor.js +108 -66
  41. package/dist/device/iosensor.js.map +1 -1
  42. package/dist/device/lightstrip.d.ts +9 -5
  43. package/dist/device/lightstrip.d.ts.map +1 -1
  44. package/dist/device/lightstrip.js +110 -65
  45. package/dist/device/lightstrip.js.map +1 -1
  46. package/dist/device/lock.d.ts +10 -6
  47. package/dist/device/lock.d.ts.map +1 -1
  48. package/dist/device/lock.js +125 -84
  49. package/dist/device/lock.js.map +1 -1
  50. package/dist/device/meter.d.ts +9 -5
  51. package/dist/device/meter.d.ts.map +1 -1
  52. package/dist/device/meter.js +102 -63
  53. package/dist/device/meter.js.map +1 -1
  54. package/dist/device/meterplus.d.ts +9 -5
  55. package/dist/device/meterplus.d.ts.map +1 -1
  56. package/dist/device/meterplus.js +102 -63
  57. package/dist/device/meterplus.js.map +1 -1
  58. package/dist/device/motion.d.ts +9 -5
  59. package/dist/device/motion.d.ts.map +1 -1
  60. package/dist/device/motion.js +95 -54
  61. package/dist/device/motion.js.map +1 -1
  62. package/dist/device/plug.d.ts +9 -5
  63. package/dist/device/plug.d.ts.map +1 -1
  64. package/dist/device/plug.js +68 -40
  65. package/dist/device/plug.js.map +1 -1
  66. package/dist/device/robotvacuumcleaner.d.ts +9 -5
  67. package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
  68. package/dist/device/robotvacuumcleaner.js +86 -52
  69. package/dist/device/robotvacuumcleaner.js.map +1 -1
  70. package/dist/homebridge-ui/server.d.ts +2 -0
  71. package/dist/homebridge-ui/server.d.ts.map +1 -0
  72. package/dist/homebridge-ui/server.js +44 -0
  73. package/dist/homebridge-ui/server.js.map +1 -0
  74. package/dist/index.d.ts +1 -4
  75. package/dist/index.d.ts.map +1 -1
  76. package/dist/index.js +9 -5
  77. package/dist/index.js.map +1 -1
  78. package/dist/irdevice/airconditioner.d.ts +8 -4
  79. package/dist/irdevice/airconditioner.d.ts.map +1 -1
  80. package/dist/irdevice/airconditioner.js +105 -71
  81. package/dist/irdevice/airconditioner.js.map +1 -1
  82. package/dist/irdevice/airpurifier.d.ts +8 -4
  83. package/dist/irdevice/airpurifier.d.ts.map +1 -1
  84. package/dist/irdevice/airpurifier.js +78 -46
  85. package/dist/irdevice/airpurifier.js.map +1 -1
  86. package/dist/irdevice/camera.d.ts +8 -4
  87. package/dist/irdevice/camera.d.ts.map +1 -1
  88. package/dist/irdevice/camera.js +41 -25
  89. package/dist/irdevice/camera.js.map +1 -1
  90. package/dist/irdevice/fan.d.ts +8 -4
  91. package/dist/irdevice/fan.d.ts.map +1 -1
  92. package/dist/irdevice/fan.js +62 -39
  93. package/dist/irdevice/fan.js.map +1 -1
  94. package/dist/irdevice/light.d.ts +8 -4
  95. package/dist/irdevice/light.d.ts.map +1 -1
  96. package/dist/irdevice/light.js +67 -45
  97. package/dist/irdevice/light.js.map +1 -1
  98. package/dist/irdevice/other.d.ts +8 -4
  99. package/dist/irdevice/other.d.ts.map +1 -1
  100. package/dist/irdevice/other.js +176 -150
  101. package/dist/irdevice/other.js.map +1 -1
  102. package/dist/irdevice/tv.d.ts +8 -4
  103. package/dist/irdevice/tv.d.ts.map +1 -1
  104. package/dist/irdevice/tv.js +81 -62
  105. package/dist/irdevice/tv.js.map +1 -1
  106. package/dist/irdevice/vacuumcleaner.d.ts +8 -4
  107. package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
  108. package/dist/irdevice/vacuumcleaner.js +41 -25
  109. package/dist/irdevice/vacuumcleaner.js.map +1 -1
  110. package/dist/irdevice/waterheater.d.ts +8 -4
  111. package/dist/irdevice/waterheater.d.ts.map +1 -1
  112. package/dist/irdevice/waterheater.js +48 -32
  113. package/dist/irdevice/waterheater.js.map +1 -1
  114. package/dist/platform.d.ts +8 -9
  115. package/dist/platform.d.ts.map +1 -1
  116. package/dist/platform.js +147 -162
  117. package/dist/platform.js.map +1 -1
  118. package/dist/settings.js +7 -14
  119. package/dist/settings.js.map +1 -1
  120. package/dist/utils.js +1 -5
  121. package/dist/utils.js.map +1 -1
  122. package/package.json +28 -16
  123. package/src/device/blindtilt.ts +80 -69
  124. package/src/device/bot.ts +189 -178
  125. package/src/device/ceilinglight.ts +55 -42
  126. package/src/device/colorbulb.ts +51 -38
  127. package/src/device/contact.ts +69 -58
  128. package/src/device/curtain.ts +94 -83
  129. package/src/device/hub.ts +54 -43
  130. package/src/device/humidifier.ts +86 -75
  131. package/src/device/iosensor.ts +63 -52
  132. package/src/device/lightstrip.ts +54 -41
  133. package/src/device/lock.ts +89 -79
  134. package/src/device/meter.ts +59 -48
  135. package/src/device/meterplus.ts +63 -52
  136. package/src/device/motion.ts +56 -45
  137. package/src/device/plug.ts +36 -25
  138. package/src/device/robotvacuumcleaner.ts +47 -36
  139. package/src/homebridge-ui/public/index.html +240 -0
  140. package/src/homebridge-ui/server.ts +48 -0
  141. package/src/index.ts +10 -7
  142. package/src/irdevice/airconditioner.ts +70 -62
  143. package/src/irdevice/airpurifier.ts +47 -39
  144. package/src/irdevice/camera.ts +27 -19
  145. package/src/irdevice/fan.ts +41 -33
  146. package/src/irdevice/light.ts +47 -39
  147. package/src/irdevice/other.ts +163 -155
  148. package/src/irdevice/tv.ts +65 -57
  149. package/src/irdevice/vacuumcleaner.ts +27 -19
  150. package/src/irdevice/waterheater.ts +34 -26
  151. package/src/platform.ts +35 -21
  152. package/tsconfig.json +11 -13
  153. package/homebridge-ui/server.js +0 -50
  154. /package/{homebridge-ui → dist/homebridge-ui}/public/index.html +0 -0
@@ -1,7 +1,7 @@
1
- import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
1
+ import { CharacteristicValue, PlatformAccessory, Service, API, Logging, HAP } from 'homebridge';
2
2
  import { request } from 'undici';
3
3
  import { SwitchBotPlatform } from '../platform';
4
- import { Devices, irDevicesConfig, irdevice } from '../settings';
4
+ import { Devices, irDevicesConfig, irdevice, SwitchBotPlatformConfig } from '../settings';
5
5
 
6
6
  /**
7
7
  * Platform Accessory
@@ -9,6 +9,10 @@ import { Devices, irDevicesConfig, irdevice } from '../settings';
9
9
  * Each accessory may expose multiple services of different service types.
10
10
  */
11
11
  export class TV {
12
+ public readonly api: API;
13
+ public readonly log: Logging;
14
+ public readonly config!: SwitchBotPlatformConfig;
15
+ protected readonly hap: HAP;
12
16
  // Services
13
17
  tvService!: Service;
14
18
  speakerService: Service;
@@ -29,22 +33,26 @@ export class TV {
29
33
  private accessory: PlatformAccessory,
30
34
  public device: irdevice & irDevicesConfig,
31
35
  ) {
36
+ this.api = this.platform.api;
37
+ this.log = this.platform.log;
38
+ this.config = this.platform.config;
39
+ this.hap = this.api.hap;
32
40
  // default placeholders
33
- this.logs(device);
41
+ this.deviceLogs(device);
34
42
  this.context();
35
43
  this.disablePushOnChanges(device);
36
44
  this.disablePushOffChanges(device);
37
45
  this.disablePushDetailChanges(device);
38
- this.config(device);
46
+ this.deviceConfig(device);
39
47
 
40
48
  // set accessory information
41
49
  accessory
42
- .getService(this.platform.Service.AccessoryInformation)!
43
- .setCharacteristic(this.platform.Characteristic.Name, `${device.deviceName} ${device.remoteType}`)
44
- .setCharacteristic(this.platform.Characteristic.Manufacturer, 'SwitchBot')
45
- .setCharacteristic(this.platform.Characteristic.Model, device.remoteType)
46
- .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId)
47
- .setCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision);
50
+ .getService(this.hap.Service.AccessoryInformation)!
51
+ .setCharacteristic(this.hap.Characteristic.Name, `${device.deviceName} ${device.remoteType}`)
52
+ .setCharacteristic(this.hap.Characteristic.Manufacturer, 'SwitchBot')
53
+ .setCharacteristic(this.hap.Characteristic.Model, device.remoteType)
54
+ .setCharacteristic(this.hap.Characteristic.SerialNumber, device.deviceId)
55
+ .setCharacteristic(this.hap.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision);
48
56
 
49
57
  // set the accessory category
50
58
  const tvServiceCategory = `${accessory.displayName} ${device.remoteType}`;
@@ -52,74 +60,74 @@ export class TV {
52
60
  case 'Speaker':
53
61
  case 'DIY Speaker':
54
62
  accessory.category = this.platform.api.hap.Categories.SPEAKER;
55
- (this.tvService = accessory.getService(this.platform.Service.Television)
56
- || accessory.addService(this.platform.Service.Television)), tvServiceCategory;
63
+ (this.tvService = accessory.getService(this.hap.Service.Television)
64
+ || accessory.addService(this.hap.Service.Television)), tvServiceCategory;
57
65
  break;
58
66
  case 'IPTV':
59
67
  case 'DIY IPTV':
60
68
  accessory.category = this.platform.api.hap.Categories.TV_STREAMING_STICK;
61
- (this.tvService = accessory.getService(this.platform.Service.Television)
62
- || accessory.addService(this.platform.Service.Television)), tvServiceCategory;
69
+ (this.tvService = accessory.getService(this.hap.Service.Television)
70
+ || accessory.addService(this.hap.Service.Television)), tvServiceCategory;
63
71
  break;
64
72
  case 'DVD':
65
73
  case 'DIY DVD':
66
74
  case 'Set Top Box':
67
75
  case 'DIY Set Top Box':
68
76
  accessory.category = this.platform.api.hap.Categories.TV_SET_TOP_BOX;
69
- (this.tvService = accessory.getService(this.platform.Service.Television)
70
- || accessory.addService(this.platform.Service.Television)), tvServiceCategory;
77
+ (this.tvService = accessory.getService(this.hap.Service.Television)
78
+ || accessory.addService(this.hap.Service.Television)), tvServiceCategory;
71
79
  break;
72
80
  default:
73
81
  accessory.category = this.platform.api.hap.Categories.TELEVISION;
74
82
 
75
83
  // get the Television service if it exists, otherwise create a new Television service
76
84
  // you can create multiple services for each accessory
77
- (this.tvService = accessory.getService(this.platform.Service.Television)
78
- || accessory.addService(this.platform.Service.Television)), tvServiceCategory;
85
+ (this.tvService = accessory.getService(this.hap.Service.Television)
86
+ || accessory.addService(this.hap.Service.Television)), tvServiceCategory;
79
87
  }
80
88
 
81
- this.tvService.getCharacteristic(this.platform.Characteristic.ConfiguredName);
89
+ this.tvService.getCharacteristic(this.hap.Characteristic.ConfiguredName);
82
90
 
83
91
  // set sleep discovery characteristic
84
92
  this.tvService.setCharacteristic(
85
- this.platform.Characteristic.SleepDiscoveryMode,
86
- this.platform.Characteristic.SleepDiscoveryMode.ALWAYS_DISCOVERABLE,
93
+ this.hap.Characteristic.SleepDiscoveryMode,
94
+ this.hap.Characteristic.SleepDiscoveryMode.ALWAYS_DISCOVERABLE,
87
95
  );
88
96
 
89
97
  // handle on / off events using the Active characteristic
90
- this.tvService.getCharacteristic(this.platform.Characteristic.Active).onSet(this.ActiveSet.bind(this));
98
+ this.tvService.getCharacteristic(this.hap.Characteristic.Active).onSet(this.ActiveSet.bind(this));
91
99
 
92
- this.tvService.setCharacteristic(this.platform.Characteristic.ActiveIdentifier, 1);
100
+ this.tvService.setCharacteristic(this.hap.Characteristic.ActiveIdentifier, 1);
93
101
 
94
102
  // handle input source changes
95
- this.tvService.getCharacteristic(this.platform.Characteristic.ActiveIdentifier).onSet(this.ActiveIdentifierSet.bind(this));
103
+ this.tvService.getCharacteristic(this.hap.Characteristic.ActiveIdentifier).onSet(this.ActiveIdentifierSet.bind(this));
96
104
 
97
105
  // handle remote control input
98
- this.tvService.getCharacteristic(this.platform.Characteristic.RemoteKey).onSet(this.RemoteKeySet.bind(this));
106
+ this.tvService.getCharacteristic(this.hap.Characteristic.RemoteKey).onSet(this.RemoteKeySet.bind(this));
99
107
 
100
108
  /**
101
109
  * Create a speaker service to allow volume control
102
110
  */
103
111
  // create a new Television Speaker service
104
112
  const speakerService = `${accessory.displayName} Speaker`;
105
- (this.speakerService = accessory.getService(this.platform.Service.TelevisionSpeaker)
106
- || accessory.addService(this.platform.Service.TelevisionSpeaker)), speakerService;
113
+ (this.speakerService = accessory.getService(this.hap.Service.TelevisionSpeaker)
114
+ || accessory.addService(this.hap.Service.TelevisionSpeaker)), speakerService;
107
115
 
108
- this.speakerService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Speaker`);
109
- if (!this.speakerService.testCharacteristic(this.platform.Characteristic.ConfiguredName)) {
110
- this.speakerService.addCharacteristic(this.platform.Characteristic.ConfiguredName, `${accessory.displayName} Speaker`);
116
+ this.speakerService.setCharacteristic(this.hap.Characteristic.Name, `${accessory.displayName} Speaker`);
117
+ if (!this.speakerService.testCharacteristic(this.hap.Characteristic.ConfiguredName)) {
118
+ this.speakerService.addCharacteristic(this.hap.Characteristic.ConfiguredName, `${accessory.displayName} Speaker`);
111
119
  }
112
120
  this.speakerService
113
- .setCharacteristic(this.platform.Characteristic.Active, this.platform.Characteristic.Active.ACTIVE)
114
- .setCharacteristic(this.platform.Characteristic.VolumeControlType, this.platform.Characteristic.VolumeControlType.ABSOLUTE);
121
+ .setCharacteristic(this.hap.Characteristic.Active, this.hap.Characteristic.Active.ACTIVE)
122
+ .setCharacteristic(this.hap.Characteristic.VolumeControlType, this.hap.Characteristic.VolumeControlType.ABSOLUTE);
115
123
 
116
124
  // handle volume control
117
- this.speakerService.getCharacteristic(this.platform.Characteristic.VolumeSelector).onSet(this.VolumeSelectorSet.bind(this));
125
+ this.speakerService.getCharacteristic(this.hap.Characteristic.VolumeSelector).onSet(this.VolumeSelectorSet.bind(this));
118
126
  }
119
127
 
120
128
  async VolumeSelectorSet(value: CharacteristicValue): Promise<void> {
121
129
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} VolumeSelector: ${value}`);
122
- if (value === this.platform.Characteristic.VolumeSelector.INCREMENT) {
130
+ if (value === this.hap.Characteristic.VolumeSelector.INCREMENT) {
123
131
  this.pushVolumeUpChanges();
124
132
  } else {
125
133
  this.pushVolumeDownChanges();
@@ -128,61 +136,61 @@ export class TV {
128
136
 
129
137
  async RemoteKeySet(value: CharacteristicValue): Promise<void> {
130
138
  switch (value) {
131
- case this.platform.Characteristic.RemoteKey.REWIND: {
139
+ case this.hap.Characteristic.RemoteKey.REWIND: {
132
140
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Set Remote Key Pressed: REWIND`);
133
141
  break;
134
142
  }
135
- case this.platform.Characteristic.RemoteKey.FAST_FORWARD: {
143
+ case this.hap.Characteristic.RemoteKey.FAST_FORWARD: {
136
144
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Set Remote Key Pressed: FAST_FORWARD`);
137
145
  break;
138
146
  }
139
- case this.platform.Characteristic.RemoteKey.NEXT_TRACK: {
147
+ case this.hap.Characteristic.RemoteKey.NEXT_TRACK: {
140
148
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Set Remote Key Pressed: NEXT_TRACK`);
141
149
  break;
142
150
  }
143
- case this.platform.Characteristic.RemoteKey.PREVIOUS_TRACK: {
151
+ case this.hap.Characteristic.RemoteKey.PREVIOUS_TRACK: {
144
152
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Set Remote Key Pressed: PREVIOUS_TRACK`);
145
153
  break;
146
154
  }
147
- case this.platform.Characteristic.RemoteKey.ARROW_UP: {
155
+ case this.hap.Characteristic.RemoteKey.ARROW_UP: {
148
156
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Set Remote Key Pressed: ARROW_UP`);
149
157
  //this.pushUpChanges();
150
158
  break;
151
159
  }
152
- case this.platform.Characteristic.RemoteKey.ARROW_DOWN: {
160
+ case this.hap.Characteristic.RemoteKey.ARROW_DOWN: {
153
161
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Set Remote Key Pressed: ARROW_DOWN`);
154
162
  //this.pushDownChanges();
155
163
  break;
156
164
  }
157
- case this.platform.Characteristic.RemoteKey.ARROW_LEFT: {
165
+ case this.hap.Characteristic.RemoteKey.ARROW_LEFT: {
158
166
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Set Remote Key Pressed: ARROW_LEFT`);
159
167
  //this.pushLeftChanges();
160
168
  break;
161
169
  }
162
- case this.platform.Characteristic.RemoteKey.ARROW_RIGHT: {
170
+ case this.hap.Characteristic.RemoteKey.ARROW_RIGHT: {
163
171
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Set Remote Key Pressed: ARROW_RIGHT`);
164
172
  //this.pushRightChanges();
165
173
  break;
166
174
  }
167
- case this.platform.Characteristic.RemoteKey.SELECT: {
175
+ case this.hap.Characteristic.RemoteKey.SELECT: {
168
176
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Set Remote Key Pressed: SELECT`);
169
177
  //this.pushOkChanges();
170
178
  break;
171
179
  }
172
- case this.platform.Characteristic.RemoteKey.BACK: {
180
+ case this.hap.Characteristic.RemoteKey.BACK: {
173
181
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Set Remote Key Pressed: BACK`);
174
182
  //this.pushBackChanges();
175
183
  break;
176
184
  }
177
- case this.platform.Characteristic.RemoteKey.EXIT: {
185
+ case this.hap.Characteristic.RemoteKey.EXIT: {
178
186
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Set Remote Key Pressed: EXIT`);
179
187
  break;
180
188
  }
181
- case this.platform.Characteristic.RemoteKey.PLAY_PAUSE: {
189
+ case this.hap.Characteristic.RemoteKey.PLAY_PAUSE: {
182
190
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Set Remote Key Pressed: PLAY_PAUSE`);
183
191
  break;
184
192
  }
185
- case this.platform.Characteristic.RemoteKey.INFORMATION: {
193
+ case this.hap.Characteristic.RemoteKey.INFORMATION: {
186
194
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Set Remote Key Pressed: INFORMATION`);
187
195
  //this.pushMenuChanges();
188
196
  break;
@@ -199,7 +207,7 @@ export class TV {
199
207
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Active (value): ${value}`);
200
208
 
201
209
  this.Active = value;
202
- if (this.Active === this.platform.Characteristic.Active.ACTIVE) {
210
+ if (this.Active === this.hap.Characteristic.Active.ACTIVE) {
203
211
  await this.pushTvOnChanges();
204
212
  } else {
205
213
  await this.pushTvOffChanges();
@@ -220,7 +228,7 @@ export class TV {
220
228
  this.debugLog(
221
229
  `${this.device.remoteType}: ${this.accessory.displayName} pushTvOnChanges Active: ${this.Active},` + ` disablePushOn: ${this.disablePushOn}`,
222
230
  );
223
- if (this.Active === this.platform.Characteristic.Active.ACTIVE && !this.disablePushOn) {
231
+ if (this.Active === this.hap.Characteristic.Active.ACTIVE && !this.disablePushOn) {
224
232
  const commandType: string = await this.commandType();
225
233
  const command: string = await this.commandOn();
226
234
  const bodyChange = JSON.stringify({
@@ -236,7 +244,7 @@ export class TV {
236
244
  this.debugLog(
237
245
  `${this.device.remoteType}: ${this.accessory.displayName} pushTvOffChanges Active: ${this.Active},` + ` disablePushOff: ${this.disablePushOff}`,
238
246
  );
239
- if (this.Active === this.platform.Characteristic.Active.INACTIVE && !this.disablePushOff) {
247
+ if (this.Active === this.hap.Characteristic.Active.INACTIVE && !this.disablePushOff) {
240
248
  const commandType: string = await this.commandType();
241
249
  const command: string = await this.commandOff();
242
250
  const bodyChange = JSON.stringify({
@@ -402,7 +410,7 @@ export class TV {
402
410
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Active: ${this.Active}`);
403
411
  } else {
404
412
  this.accessory.context.Active = this.Active;
405
- this.tvService?.updateCharacteristic(this.platform.Characteristic.Active, this.Active);
413
+ this.tvService?.updateCharacteristic(this.hap.Characteristic.Active, this.Active);
406
414
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic Active: ${this.Active}`);
407
415
  }
408
416
  // ActiveIdentifier
@@ -410,7 +418,7 @@ export class TV {
410
418
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} ActiveIdentifier: ${this.ActiveIdentifier}`);
411
419
  } else {
412
420
  this.accessory.context.ActiveIdentifier = this.ActiveIdentifier;
413
- this.tvService?.updateCharacteristic(this.platform.Characteristic.ActiveIdentifier, this.ActiveIdentifier);
421
+ this.tvService?.updateCharacteristic(this.hap.Characteristic.ActiveIdentifier, this.ActiveIdentifier);
414
422
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName}` + ` updateCharacteristic ActiveIdentifier: ${this.ActiveIdentifier}`);
415
423
  }
416
424
  }
@@ -510,13 +518,13 @@ export class TV {
510
518
  }
511
519
 
512
520
  async apiError(e: any): Promise<void> {
513
- this.tvService.updateCharacteristic(this.platform.Characteristic.Active, e);
514
- this.tvService.updateCharacteristic(this.platform.Characteristic.ActiveIdentifier, e);
521
+ this.tvService.updateCharacteristic(this.hap.Characteristic.Active, e);
522
+ this.tvService.updateCharacteristic(this.hap.Characteristic.ActiveIdentifier, e);
515
523
  }
516
524
 
517
525
  async context() {
518
526
  if (this.Active === undefined) {
519
- this.Active = this.platform.Characteristic.Active.INACTIVE;
527
+ this.Active = this.hap.Characteristic.Active.INACTIVE;
520
528
  } else {
521
529
  this.Active = this.accessory.context.Active;
522
530
  }
@@ -531,7 +539,7 @@ export class TV {
531
539
  }
532
540
  }
533
541
 
534
- async config(device: irdevice & irDevicesConfig): Promise<void> {
542
+ async deviceConfig(device: irdevice & irDevicesConfig): Promise<void> {
535
543
  let config = {};
536
544
  if (device.irtv) {
537
545
  config = device.irtv;
@@ -568,7 +576,7 @@ export class TV {
568
576
  }
569
577
  }
570
578
 
571
- async logs(device: irdevice & irDevicesConfig): Promise<void> {
579
+ async deviceLogs(device: irdevice & irDevicesConfig): Promise<void> {
572
580
  if (this.platform.debugMode) {
573
581
  this.deviceLogging = this.accessory.context.logging = 'debugMode';
574
582
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
@@ -1,7 +1,7 @@
1
- import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
1
+ import { CharacteristicValue, PlatformAccessory, Service, API, Logging, HAP } from 'homebridge';
2
2
  import { request } from 'undici';
3
3
  import { SwitchBotPlatform } from '../platform';
4
- import { Devices, irDevicesConfig, irdevice } from '../settings';
4
+ import { Devices, irDevicesConfig, irdevice, SwitchBotPlatformConfig } from '../settings';
5
5
 
6
6
  /**
7
7
  * Platform Accessory
@@ -9,6 +9,10 @@ import { Devices, irDevicesConfig, irdevice } from '../settings';
9
9
  * Each accessory may expose multiple services of different service types.
10
10
  */
11
11
  export class VacuumCleaner {
12
+ public readonly api: API;
13
+ public readonly log: Logging;
14
+ public readonly config!: SwitchBotPlatformConfig;
15
+ protected readonly hap: HAP;
12
16
  // Services
13
17
  switchService!: Service;
14
18
 
@@ -26,34 +30,38 @@ export class VacuumCleaner {
26
30
  private accessory: PlatformAccessory,
27
31
  public device: irdevice & irDevicesConfig,
28
32
  ) {
33
+ this.api = this.platform.api;
34
+ this.log = this.platform.log;
35
+ this.config = this.platform.config;
36
+ this.hap = this.api.hap;
29
37
  // default placeholders
30
- this.logs(device);
38
+ this.deviceLogs(device);
31
39
  this.context();
32
40
  this.disablePushOnChanges(device);
33
41
  this.disablePushOffChanges(device);
34
- this.config(device);
42
+ this.deviceConfig(device);
35
43
 
36
44
  // set accessory information
37
45
  accessory
38
- .getService(this.platform.Service.AccessoryInformation)!
39
- .setCharacteristic(this.platform.Characteristic.Manufacturer, 'SwitchBot')
40
- .setCharacteristic(this.platform.Characteristic.Model, device.remoteType)
41
- .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId)
42
- .setCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision);
46
+ .getService(this.hap.Service.AccessoryInformation)!
47
+ .setCharacteristic(this.hap.Characteristic.Manufacturer, 'SwitchBot')
48
+ .setCharacteristic(this.hap.Characteristic.Model, device.remoteType)
49
+ .setCharacteristic(this.hap.Characteristic.SerialNumber, device.deviceId)
50
+ .setCharacteristic(this.hap.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision);
43
51
 
44
52
  // get the Television service if it exists, otherwise create a new Television service
45
53
  // you can create multiple services for each accessory
46
54
  const switchService = `${accessory.displayName} ${device.remoteType}`;
47
- (this.switchService = accessory.getService(this.platform.Service.Switch)
48
- || accessory.addService(this.platform.Service.Switch)), switchService;
55
+ (this.switchService = accessory.getService(this.hap.Service.Switch)
56
+ || accessory.addService(this.hap.Service.Switch)), switchService;
49
57
 
50
- this.switchService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
51
- if (!this.switchService.testCharacteristic(this.platform.Characteristic.ConfiguredName)) {
52
- this.switchService.addCharacteristic(this.platform.Characteristic.ConfiguredName, accessory.displayName);
58
+ this.switchService.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
59
+ if (!this.switchService.testCharacteristic(this.hap.Characteristic.ConfiguredName)) {
60
+ this.switchService.addCharacteristic(this.hap.Characteristic.ConfiguredName, accessory.displayName);
53
61
  }
54
62
 
55
63
  // handle on / off events using the On characteristic
56
- this.switchService.getCharacteristic(this.platform.Characteristic.On).onSet(this.OnSet.bind(this));
64
+ this.switchService.getCharacteristic(this.hap.Characteristic.On).onSet(this.OnSet.bind(this));
57
65
  }
58
66
 
59
67
  async OnSet(value: CharacteristicValue): Promise<void> {
@@ -149,7 +157,7 @@ export class VacuumCleaner {
149
157
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${this.On}`);
150
158
  } else {
151
159
  this.accessory.context.On = this.On;
152
- this.switchService?.updateCharacteristic(this.platform.Characteristic.On, this.On);
160
+ this.switchService?.updateCharacteristic(this.hap.Characteristic.On, this.On);
153
161
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`);
154
162
  }
155
163
  }
@@ -241,7 +249,7 @@ export class VacuumCleaner {
241
249
  }
242
250
 
243
251
  async apiError(e: any): Promise<void> {
244
- this.switchService.updateCharacteristic(this.platform.Characteristic.On, e);
252
+ this.switchService.updateCharacteristic(this.hap.Characteristic.On, e);
245
253
  }
246
254
 
247
255
  async context() {
@@ -256,7 +264,7 @@ export class VacuumCleaner {
256
264
  }
257
265
  }
258
266
 
259
- async config(device: irdevice & irDevicesConfig): Promise<void> {
267
+ async deviceConfig(device: irdevice & irDevicesConfig): Promise<void> {
260
268
  let config = {};
261
269
  if (device.irvc) {
262
270
  config = device.irvc;
@@ -290,7 +298,7 @@ export class VacuumCleaner {
290
298
  }
291
299
  }
292
300
 
293
- async logs(device: irdevice & irDevicesConfig): Promise<void> {
301
+ async deviceLogs(device: irdevice & irDevicesConfig): Promise<void> {
294
302
  if (this.platform.debugMode) {
295
303
  this.deviceLogging = this.accessory.context.logging = 'debugMode';
296
304
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
@@ -1,7 +1,7 @@
1
- import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
1
+ import { CharacteristicValue, PlatformAccessory, Service, API, Logging, HAP } from 'homebridge';
2
2
  import { request } from 'undici';
3
3
  import { SwitchBotPlatform } from '../platform';
4
- import { Devices, irDevicesConfig, irdevice } from '../settings';
4
+ import { Devices, irDevicesConfig, irdevice, SwitchBotPlatformConfig } from '../settings';
5
5
 
6
6
  /**
7
7
  * Platform Accessory
@@ -9,6 +9,10 @@ import { Devices, irDevicesConfig, irdevice } from '../settings';
9
9
  * Each accessory may expose multiple services of different service types.
10
10
  */
11
11
  export class WaterHeater {
12
+ public readonly api: API;
13
+ public readonly log: Logging;
14
+ public readonly config!: SwitchBotPlatformConfig;
15
+ protected readonly hap: HAP;
12
16
  // Services
13
17
  valveService!: Service;
14
18
 
@@ -26,49 +30,53 @@ export class WaterHeater {
26
30
  private accessory: PlatformAccessory,
27
31
  public device: irdevice & irDevicesConfig,
28
32
  ) {
33
+ this.api = this.platform.api;
34
+ this.log = this.platform.log;
35
+ this.config = this.platform.config;
36
+ this.hap = this.api.hap;
29
37
  // default placeholders
30
- this.logs(device);
38
+ this.deviceLogs(device);
31
39
  this.context();
32
40
  this.disablePushOnChanges(device);
33
41
  this.disablePushOffChanges(device);
34
- this.config(device);
42
+ this.deviceConfig(device);
35
43
 
36
44
  // set accessory information
37
45
  accessory
38
- .getService(this.platform.Service.AccessoryInformation)!
39
- .setCharacteristic(this.platform.Characteristic.Manufacturer, 'SwitchBot')
40
- .setCharacteristic(this.platform.Characteristic.Model, device.remoteType)
41
- .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId)
42
- .setCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision);
46
+ .getService(this.hap.Service.AccessoryInformation)!
47
+ .setCharacteristic(this.hap.Characteristic.Manufacturer, 'SwitchBot')
48
+ .setCharacteristic(this.hap.Characteristic.Model, device.remoteType)
49
+ .setCharacteristic(this.hap.Characteristic.SerialNumber, device.deviceId)
50
+ .setCharacteristic(this.hap.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision);
43
51
 
44
52
  // get the Television service if it exists, otherwise create a new Television service
45
53
  // you can create multiple services for each accessory
46
54
  const valveService = `${accessory.displayName} ${device.remoteType}`;
47
- (this.valveService = accessory.getService(this.platform.Service.Valve)
48
- || accessory.addService(this.platform.Service.Valve)), valveService;
55
+ (this.valveService = accessory.getService(this.hap.Service.Valve)
56
+ || accessory.addService(this.hap.Service.Valve)), valveService;
49
57
 
50
- this.valveService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
51
- if (!this.valveService.testCharacteristic(this.platform.Characteristic.ConfiguredName)) {
52
- this.valveService.addCharacteristic(this.platform.Characteristic.ConfiguredName, accessory.displayName);
58
+ this.valveService.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
59
+ if (!this.valveService.testCharacteristic(this.hap.Characteristic.ConfiguredName)) {
60
+ this.valveService.addCharacteristic(this.hap.Characteristic.ConfiguredName, accessory.displayName);
53
61
  }
54
62
 
55
63
  // set sleep discovery characteristic
56
- this.valveService.setCharacteristic(this.platform.Characteristic.ValveType, this.platform.Characteristic.ValveType.GENERIC_VALVE);
64
+ this.valveService.setCharacteristic(this.hap.Characteristic.ValveType, this.hap.Characteristic.ValveType.GENERIC_VALVE);
57
65
 
58
66
  // handle on / off events using the Active characteristic
59
- this.valveService.getCharacteristic(this.platform.Characteristic.Active).onSet(this.ActiveSet.bind(this));
67
+ this.valveService.getCharacteristic(this.hap.Characteristic.Active).onSet(this.ActiveSet.bind(this));
60
68
  }
61
69
 
62
70
  async ActiveSet(value: CharacteristicValue): Promise<void> {
63
71
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Active: ${value}`);
64
72
 
65
73
  this.Active = value;
66
- if (this.Active === this.platform.Characteristic.Active.ACTIVE) {
74
+ if (this.Active === this.hap.Characteristic.Active.ACTIVE) {
67
75
  await this.pushWaterHeaterOnChanges();
68
- this.valveService.setCharacteristic(this.platform.Characteristic.InUse, this.platform.Characteristic.InUse.IN_USE);
76
+ this.valveService.setCharacteristic(this.hap.Characteristic.InUse, this.hap.Characteristic.InUse.IN_USE);
69
77
  } else {
70
78
  await this.pushWaterHeaterOffChanges();
71
- this.valveService.setCharacteristic(this.platform.Characteristic.InUse, this.platform.Characteristic.InUse.NOT_IN_USE);
79
+ this.valveService.setCharacteristic(this.hap.Characteristic.InUse, this.hap.Characteristic.InUse.NOT_IN_USE);
72
80
  }
73
81
  }
74
82
 
@@ -83,7 +91,7 @@ export class WaterHeater {
83
91
  `${this.device.remoteType}: ${this.accessory.displayName} pushWaterHeaterOnChanges Active: ${this.Active},` +
84
92
  ` disablePushOn: ${this.disablePushOn}`,
85
93
  );
86
- if (this.Active === this.platform.Characteristic.Active.ACTIVE && !this.disablePushOn) {
94
+ if (this.Active === this.hap.Characteristic.Active.ACTIVE && !this.disablePushOn) {
87
95
  const commandType: string = await this.commandType();
88
96
  const command: string = await this.commandOn();
89
97
  const bodyChange = JSON.stringify({
@@ -100,7 +108,7 @@ export class WaterHeater {
100
108
  `${this.device.remoteType}: ${this.accessory.displayName} pushWaterHeaterOffChanges Active: ${this.Active},` +
101
109
  ` disablePushOff: ${this.disablePushOff}`,
102
110
  );
103
- if (this.Active === this.platform.Characteristic.Active.INACTIVE && !this.disablePushOff) {
111
+ if (this.Active === this.hap.Characteristic.Active.INACTIVE && !this.disablePushOff) {
104
112
  const commandType: string = await this.commandType();
105
113
  const command: string = await this.commandOff();
106
114
  const bodyChange = JSON.stringify({
@@ -158,7 +166,7 @@ export class WaterHeater {
158
166
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Active: ${this.Active}`);
159
167
  } else {
160
168
  this.accessory.context.Active = this.Active;
161
- this.valveService?.updateCharacteristic(this.platform.Characteristic.Active, this.Active);
169
+ this.valveService?.updateCharacteristic(this.hap.Characteristic.Active, this.Active);
162
170
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic Active: ${this.Active}`);
163
171
  }
164
172
  }
@@ -250,12 +258,12 @@ export class WaterHeater {
250
258
  }
251
259
 
252
260
  async apiError({ e }: { e: any }): Promise<void> {
253
- this.valveService.updateCharacteristic(this.platform.Characteristic.Active, e);
261
+ this.valveService.updateCharacteristic(this.hap.Characteristic.Active, e);
254
262
  }
255
263
 
256
264
  async context(): Promise<void> {
257
265
  if (this.Active === undefined) {
258
- this.Active = this.platform.Characteristic.Active.INACTIVE;
266
+ this.Active = this.hap.Characteristic.Active.INACTIVE;
259
267
  } else {
260
268
  this.Active = this.accessory.context.Active;
261
269
  }
@@ -265,7 +273,7 @@ export class WaterHeater {
265
273
  }
266
274
  }
267
275
 
268
- async config(device: irdevice & irDevicesConfig): Promise<void> {
276
+ async deviceConfig(device: irdevice & irDevicesConfig): Promise<void> {
269
277
  let config = {};
270
278
  if (device.irwh) {
271
279
  config = device.irwh;
@@ -299,7 +307,7 @@ export class WaterHeater {
299
307
  }
300
308
  }
301
309
 
302
- async logs(device: irdevice & irDevicesConfig): Promise<void> {
310
+ async deviceLogs(device: irdevice & irDevicesConfig): Promise<void> {
303
311
  if (this.platform.debugMode) {
304
312
  this.deviceLogging = this.accessory.context.logging = 'debugMode';
305
313
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
package/src/platform.ts CHANGED
@@ -1,3 +1,9 @@
1
+ /* Copyright(C) 2017-2023, donavanbecker (https://github.com/donavanbecker). All rights reserved.
2
+ *
3
+ * protect-platform.ts: homebridge-cloudflared-tunnel platform class.
4
+ */
5
+ import { API, DynamicPlatformPlugin, Logging, PlatformAccessory } from 'homebridge';
6
+ import { PLATFORM_NAME, PLUGIN_NAME, irdevice, device, SwitchBotPlatformConfig, devicesConfig, irDevicesConfig, Devices } from './settings.js';
1
7
  import { Bot } from './device/bot';
2
8
  import { Plug } from './device/plug';
3
9
  import { Lock } from './device/lock';
@@ -23,19 +29,17 @@ import { AirPurifier } from './irdevice/airpurifier';
23
29
  import { WaterHeater } from './irdevice/waterheater';
24
30
  import { VacuumCleaner } from './irdevice/vacuumcleaner';
25
31
  import { AirConditioner } from './irdevice/airconditioner';
26
- import { request } from 'undici';
27
- import crypto, { randomUUID } from 'crypto';
32
+ import * as http from 'http';
28
33
  import { Buffer } from 'buffer';
34
+ import { request } from 'undici';
35
+ import { MqttClient } from 'mqtt';
29
36
  import { queueScheduler } from 'rxjs';
30
37
  import fakegato from 'fakegato-history';
31
- import { EveHomeKitTypes } from 'homebridge-lib';
32
- import { MqttClient } from 'mqtt';
33
38
  import { connectAsync } from 'async-mqtt';
34
- import * as http from 'http';
35
-
39
+ import crypto, { randomUUID } from 'crypto';
36
40
  import { readFileSync, writeFileSync } from 'fs';
37
- import { API, DynamicPlatformPlugin, Logger, PlatformAccessory, Service, Characteristic } from 'homebridge';
38
- import { PLATFORM_NAME, PLUGIN_NAME, irdevice, device, SwitchBotPlatformConfig, devicesConfig, irDevicesConfig, Devices } from './settings';
41
+ import { EveHomeKitTypes } from 'homebridge-lib';
42
+
39
43
 
40
44
  /**
41
45
  * HomebridgePlatform
@@ -43,15 +47,15 @@ import { PLATFORM_NAME, PLUGIN_NAME, irdevice, device, SwitchBotPlatformConfig,
43
47
  * parse the user config and discover/register accessories with Homebridge.
44
48
  */
45
49
  export class SwitchBotPlatform implements DynamicPlatformPlugin {
46
- public readonly Service: typeof Service = this.api.hap.Service;
47
- public readonly Characteristic: typeof Characteristic = this.api.hap.Characteristic;
48
-
49
- // this is used to track restored cached accessories
50
- public readonly accessories: PlatformAccessory[] = [];
50
+ public accessories: PlatformAccessory[];
51
+ public readonly api: API;
52
+ public readonly log: Logging;
51
53
 
52
- version = process.env.npm_package_version || '2.9.0';
54
+ version = process.env.npm_package_version || '2.13.0';
55
+ Logging?: string;
53
56
  debugMode!: boolean;
54
57
  platformLogging?: string;
58
+ config!: SwitchBotPlatformConfig;
55
59
  webhookEventListener: http.Server | null = null;
56
60
  mqttClient: MqttClient | null = null;
57
61
 
@@ -59,18 +63,28 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
59
63
  public readonly eve: any;
60
64
  public readonly webhookEventHandler: { [x: string]: (context: { [x: string]: any }) => void } = {};
61
65
 
62
- constructor(
63
- public readonly log: Logger,
64
- public readonly config: SwitchBotPlatformConfig,
65
- public readonly api: API,
66
- ) {
67
- this.logs();
68
- this.debugLog('Finished initializing platform:', this.config.name);
66
+ constructor(log: Logging, config: SwitchBotPlatformConfig, api: API) {
67
+ this.accessories = [];
68
+ this.api = api;
69
+ this.log = log;
69
70
  // only load if configured
70
71
  if (!this.config) {
71
72
  return;
72
73
  }
73
74
 
75
+ // Plugin options into our config variables.
76
+ this.config = {
77
+ platform: 'SwitchBotPlatform',
78
+ url: config.url as string,
79
+ port: config.port as number,
80
+ hostname: config.hostname as string,
81
+ protocol: config.protocol as string,
82
+ verifyTLS: config.verifyTLS as boolean,
83
+ logging: config.logging as string,
84
+ };
85
+ this.logs();
86
+ this.debugLog(`Finished initializing platform: ${config.name}`);
87
+
74
88
  // HOOBS notice
75
89
  if (__dirname.includes('hoobs')) {
76
90
  this.warnLog(