@switchbot/homebridge-switchbot 3.5.0-beta.23 → 3.5.0-beta.25

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 (150) hide show
  1. package/config.schema.json +23 -2
  2. package/dist/device/blindtilt.d.ts +21 -98
  3. package/dist/device/blindtilt.d.ts.map +1 -1
  4. package/dist/device/blindtilt.js +332 -785
  5. package/dist/device/blindtilt.js.map +1 -1
  6. package/dist/device/bot.d.ts +25 -75
  7. package/dist/device/bot.d.ts.map +1 -1
  8. package/dist/device/bot.js +566 -778
  9. package/dist/device/bot.js.map +1 -1
  10. package/dist/device/ceilinglight.d.ts +13 -71
  11. package/dist/device/ceilinglight.d.ts.map +1 -1
  12. package/dist/device/ceilinglight.js +168 -606
  13. package/dist/device/ceilinglight.js.map +1 -1
  14. package/dist/device/colorbulb.d.ts +13 -78
  15. package/dist/device/colorbulb.d.ts.map +1 -1
  16. package/dist/device/colorbulb.js +218 -655
  17. package/dist/device/colorbulb.js.map +1 -1
  18. package/dist/device/contact.d.ts +14 -69
  19. package/dist/device/contact.d.ts.map +1 -1
  20. package/dist/device/contact.js +196 -553
  21. package/dist/device/contact.js.map +1 -1
  22. package/dist/device/curtain.d.ts +17 -90
  23. package/dist/device/curtain.d.ts.map +1 -1
  24. package/dist/device/curtain.js +324 -810
  25. package/dist/device/curtain.js.map +1 -1
  26. package/dist/device/device.d.ts +58 -0
  27. package/dist/device/device.d.ts.map +1 -0
  28. package/dist/device/device.js +629 -0
  29. package/dist/device/device.js.map +1 -0
  30. package/dist/device/hub.d.ts +15 -63
  31. package/dist/device/hub.d.ts.map +1 -1
  32. package/dist/device/hub.js +223 -610
  33. package/dist/device/hub.js.map +1 -1
  34. package/dist/device/humidifier.d.ts +10 -69
  35. package/dist/device/humidifier.d.ts.map +1 -1
  36. package/dist/device/humidifier.js +192 -595
  37. package/dist/device/humidifier.js.map +1 -1
  38. package/dist/device/iosensor.d.ts +11 -68
  39. package/dist/device/iosensor.d.ts.map +1 -1
  40. package/dist/device/iosensor.js +156 -599
  41. package/dist/device/iosensor.js.map +1 -1
  42. package/dist/device/lightstrip.d.ts +10 -72
  43. package/dist/device/lightstrip.d.ts.map +1 -1
  44. package/dist/device/lightstrip.js +204 -591
  45. package/dist/device/lightstrip.js.map +1 -1
  46. package/dist/device/lock.d.ts +15 -66
  47. package/dist/device/lock.d.ts.map +1 -1
  48. package/dist/device/lock.js +199 -566
  49. package/dist/device/lock.js.map +1 -1
  50. package/dist/device/meter.d.ts +13 -67
  51. package/dist/device/meter.d.ts.map +1 -1
  52. package/dist/device/meter.js +152 -592
  53. package/dist/device/meter.js.map +1 -1
  54. package/dist/device/meterplus.d.ts +13 -68
  55. package/dist/device/meterplus.d.ts.map +1 -1
  56. package/dist/device/meterplus.js +151 -599
  57. package/dist/device/meterplus.js.map +1 -1
  58. package/dist/device/motion.d.ts +13 -73
  59. package/dist/device/motion.d.ts.map +1 -1
  60. package/dist/device/motion.js +129 -540
  61. package/dist/device/motion.js.map +1 -1
  62. package/dist/device/plug.d.ts +9 -61
  63. package/dist/device/plug.d.ts.map +1 -1
  64. package/dist/device/plug.js +71 -476
  65. package/dist/device/plug.js.map +1 -1
  66. package/dist/device/robotvacuumcleaner.d.ts +11 -66
  67. package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
  68. package/dist/device/robotvacuumcleaner.js +122 -471
  69. package/dist/device/robotvacuumcleaner.js.map +1 -1
  70. package/dist/device/waterdetector.d.ts +9 -66
  71. package/dist/device/waterdetector.d.ts.map +1 -1
  72. package/dist/device/waterdetector.js +105 -478
  73. package/dist/device/waterdetector.js.map +1 -1
  74. package/dist/irdevice/airconditioner.d.ts +5 -36
  75. package/dist/irdevice/airconditioner.d.ts.map +1 -1
  76. package/dist/irdevice/airconditioner.js +228 -337
  77. package/dist/irdevice/airconditioner.js.map +1 -1
  78. package/dist/irdevice/airpurifier.d.ts +5 -34
  79. package/dist/irdevice/airpurifier.d.ts.map +1 -1
  80. package/dist/irdevice/airpurifier.js +19 -267
  81. package/dist/irdevice/airpurifier.js.map +1 -1
  82. package/dist/irdevice/camera.d.ts +5 -34
  83. package/dist/irdevice/camera.d.ts.map +1 -1
  84. package/dist/irdevice/camera.js +13 -261
  85. package/dist/irdevice/camera.js.map +1 -1
  86. package/dist/irdevice/fan.d.ts +5 -34
  87. package/dist/irdevice/fan.d.ts.map +1 -1
  88. package/dist/irdevice/fan.js +13 -260
  89. package/dist/irdevice/fan.js.map +1 -1
  90. package/dist/irdevice/irdevice.d.ts +39 -0
  91. package/dist/irdevice/irdevice.d.ts.map +1 -0
  92. package/dist/irdevice/irdevice.js +502 -0
  93. package/dist/irdevice/irdevice.js.map +1 -0
  94. package/dist/irdevice/light.d.ts +5 -34
  95. package/dist/irdevice/light.d.ts.map +1 -1
  96. package/dist/irdevice/light.js +13 -267
  97. package/dist/irdevice/light.js.map +1 -1
  98. package/dist/irdevice/other.d.ts +18 -48
  99. package/dist/irdevice/other.d.ts.map +1 -1
  100. package/dist/irdevice/other.js +349 -551
  101. package/dist/irdevice/other.js.map +1 -1
  102. package/dist/irdevice/tv.d.ts +7 -40
  103. package/dist/irdevice/tv.d.ts.map +1 -1
  104. package/dist/irdevice/tv.js +79 -325
  105. package/dist/irdevice/tv.js.map +1 -1
  106. package/dist/irdevice/vacuumcleaner.d.ts +6 -36
  107. package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
  108. package/dist/irdevice/vacuumcleaner.js +38 -288
  109. package/dist/irdevice/vacuumcleaner.js.map +1 -1
  110. package/dist/irdevice/waterheater.d.ts +6 -36
  111. package/dist/irdevice/waterheater.d.ts.map +1 -1
  112. package/dist/irdevice/waterheater.js +39 -291
  113. package/dist/irdevice/waterheater.js.map +1 -1
  114. package/dist/settings.d.ts +15 -2
  115. package/dist/settings.d.ts.map +1 -1
  116. package/dist/utils.d.ts +68 -0
  117. package/dist/utils.d.ts.map +1 -1
  118. package/dist/utils.js +71 -0
  119. package/dist/utils.js.map +1 -1
  120. package/package.json +9 -9
  121. package/src/device/blindtilt.ts +356 -809
  122. package/src/device/bot.ts +601 -865
  123. package/src/device/ceilinglight.ts +182 -628
  124. package/src/device/colorbulb.ts +235 -683
  125. package/src/device/contact.ts +220 -575
  126. package/src/device/curtain.ts +344 -836
  127. package/src/device/device.ts +655 -0
  128. package/src/device/hub.ts +246 -636
  129. package/src/device/humidifier.ts +224 -645
  130. package/src/device/iosensor.ts +181 -625
  131. package/src/device/lightstrip.ts +230 -622
  132. package/src/device/lock.ts +236 -607
  133. package/src/device/meter.ts +177 -616
  134. package/src/device/meterplus.ts +175 -624
  135. package/src/device/motion.ts +147 -563
  136. package/src/device/plug.ts +81 -505
  137. package/src/device/robotvacuumcleaner.ts +139 -494
  138. package/src/device/waterdetector.ts +126 -506
  139. package/src/irdevice/airconditioner.ts +228 -353
  140. package/src/irdevice/airpurifier.ts +23 -282
  141. package/src/irdevice/camera.ts +18 -277
  142. package/src/irdevice/fan.ts +18 -275
  143. package/src/irdevice/irdevice.ts +518 -0
  144. package/src/irdevice/light.ts +18 -283
  145. package/src/irdevice/other.ts +394 -621
  146. package/src/irdevice/tv.ts +97 -344
  147. package/src/irdevice/vacuumcleaner.ts +46 -310
  148. package/src/irdevice/waterheater.ts +47 -315
  149. package/src/settings.ts +20 -3
  150. package/src/utils.ts +71 -0
@@ -1,128 +1,139 @@
1
- import { CharacteristicValue, PlatformAccessory, Service, API, Logging, HAP } from 'homebridge';
1
+ /* Copyright(C) 2021-2024, donavanbecker (https://github.com/donavanbecker). All rights reserved.
2
+ *
3
+ * tv.ts: @switchbot/homebridge-switchbot.
4
+ */
2
5
  import { request } from 'undici';
6
+ import { irdeviceBase } from './irdevice.js';
3
7
  import { SwitchBotPlatform } from '../platform.js';
4
- import { Devices, irDevicesConfig, irdevice, SwitchBotPlatformConfig } from '../settings.js';
8
+ import { Devices, irDevicesConfig, irdevice } from '../settings.js';
9
+ import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
5
10
 
6
11
  /**
7
12
  * Platform Accessory
8
13
  * An instance of this class is created for each accessory your platform registers
9
14
  * Each accessory may expose multiple services of different service types.
10
15
  */
11
- export class TV {
12
- public readonly api: API;
13
- public readonly log: Logging;
14
- public readonly config!: SwitchBotPlatformConfig;
15
- protected readonly hap: HAP;
16
+ export class TV extends irdeviceBase {
16
17
  // Services
17
- tvService!: Service;
18
- speakerService: Service;
18
+ private Television: {
19
+ Service: Service;
20
+ Active: CharacteristicValue;
21
+ ActiveIdentifier: CharacteristicValue;
22
+ SleepDiscoveryMode: CharacteristicValue;
23
+ RemoteKey: CharacteristicValue;
24
+ };
25
+
26
+ private TelevisionSpeaker: {
27
+ Service: Service;
28
+ Active: CharacteristicValue;
29
+ VolumeControlType: CharacteristicValue;
30
+ VolumeSelector: CharacteristicValue;
31
+ };
19
32
 
20
33
  // Characteristic Values
21
- Active!: CharacteristicValue;
22
- ActiveIdentifier!: CharacteristicValue;
23
- FirmwareRevision!: CharacteristicValue;
24
-
25
- // Config
26
- deviceLogging!: string;
27
- disablePushOn?: boolean;
28
- disablePushOff?: boolean;
29
- disablePushDetail?: boolean;
30
34
 
31
35
  constructor(
32
- private readonly platform: SwitchBotPlatform,
33
- private accessory: PlatformAccessory,
34
- public device: irdevice & irDevicesConfig,
36
+ readonly platform: SwitchBotPlatform,
37
+ accessory: PlatformAccessory,
38
+ device: irdevice & irDevicesConfig,
35
39
  ) {
36
- this.api = this.platform.api;
37
- this.log = this.platform.log;
38
- this.config = this.platform.config;
39
- this.hap = this.api.hap;
40
+ super(platform, accessory, device);
41
+
42
+ // Initialize Television property
43
+ this.Television = {
44
+ Service: accessory.addService(this.hap.Service.Television),
45
+ Active: accessory.context.Active || this.hap.Characteristic.Active.INACTIVE,
46
+ ActiveIdentifier: accessory.context.ActiveIdentifier || 1,
47
+ SleepDiscoveryMode: accessory.context.SleepDiscoveryMode || this.hap.Characteristic.SleepDiscoveryMode.ALWAYS_DISCOVERABLE,
48
+ RemoteKey: accessory.context.RemoteKey || this.hap.Characteristic.RemoteKey.EXIT,
49
+ };
50
+
51
+ // Initialize TelevisionSpeaker property
52
+ this.TelevisionSpeaker = {
53
+ Service: accessory.addService(this.hap.Service.TelevisionSpeaker),
54
+ Active: accessory.context.Active || false,
55
+ VolumeControlType: accessory.context.VolumeControlType || this.hap.Characteristic.VolumeControlType.ABSOLUTE,
56
+ VolumeSelector: accessory.context.VolumeSelector || this.hap.Characteristic.VolumeSelector.INCREMENT,
57
+ };
58
+
40
59
  // default placeholders
41
- this.deviceLogs(device);
42
- this.deviceContext();
43
- this.disablePushOnChanges(device);
44
- this.disablePushOffChanges(device);
45
- this.disablePushDetailChanges(device);
46
- this.deviceConfig(device);
47
-
48
- // set accessory information
49
- accessory
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);
60
+ if (this.Television.Active === undefined) {
61
+ this.Television.Active = this.hap.Characteristic.Active.INACTIVE;
62
+ } else {
63
+ this.Television.Active = this.accessory.context.Active;
64
+ }
65
+ if (this.Television.ActiveIdentifier === undefined) {
66
+ this.Television.ActiveIdentifier = 1;
67
+ } else {
68
+ this.Television.ActiveIdentifier = this.accessory.context.ActiveIdentifier;
69
+ }
56
70
 
57
71
  // set the accessory category
58
- const tvServiceCategory = `${accessory.displayName} ${device.remoteType}`;
72
+ const TelevisionServiceCategory = `${accessory.displayName} ${device.remoteType}`;
59
73
  switch (device.remoteType) {
60
74
  case 'Speaker':
61
75
  case 'DIY Speaker':
62
76
  accessory.category = this.platform.api.hap.Categories.SPEAKER;
63
- (this.tvService = accessory.getService(this.hap.Service.Television)
64
- || accessory.addService(this.hap.Service.Television)), tvServiceCategory;
77
+ (this.Television.Service = accessory.getService(this.hap.Service.Television)
78
+ || accessory.addService(this.hap.Service.Television)), TelevisionServiceCategory;
65
79
  break;
66
80
  case 'IPTV':
67
81
  case 'DIY IPTV':
68
82
  accessory.category = this.platform.api.hap.Categories.TV_STREAMING_STICK;
69
- (this.tvService = accessory.getService(this.hap.Service.Television)
70
- || accessory.addService(this.hap.Service.Television)), tvServiceCategory;
83
+ (this.Television.Service = accessory.getService(this.hap.Service.Television)
84
+ || accessory.addService(this.hap.Service.Television)), TelevisionServiceCategory;
71
85
  break;
72
86
  case 'DVD':
73
87
  case 'DIY DVD':
74
88
  case 'Set Top Box':
75
89
  case 'DIY Set Top Box':
76
90
  accessory.category = this.platform.api.hap.Categories.TV_SET_TOP_BOX;
77
- (this.tvService = accessory.getService(this.hap.Service.Television)
78
- || accessory.addService(this.hap.Service.Television)), tvServiceCategory;
91
+ (this.Television.Service = accessory.getService(this.hap.Service.Television)
92
+ || accessory.addService(this.hap.Service.Television)), TelevisionServiceCategory;
79
93
  break;
80
94
  default:
81
95
  accessory.category = this.platform.api.hap.Categories.TELEVISION;
82
96
 
83
97
  // get the Television service if it exists, otherwise create a new Television service
84
98
  // you can create multiple services for each accessory
85
- (this.tvService = accessory.getService(this.hap.Service.Television)
86
- || accessory.addService(this.hap.Service.Television)), tvServiceCategory;
99
+ (this.Television.Service = accessory.getService(this.hap.Service.Television)
100
+ || accessory.addService(this.hap.Service.Television)), TelevisionServiceCategory;
87
101
  }
88
102
 
89
- this.tvService.getCharacteristic(this.hap.Characteristic.ConfiguredName);
103
+ this.Television.Service.getCharacteristic(this.hap.Characteristic.ConfiguredName);
90
104
 
91
105
  // set sleep discovery characteristic
92
- this.tvService.setCharacteristic(
106
+ this.Television.Service.setCharacteristic(
93
107
  this.hap.Characteristic.SleepDiscoveryMode,
94
108
  this.hap.Characteristic.SleepDiscoveryMode.ALWAYS_DISCOVERABLE,
95
109
  );
96
110
 
97
111
  // handle on / off events using the Active characteristic
98
- this.tvService.getCharacteristic(this.hap.Characteristic.Active).onSet(this.ActiveSet.bind(this));
112
+ this.Television.Service.getCharacteristic(this.hap.Characteristic.Active).onSet(this.ActiveSet.bind(this));
99
113
 
100
- this.tvService.setCharacteristic(this.hap.Characteristic.ActiveIdentifier, 1);
114
+ this.Television.Service.setCharacteristic(this.hap.Characteristic.ActiveIdentifier, 1);
101
115
 
102
116
  // handle input source changes
103
- this.tvService.getCharacteristic(this.hap.Characteristic.ActiveIdentifier).onSet(this.ActiveIdentifierSet.bind(this));
117
+ this.Television.Service.getCharacteristic(this.hap.Characteristic.ActiveIdentifier).onSet(this.ActiveIdentifierSet.bind(this));
104
118
 
105
119
  // handle remote control input
106
- this.tvService.getCharacteristic(this.hap.Characteristic.RemoteKey).onSet(this.RemoteKeySet.bind(this));
120
+ this.Television.Service.getCharacteristic(this.hap.Characteristic.RemoteKey).onSet(this.RemoteKeySet.bind(this));
107
121
 
108
122
  /**
109
123
  * Create a speaker service to allow volume control
110
124
  */
111
125
  // create a new Television Speaker service
112
- const speakerService = `${accessory.displayName} Speaker`;
113
- (this.speakerService = accessory.getService(this.hap.Service.TelevisionSpeaker)
114
- || accessory.addService(this.hap.Service.TelevisionSpeaker)), speakerService;
126
+ const TelevisionSpeakerService = `${accessory.displayName} Speaker`;
127
+ (this.TelevisionSpeaker.Service = accessory.getService(this.hap.Service.TelevisionSpeaker)
128
+ || accessory.addService(this.hap.Service.TelevisionSpeaker)), TelevisionSpeakerService;
115
129
 
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`);
119
- }
120
- this.speakerService
130
+ this.TelevisionSpeaker.Service.setCharacteristic(this.hap.Characteristic.Name, TelevisionSpeakerService);
131
+ this.TelevisionSpeaker.Service
121
132
  .setCharacteristic(this.hap.Characteristic.Active, this.hap.Characteristic.Active.ACTIVE)
122
133
  .setCharacteristic(this.hap.Characteristic.VolumeControlType, this.hap.Characteristic.VolumeControlType.ABSOLUTE);
123
134
 
124
135
  // handle volume control
125
- this.speakerService.getCharacteristic(this.hap.Characteristic.VolumeSelector).onSet(this.VolumeSelectorSet.bind(this));
136
+ this.TelevisionSpeaker.Service.getCharacteristic(this.hap.Characteristic.VolumeSelector).onSet(this.VolumeSelectorSet.bind(this));
126
137
  }
127
138
 
128
139
  async VolumeSelectorSet(value: CharacteristicValue): Promise<void> {
@@ -200,14 +211,14 @@ export class TV {
200
211
 
201
212
  async ActiveIdentifierSet(value: CharacteristicValue): Promise<void> {
202
213
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} ActiveIdentifier: ${value}`);
203
- this.ActiveIdentifier = value;
214
+ this.Television.ActiveIdentifier = value;
204
215
  }
205
216
 
206
217
  async ActiveSet(value: CharacteristicValue): Promise<void> {
207
218
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Active (value): ${value}`);
208
219
 
209
- this.Active = value;
210
- if (this.Active === this.hap.Characteristic.Active.ACTIVE) {
220
+ this.Television.Active = value;
221
+ if (this.Television.Active === this.hap.Characteristic.Active.ACTIVE) {
211
222
  await this.pushTvOnChanges();
212
223
  } else {
213
224
  await this.pushTvOffChanges();
@@ -225,10 +236,9 @@ export class TV {
225
236
  * TV "command" "channelSub" "default" previous channel
226
237
  */
227
238
  async pushTvOnChanges(): Promise<void> {
228
- this.debugLog(
229
- `${this.device.remoteType}: ${this.accessory.displayName} pushTvOnChanges Active: ${this.Active},` + ` disablePushOn: ${this.disablePushOn}`,
230
- );
231
- if (this.Active === this.hap.Characteristic.Active.ACTIVE && !this.disablePushOn) {
239
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushTvOnChanges`
240
+ + ` Active: ${this.Television.Active}, disablePushOn: ${this.disablePushOn}`);
241
+ if (this.Television.Active === this.hap.Characteristic.Active.ACTIVE && !this.disablePushOn) {
232
242
  const commandType: string = await this.commandType();
233
243
  const command: string = await this.commandOn();
234
244
  const bodyChange = JSON.stringify({
@@ -241,10 +251,9 @@ export class TV {
241
251
  }
242
252
 
243
253
  async pushTvOffChanges(): Promise<void> {
244
- this.debugLog(
245
- `${this.device.remoteType}: ${this.accessory.displayName} pushTvOffChanges Active: ${this.Active},` + ` disablePushOff: ${this.disablePushOff}`,
246
- );
247
- if (this.Active === this.hap.Characteristic.Active.INACTIVE && !this.disablePushOff) {
254
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushTvOffChanges`
255
+ + ` Active: ${this.Television.Active}, disablePushOff: ${this.disablePushOff}`);
256
+ if (this.Television.Active === this.hap.Characteristic.Active.INACTIVE && !this.disablePushOff) {
248
257
  const commandType: string = await this.commandType();
249
258
  const command: string = await this.commandOff();
250
259
  const bodyChange = JSON.stringify({
@@ -404,282 +413,26 @@ export class TV {
404
413
 
405
414
  async updateHomeKitCharacteristics(): Promise<void> {
406
415
  // Active
407
- if (this.Active === undefined) {
408
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Active: ${this.Active}`);
416
+ if (this.Television.Active === undefined) {
417
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Active: ${this.Television.Active}`);
409
418
  } else {
410
- this.accessory.context.Active = this.Active;
411
- this.tvService?.updateCharacteristic(this.hap.Characteristic.Active, this.Active);
412
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic Active: ${this.Active}`);
419
+ this.accessory.context.Active = this.Television.Active;
420
+ this.Television.Service?.updateCharacteristic(this.hap.Characteristic.Active, this.Television.Active);
421
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic Active: ${this.Television.Active}`);
413
422
  }
414
423
  // ActiveIdentifier
415
- if (this.ActiveIdentifier === undefined) {
416
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} ActiveIdentifier: ${this.ActiveIdentifier}`);
417
- } else {
418
- this.accessory.context.ActiveIdentifier = this.ActiveIdentifier;
419
- this.tvService?.updateCharacteristic(this.hap.Characteristic.ActiveIdentifier, this.ActiveIdentifier);
420
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName}` + ` updateCharacteristic ActiveIdentifier: ${this.ActiveIdentifier}`);
421
- }
422
- }
423
-
424
- async disablePushOnChanges(device: irdevice & irDevicesConfig): Promise<void> {
425
- if (device.disablePushOn === undefined) {
426
- this.disablePushOn = false;
427
- } else {
428
- this.disablePushOn = device.disablePushOn;
429
- }
430
- }
431
-
432
- async disablePushOffChanges(device: irdevice & irDevicesConfig): Promise<void> {
433
- if (device.disablePushOff === undefined) {
434
- this.disablePushOff = false;
435
- } else {
436
- this.disablePushOff = device.disablePushOff;
437
- }
438
- }
439
-
440
- async disablePushDetailChanges(device: irdevice & irDevicesConfig): Promise<void> {
441
- if (device.disablePushDetail === undefined) {
442
- this.disablePushDetail = false;
443
- } else {
444
- this.disablePushDetail = device.disablePushDetail;
445
- }
446
- }
447
-
448
- async commandType(): Promise<string> {
449
- let commandType: string;
450
- if (this.device.customize) {
451
- commandType = 'customize';
452
- } else {
453
- commandType = 'command';
454
- }
455
- return commandType;
456
- }
457
-
458
- async commandOn(): Promise<string> {
459
- let command: string;
460
- if (this.device.customize && this.device.customOn) {
461
- command = this.device.customOn;
424
+ if (this.Television.ActiveIdentifier === undefined) {
425
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} ActiveIdentifier: ${this.Television.ActiveIdentifier}`);
462
426
  } else {
463
- command = 'turnOn';
464
- }
465
- return command;
466
- }
467
-
468
- async commandOff(): Promise<string> {
469
- let command: string;
470
- if (this.device.customize && this.device.customOff) {
471
- command = this.device.customOff;
472
- } else {
473
- command = 'turnOff';
474
- }
475
- return command;
476
- }
477
-
478
- async statusCode(statusCode: number): Promise<void> {
479
- switch (statusCode) {
480
- case 151:
481
- this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Command not supported by this deviceType, statusCode: ${statusCode}`);
482
- break;
483
- case 152:
484
- this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Device not found, statusCode: ${statusCode}`);
485
- break;
486
- case 160:
487
- this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Command is not supported, statusCode: ${statusCode}`);
488
- break;
489
- case 161:
490
- this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Device is offline, statusCode: ${statusCode}`);
491
- break;
492
- case 171:
493
- this.errorLog(
494
- `${this.device.remoteType}: ${this.accessory.displayName} Hub Device is offline, statusCode: ${statusCode}. ` +
495
- `Hub: ${this.device.hubDeviceId}`,
496
- );
497
- break;
498
- case 190:
499
- this.errorLog(
500
- `${this.device.remoteType}: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,` +
501
- ` Or command format is invalid, statusCode: ${statusCode}`,
502
- );
503
- break;
504
- case 100:
505
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Command successfully sent, statusCode: ${statusCode}`);
506
- break;
507
- case 200:
508
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Request successful, statusCode: ${statusCode}`);
509
- break;
510
- case 400:
511
- this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Bad Request, The client has issued an invalid request. `
512
- + `This is commonly used to specify validation errors in a request payload, statusCode: ${statusCode}`);
513
- break;
514
- case 401:
515
- this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Unauthorized, Authorization for the API is required, `
516
- + `but the request has not been authenticated, statusCode: ${statusCode}`);
517
- break;
518
- case 403:
519
- this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Forbidden, The request has been authenticated but does not `
520
- + `have appropriate permissions, or a requested resource is not found, statusCode: ${statusCode}`);
521
- break;
522
- case 404:
523
- this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Not Found, Specifies the requested path does not exist, `
524
- + `statusCode: ${statusCode}`);
525
- break;
526
- case 406:
527
- this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Not Acceptable, The client has requested a MIME type via `
528
- + `the Accept header for a value not supported by the server, statusCode: ${statusCode}`);
529
- break;
530
- case 415:
531
- this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Unsupported Media Type, The client has defined a contentType `
532
- + `header that is not supported by the server, statusCode: ${statusCode}`);
533
- break;
534
- case 422:
535
- this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Unprocessable Entity, The client has made a valid request, but `
536
- + `the server cannot process it. This is often used for APIs for which certain limits have been exceeded, statusCode: ${statusCode}`);
537
- break;
538
- case 429:
539
- this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Too Many Requests, The client has exceeded the number of `
540
- + `requests allowed for a given time window, statusCode: ${statusCode}`);
541
- break;
542
- case 500:
543
- this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Internal Server Error, An unexpected error on the SmartThings `
544
- + `servers has occurred. These errors should be rare, statusCode: ${statusCode}`);
545
- break;
546
- default:
547
- this.infoLog(
548
- `${this.device.remoteType}: ${this.accessory.displayName} Unknown statusCode: ` +
549
- `${statusCode}, Submit Bugs Here: ' + 'https://tinyurl.com/SwitchBotBug`,
550
- );
427
+ this.accessory.context.ActiveIdentifier = this.Television.ActiveIdentifier;
428
+ this.Television.Service?.updateCharacteristic(this.hap.Characteristic.ActiveIdentifier, this.Television.ActiveIdentifier);
429
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic`
430
+ + ` ActiveIdentifier: ${this.Television.ActiveIdentifier}`);
551
431
  }
552
432
  }
553
433
 
554
434
  async apiError(e: any): Promise<void> {
555
- this.tvService.updateCharacteristic(this.hap.Characteristic.Active, e);
556
- this.tvService.updateCharacteristic(this.hap.Characteristic.ActiveIdentifier, e);
557
- }
558
-
559
- async deviceContext() {
560
- if (this.Active === undefined) {
561
- this.Active = this.hap.Characteristic.Active.INACTIVE;
562
- } else {
563
- this.Active = this.accessory.context.Active;
564
- }
565
- if (this.ActiveIdentifier === undefined) {
566
- this.ActiveIdentifier = 1;
567
- } else {
568
- this.ActiveIdentifier = this.accessory.context.ActiveIdentifier;
569
- }
570
- if (this.FirmwareRevision === undefined) {
571
- this.FirmwareRevision = this.platform.version;
572
- this.accessory.context.FirmwareRevision = this.FirmwareRevision;
573
- }
574
- }
575
-
576
- async deviceConfig(device: irdevice & irDevicesConfig): Promise<void> {
577
- let config = {};
578
- if (device.irtv) {
579
- config = device.irtv;
580
- }
581
- if (device.logging !== undefined) {
582
- config['logging'] = device.logging;
583
- }
584
- if (device.connectionType !== undefined) {
585
- config['connectionType'] = device.connectionType;
586
- }
587
- if (device.external !== undefined) {
588
- config['external'] = device.external;
589
- }
590
- if (device.customOn !== undefined) {
591
- config['customOn'] = device.customOn;
592
- }
593
- if (device.customOff !== undefined) {
594
- config['customOff'] = device.customOff;
595
- }
596
- if (device.customize !== undefined) {
597
- config['customize'] = device.customize;
598
- }
599
- if (device.disablePushOn !== undefined) {
600
- config['disablePushOn'] = device.disablePushOn;
601
- }
602
- if (device.disablePushOff !== undefined) {
603
- config['disablePushOff'] = device.disablePushOff;
604
- }
605
- if (device.disablePushDetail !== undefined) {
606
- config['disablePushDetail'] = device.disablePushDetail;
607
- }
608
- if (Object.entries(config).length !== 0) {
609
- this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
610
- }
611
- }
612
-
613
- async deviceLogs(device: irdevice & irDevicesConfig): Promise<void> {
614
- if (this.platform.debugMode) {
615
- this.deviceLogging = this.accessory.context.logging = 'debugMode';
616
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
617
- } else if (device.logging) {
618
- this.deviceLogging = this.accessory.context.logging = device.logging;
619
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
620
- } else if (this.platform.config.options?.logging) {
621
- this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
622
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
623
- } else {
624
- this.deviceLogging = this.accessory.context.logging = 'standard';
625
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`);
626
- }
627
- }
628
-
629
- /**
630
- * Logging for Device
631
- */
632
- successLog(...log: any[]): void {
633
- if (this.enablingDeviceLogging()) {
634
- this.platform.log.success(String(...log));
635
- }
636
- }
637
-
638
- infoLog(...log: any[]): void {
639
- if (this.enablingDeviceLogging()) {
640
- this.platform.log.info(String(...log));
641
- }
642
- }
643
-
644
- warnLog(...log: any[]): void {
645
- if (this.enablingDeviceLogging()) {
646
- this.platform.log.warn(String(...log));
647
- }
648
- }
649
-
650
- debugWarnLog(...log: any[]): void {
651
- if (this.enablingDeviceLogging()) {
652
- if (this.deviceLogging?.includes('debug')) {
653
- this.platform.log.warn('[DEBUG]', String(...log));
654
- }
655
- }
656
- }
657
-
658
- errorLog(...log: any[]): void {
659
- if (this.enablingDeviceLogging()) {
660
- this.platform.log.error(String(...log));
661
- }
662
- }
663
-
664
- debugErrorLog(...log: any[]): void {
665
- if (this.enablingDeviceLogging()) {
666
- if (this.deviceLogging?.includes('debug')) {
667
- this.platform.log.error('[DEBUG]', String(...log));
668
- }
669
- }
670
- }
671
-
672
- debugLog(...log: any[]): void {
673
- if (this.enablingDeviceLogging()) {
674
- if (this.deviceLogging === 'debug') {
675
- this.platform.log.info('[DEBUG]', String(...log));
676
- } else {
677
- this.platform.log.debug(String(...log));
678
- }
679
- }
680
- }
681
-
682
- enablingDeviceLogging(): boolean {
683
- return this.deviceLogging.includes('debug') || this.deviceLogging === 'standard';
435
+ this.Television.Service.updateCharacteristic(this.hap.Characteristic.Active, e);
436
+ this.Television.Service.updateCharacteristic(this.hap.Characteristic.ActiveIdentifier, e);
684
437
  }
685
438
  }