@switchbot/homebridge-switchbot 3.5.0-beta.9 → 3.5.1-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.
- package/.vscode/settings.json +4 -1
- package/CHANGELOG.md +4 -1
- package/config.schema.json +164 -22
- package/dist/device/blindtilt.d.ts +21 -96
- package/dist/device/blindtilt.d.ts.map +1 -1
- package/dist/device/blindtilt.js +457 -866
- package/dist/device/blindtilt.js.map +1 -1
- package/dist/device/bot.d.ts +27 -72
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +851 -913
- package/dist/device/bot.js.map +1 -1
- package/dist/device/ceilinglight.d.ts +15 -69
- package/dist/device/ceilinglight.d.ts.map +1 -1
- package/dist/device/ceilinglight.js +316 -742
- package/dist/device/ceilinglight.js.map +1 -1
- package/dist/device/colorbulb.d.ts +15 -76
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +380 -833
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts +14 -66
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +267 -602
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts +18 -89
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +469 -897
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/device.d.ts +76 -0
- package/dist/device/device.d.ts.map +1 -0
- package/dist/device/device.js +846 -0
- package/dist/device/device.js.map +1 -0
- package/dist/device/fan.d.ts +63 -0
- package/dist/device/fan.d.ts.map +1 -0
- package/dist/device/fan.js +645 -0
- package/dist/device/fan.js.map +1 -0
- package/dist/device/hub.d.ts +19 -58
- package/dist/device/hub.d.ts.map +1 -1
- package/dist/device/hub.js +304 -640
- package/dist/device/hub.js.map +1 -1
- package/dist/device/humidifier.d.ts +11 -66
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +300 -710
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/iosensor.d.ts +12 -64
- package/dist/device/iosensor.d.ts.map +1 -1
- package/dist/device/iosensor.js +225 -643
- package/dist/device/iosensor.js.map +1 -1
- package/dist/device/lightstrip.d.ts +12 -70
- package/dist/device/lightstrip.d.ts.map +1 -1
- package/dist/device/lightstrip.js +371 -742
- package/dist/device/lightstrip.js.map +1 -1
- package/dist/device/lock.d.ts +17 -63
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +309 -642
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts +15 -64
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +223 -638
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.d.ts +15 -65
- package/dist/device/meterplus.d.ts.map +1 -1
- package/dist/device/meterplus.js +216 -644
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.d.ts +12 -69
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +209 -588
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts +10 -57
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +141 -532
- package/dist/device/plug.js.map +1 -1
- package/dist/device/robotvacuumcleaner.d.ts +13 -63
- package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
- package/dist/device/robotvacuumcleaner.js +252 -609
- package/dist/device/robotvacuumcleaner.js.map +1 -1
- package/dist/device/waterdetector.d.ts +11 -63
- package/dist/device/waterdetector.d.ts.map +1 -1
- package/dist/device/waterdetector.js +179 -521
- package/dist/device/waterdetector.js.map +1 -1
- package/dist/homebridge-ui/public/index.html +22 -16
- package/dist/homebridge-ui/server.js +1 -1
- package/dist/homebridge-ui/server.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/irdevice/airconditioner.d.ts +10 -50
- package/dist/irdevice/airconditioner.d.ts.map +1 -1
- package/dist/irdevice/airconditioner.js +337 -482
- package/dist/irdevice/airconditioner.js.map +1 -1
- package/dist/irdevice/airpurifier.d.ts +8 -39
- package/dist/irdevice/airpurifier.d.ts.map +1 -1
- package/dist/irdevice/airpurifier.js +108 -333
- package/dist/irdevice/airpurifier.js.map +1 -1
- package/dist/irdevice/camera.d.ts +7 -36
- package/dist/irdevice/camera.d.ts.map +1 -1
- package/dist/irdevice/camera.js +47 -299
- package/dist/irdevice/camera.js.map +1 -1
- package/dist/irdevice/fan.d.ts +7 -43
- package/dist/irdevice/fan.d.ts.map +1 -1
- package/dist/irdevice/fan.js +95 -364
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/irdevice.d.ts +46 -0
- package/dist/irdevice/irdevice.d.ts.map +1 -0
- package/dist/irdevice/irdevice.js +393 -0
- package/dist/irdevice/irdevice.js.map +1 -0
- package/dist/irdevice/light.d.ts +12 -45
- package/dist/irdevice/light.d.ts.map +1 -1
- package/dist/irdevice/light.js +121 -376
- package/dist/irdevice/light.js.map +1 -1
- package/dist/irdevice/other.d.ts +19 -48
- package/dist/irdevice/other.d.ts.map +1 -1
- package/dist/irdevice/other.js +441 -584
- package/dist/irdevice/other.js.map +1 -1
- package/dist/irdevice/tv.d.ts +8 -40
- package/dist/irdevice/tv.d.ts.map +1 -1
- package/dist/irdevice/tv.js +94 -353
- package/dist/irdevice/tv.js.map +1 -1
- package/dist/irdevice/vacuumcleaner.d.ts +7 -36
- package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
- package/dist/irdevice/vacuumcleaner.js +48 -299
- package/dist/irdevice/vacuumcleaner.js.map +1 -1
- package/dist/irdevice/waterheater.d.ts +7 -36
- package/dist/irdevice/waterheater.d.ts.map +1 -1
- package/dist/irdevice/waterheater.js +50 -305
- package/dist/irdevice/waterheater.js.map +1 -1
- package/dist/platform.d.ts +22 -8
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +342 -191
- package/dist/platform.js.map +1 -1
- package/dist/settings.d.ts +66 -18
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js +16 -552
- package/dist/settings.js.map +1 -1
- package/dist/utils.d.ts +95 -0
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +657 -1
- package/dist/utils.js.map +1 -1
- package/eslint.config.js +96 -0
- package/package.json +20 -16
- package/src/custom.d.ts +2 -1
- package/src/device/blindtilt.ts +488 -937
- package/src/device/bot.ts +907 -1016
- package/src/device/ceilinglight.ts +330 -798
- package/src/device/colorbulb.ts +394 -904
- package/src/device/contact.ts +298 -637
- package/src/device/curtain.ts +496 -954
- package/src/device/device.ts +872 -0
- package/src/device/fan.ts +692 -0
- package/src/device/hub.ts +338 -671
- package/src/device/humidifier.ts +330 -777
- package/src/device/iosensor.ts +258 -671
- package/src/device/lightstrip.ts +394 -809
- package/src/device/lock.ts +345 -700
- package/src/device/meter.ts +256 -666
- package/src/device/meterplus.ts +248 -672
- package/src/device/motion.ts +234 -622
- package/src/device/plug.ts +152 -572
- package/src/device/robotvacuumcleaner.ts +273 -653
- package/src/device/waterdetector.ts +198 -549
- package/src/homebridge-ui/public/index.html +22 -16
- package/src/homebridge-ui/server.ts +1 -1
- package/src/index.ts +4 -3
- package/src/irdevice/airconditioner.ts +368 -540
- package/src/irdevice/airpurifier.ts +134 -369
- package/src/irdevice/camera.ts +60 -324
- package/src/irdevice/fan.ts +111 -392
- package/src/irdevice/irdevice.ts +406 -0
- package/src/irdevice/light.ts +159 -425
- package/src/irdevice/other.ts +509 -661
- package/src/irdevice/tv.ts +123 -388
- package/src/irdevice/vacuumcleaner.ts +61 -324
- package/src/irdevice/waterheater.ts +63 -333
- package/src/platform.ts +395 -259
- package/src/settings.ts +120 -610
- package/src/utils.ts +661 -1
- package/src/device/waterdetector.json +0 -11
package/src/irdevice/tv.ts
CHANGED
|
@@ -1,128 +1,126 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
/* Copyright(C) 2021-2024, donavanbecker (https://github.com/donavanbecker). All rights reserved.
|
|
2
|
+
*
|
|
3
|
+
* tv.ts: @switchbot/homebridge-switchbot.
|
|
4
|
+
*/
|
|
5
|
+
import { irdeviceBase } from './irdevice.js';
|
|
6
|
+
|
|
7
|
+
import type { SwitchBotPlatform } from '../platform.js';
|
|
8
|
+
import type { irDevicesConfig, irdevice } from '../settings.js';
|
|
9
|
+
import type { 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
|
-
|
|
18
|
-
|
|
18
|
+
private Television: {
|
|
19
|
+
Name: CharacteristicValue;
|
|
20
|
+
ConfiguredName: CharacteristicValue;
|
|
21
|
+
Service: Service;
|
|
22
|
+
Active: CharacteristicValue;
|
|
23
|
+
ActiveIdentifier: CharacteristicValue;
|
|
24
|
+
SleepDiscoveryMode: CharacteristicValue;
|
|
25
|
+
RemoteKey: CharacteristicValue;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
private TelevisionSpeaker: {
|
|
29
|
+
Name: CharacteristicValue;
|
|
30
|
+
Service: Service;
|
|
31
|
+
Active: CharacteristicValue;
|
|
32
|
+
VolumeControlType: CharacteristicValue;
|
|
33
|
+
VolumeSelector: CharacteristicValue;
|
|
34
|
+
};
|
|
19
35
|
|
|
20
36
|
// 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
37
|
|
|
31
38
|
constructor(
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
39
|
+
readonly platform: SwitchBotPlatform,
|
|
40
|
+
accessory: PlatformAccessory,
|
|
41
|
+
device: irdevice & irDevicesConfig,
|
|
35
42
|
) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
accessory
|
|
50
|
-
|
|
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);
|
|
56
|
-
|
|
57
|
-
// set the accessory category
|
|
58
|
-
const tvServiceCategory = `${accessory.displayName} ${device.remoteType}`;
|
|
43
|
+
super(platform, accessory, device);
|
|
44
|
+
|
|
45
|
+
// Initialize Television Service
|
|
46
|
+
accessory.context.Television = accessory.context.Television ?? {};
|
|
47
|
+
this.Television = {
|
|
48
|
+
Name: accessory.context.Television.Name ?? `${accessory.displayName} ${device.remoteType}`,
|
|
49
|
+
ConfiguredName: accessory.context.Television.ConfiguredName ?? `${accessory.displayName} ${device.remoteType}`,
|
|
50
|
+
Service: accessory.getService(this.hap.Service.Television) ?? accessory.addService(this.hap.Service.Television) as Service,
|
|
51
|
+
Active: accessory.context.Active ?? this.hap.Characteristic.Active.INACTIVE,
|
|
52
|
+
ActiveIdentifier: accessory.context.ActiveIdentifier ?? 1,
|
|
53
|
+
SleepDiscoveryMode: accessory.context.SleepDiscoveryMode ?? this.hap.Characteristic.SleepDiscoveryMode.ALWAYS_DISCOVERABLE,
|
|
54
|
+
RemoteKey: accessory.context.RemoteKey ?? this.hap.Characteristic.RemoteKey.EXIT,
|
|
55
|
+
};
|
|
56
|
+
accessory.context.Television = this.Television as object;
|
|
57
|
+
|
|
59
58
|
switch (device.remoteType) {
|
|
60
59
|
case 'Speaker':
|
|
61
60
|
case 'DIY Speaker':
|
|
62
61
|
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;
|
|
65
62
|
break;
|
|
66
63
|
case 'IPTV':
|
|
67
64
|
case 'DIY IPTV':
|
|
68
65
|
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;
|
|
71
66
|
break;
|
|
72
67
|
case 'DVD':
|
|
73
68
|
case 'DIY DVD':
|
|
74
69
|
case 'Set Top Box':
|
|
75
70
|
case 'DIY Set Top Box':
|
|
76
71
|
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;
|
|
79
72
|
break;
|
|
80
73
|
default:
|
|
81
74
|
accessory.category = this.platform.api.hap.Categories.TELEVISION;
|
|
82
|
-
|
|
83
|
-
// get the Television service if it exists, otherwise create a new Television service
|
|
84
|
-
// 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;
|
|
87
75
|
}
|
|
88
76
|
|
|
89
|
-
this.
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
77
|
+
this.Television.Service
|
|
78
|
+
.setCharacteristic(this.hap.Characteristic.SleepDiscoveryMode, this.hap.Characteristic.SleepDiscoveryMode.ALWAYS_DISCOVERABLE)
|
|
79
|
+
.setCharacteristic(this.hap.Characteristic.ConfiguredName, this.Television.ConfiguredName)
|
|
80
|
+
.getCharacteristic(this.hap.Characteristic.ConfiguredName);
|
|
81
|
+
|
|
82
|
+
this.Television.Service
|
|
83
|
+
.setCharacteristic(this.hap.Characteristic.ActiveIdentifier, 1)
|
|
84
|
+
.getCharacteristic(this.hap.Characteristic.Active)
|
|
85
|
+
.onGet(() => {
|
|
86
|
+
return this.Television.Active;
|
|
87
|
+
})
|
|
88
|
+
.onSet(this.ActiveSet.bind(this));
|
|
89
|
+
|
|
90
|
+
this.Television.Service
|
|
91
|
+
.getCharacteristic(this.hap.Characteristic.ActiveIdentifier)
|
|
92
|
+
.onGet(() => {
|
|
93
|
+
return this.Television.ActiveIdentifier;
|
|
94
|
+
})
|
|
95
|
+
.onSet(this.ActiveIdentifierSet.bind(this));
|
|
96
|
+
|
|
97
|
+
this.Television.Service
|
|
98
|
+
.getCharacteristic(this.hap.Characteristic.RemoteKey)
|
|
99
|
+
.onGet(() => {
|
|
100
|
+
return this.Television.RemoteKey;
|
|
101
|
+
})
|
|
102
|
+
.onSet(this.RemoteKeySet.bind(this));
|
|
103
|
+
|
|
104
|
+
// Initialize TelevisionSpeaker Service
|
|
105
|
+
accessory.context.TelevisionSpeaker = accessory.context.TelevisionSpeaker ?? {};
|
|
106
|
+
this.TelevisionSpeaker = {
|
|
107
|
+
Name: accessory.context.TelevisionSpeaker.Name ?? `${accessory.displayName} ${device.remoteType} Speaker`,
|
|
108
|
+
Service: accessory.getService(this.hap.Service.TelevisionSpeaker) ?? accessory.addService(this.hap.Service.TelevisionSpeaker) as Service,
|
|
109
|
+
Active: accessory.context.Active ?? false,
|
|
110
|
+
VolumeControlType: accessory.context.VolumeControlType ?? this.hap.Characteristic.VolumeControlType.ABSOLUTE,
|
|
111
|
+
VolumeSelector: accessory.context.VolumeSelector ?? this.hap.Characteristic.VolumeSelector.INCREMENT,
|
|
112
|
+
};
|
|
113
|
+
accessory.context.TelevisionSpeaker = this.TelevisionSpeaker as object;
|
|
114
|
+
|
|
115
|
+
this.TelevisionSpeaker.Service
|
|
116
|
+
.setCharacteristic(this.hap.Characteristic.Name, this.TelevisionSpeaker.Name)
|
|
121
117
|
.setCharacteristic(this.hap.Characteristic.Active, this.hap.Characteristic.Active.ACTIVE)
|
|
122
|
-
.setCharacteristic(this.hap.Characteristic.VolumeControlType, this.hap.Characteristic.VolumeControlType.ABSOLUTE)
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
118
|
+
.setCharacteristic(this.hap.Characteristic.VolumeControlType, this.hap.Characteristic.VolumeControlType.ABSOLUTE)
|
|
119
|
+
.getCharacteristic(this.hap.Characteristic.VolumeSelector)
|
|
120
|
+
.onGet(() => {
|
|
121
|
+
return this.TelevisionSpeaker.VolumeSelector;
|
|
122
|
+
})
|
|
123
|
+
.onSet(this.VolumeSelectorSet.bind(this));
|
|
126
124
|
}
|
|
127
125
|
|
|
128
126
|
async VolumeSelectorSet(value: CharacteristicValue): Promise<void> {
|
|
@@ -200,14 +198,14 @@ export class TV {
|
|
|
200
198
|
|
|
201
199
|
async ActiveIdentifierSet(value: CharacteristicValue): Promise<void> {
|
|
202
200
|
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} ActiveIdentifier: ${value}`);
|
|
203
|
-
this.ActiveIdentifier = value;
|
|
201
|
+
this.Television.ActiveIdentifier = value;
|
|
204
202
|
}
|
|
205
203
|
|
|
206
204
|
async ActiveSet(value: CharacteristicValue): Promise<void> {
|
|
207
205
|
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Active (value): ${value}`);
|
|
208
206
|
|
|
209
|
-
this.Active = value;
|
|
210
|
-
if (this.Active === this.hap.Characteristic.Active.ACTIVE) {
|
|
207
|
+
this.Television.Active = value;
|
|
208
|
+
if (this.Television.Active === this.hap.Characteristic.Active.ACTIVE) {
|
|
211
209
|
await this.pushTvOnChanges();
|
|
212
210
|
} else {
|
|
213
211
|
await this.pushTvOffChanges();
|
|
@@ -225,10 +223,9 @@ export class TV {
|
|
|
225
223
|
* TV "command" "channelSub" "default" previous channel
|
|
226
224
|
*/
|
|
227
225
|
async pushTvOnChanges(): Promise<void> {
|
|
228
|
-
this.debugLog(
|
|
229
|
-
|
|
230
|
-
)
|
|
231
|
-
if (this.Active === this.hap.Characteristic.Active.ACTIVE && !this.disablePushOn) {
|
|
226
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushTvOnChanges`
|
|
227
|
+
+ ` Active: ${this.Television.Active}, disablePushOn: ${this.disablePushOn}`);
|
|
228
|
+
if (this.Television.Active === this.hap.Characteristic.Active.ACTIVE && !this.disablePushOn) {
|
|
232
229
|
const commandType: string = await this.commandType();
|
|
233
230
|
const command: string = await this.commandOn();
|
|
234
231
|
const bodyChange = JSON.stringify({
|
|
@@ -241,10 +238,9 @@ export class TV {
|
|
|
241
238
|
}
|
|
242
239
|
|
|
243
240
|
async pushTvOffChanges(): Promise<void> {
|
|
244
|
-
this.debugLog(
|
|
245
|
-
|
|
246
|
-
)
|
|
247
|
-
if (this.Active === this.hap.Characteristic.Active.INACTIVE && !this.disablePushOff) {
|
|
241
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushTvOffChanges`
|
|
242
|
+
+ ` Active: ${this.Television.Active}, disablePushOff: ${this.disablePushOff}`);
|
|
243
|
+
if (this.Television.Active === this.hap.Characteristic.Active.INACTIVE && !this.disablePushOff) {
|
|
248
244
|
const commandType: string = await this.commandType();
|
|
249
245
|
const command: string = await this.commandOff();
|
|
250
246
|
const bodyChange = JSON.stringify({
|
|
@@ -369,310 +365,49 @@ export class TV {
|
|
|
369
365
|
if (this.device.connectionType === 'OpenAPI') {
|
|
370
366
|
this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
|
|
371
367
|
try {
|
|
372
|
-
const { body, statusCode } = await
|
|
373
|
-
body: bodyChange,
|
|
374
|
-
method: 'POST',
|
|
375
|
-
headers: this.platform.generateHeaders(),
|
|
376
|
-
});
|
|
377
|
-
this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} statusCode: ${statusCode}`);
|
|
368
|
+
const { body, statusCode } = await this.pushChangeRequest(bodyChange);
|
|
378
369
|
const deviceStatus: any = await body.json();
|
|
379
|
-
this.
|
|
380
|
-
this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} deviceStatus statusCode: ${deviceStatus.statusCode}`);
|
|
370
|
+
await this.pushStatusCodes(statusCode, deviceStatus);
|
|
381
371
|
if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
|
|
382
|
-
this.
|
|
383
|
-
|
|
384
|
-
this.updateHomeKitCharacteristics();
|
|
372
|
+
await this.successfulPushChange(statusCode, deviceStatus, bodyChange);
|
|
373
|
+
await this.updateHomeKitCharacteristics();
|
|
385
374
|
} else {
|
|
386
|
-
this.statusCode(statusCode);
|
|
387
|
-
this.statusCode(deviceStatus.statusCode);
|
|
375
|
+
await this.statusCode(statusCode);
|
|
376
|
+
await this.statusCode(deviceStatus.statusCode);
|
|
388
377
|
}
|
|
389
378
|
} catch (e: any) {
|
|
390
379
|
this.apiError(e);
|
|
391
|
-
this.errorLog(
|
|
392
|
-
|
|
393
|
-
` Connection, Error Message: ${JSON.stringify(e.message)}`,
|
|
394
|
-
);
|
|
380
|
+
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} failed pushTVChanges with ${this.device.connectionType}`
|
|
381
|
+
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
395
382
|
}
|
|
396
383
|
} else {
|
|
397
|
-
this.warnLog(
|
|
398
|
-
|
|
399
|
-
` Connection Type: ${this.device.connectionType}, commands will not be sent to OpenAPI`,
|
|
400
|
-
);
|
|
384
|
+
this.warnLog(`${this.device.remoteType}: ${this.accessory.displayName}`
|
|
385
|
+
+ ` Connection Type: ${this.device.connectionType}, commands will not be sent to OpenAPI`);
|
|
401
386
|
}
|
|
402
387
|
}
|
|
403
388
|
|
|
404
389
|
async updateHomeKitCharacteristics(): Promise<void> {
|
|
405
390
|
// Active
|
|
406
|
-
if (this.Active === undefined) {
|
|
407
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Active: ${this.Active}`);
|
|
391
|
+
if (this.Television.Active === undefined) {
|
|
392
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Active: ${this.Television.Active}`);
|
|
408
393
|
} else {
|
|
409
|
-
this.accessory.context.Active = this.Active;
|
|
410
|
-
this.
|
|
411
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic Active: ${this.Active}`);
|
|
394
|
+
this.accessory.context.Active = this.Television.Active;
|
|
395
|
+
this.Television.Service.updateCharacteristic(this.hap.Characteristic.Active, this.Television.Active);
|
|
396
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic Active: ${this.Television.Active}`);
|
|
412
397
|
}
|
|
413
398
|
// ActiveIdentifier
|
|
414
|
-
if (this.ActiveIdentifier === undefined) {
|
|
415
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} ActiveIdentifier: ${this.ActiveIdentifier}`);
|
|
416
|
-
} else {
|
|
417
|
-
this.accessory.context.ActiveIdentifier = this.ActiveIdentifier;
|
|
418
|
-
this.tvService?.updateCharacteristic(this.hap.Characteristic.ActiveIdentifier, this.ActiveIdentifier);
|
|
419
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName}` + ` updateCharacteristic ActiveIdentifier: ${this.ActiveIdentifier}`);
|
|
420
|
-
}
|
|
421
|
-
}
|
|
422
|
-
|
|
423
|
-
async disablePushOnChanges(device: irdevice & irDevicesConfig): Promise<void> {
|
|
424
|
-
if (device.disablePushOn === undefined) {
|
|
425
|
-
this.disablePushOn = false;
|
|
426
|
-
} else {
|
|
427
|
-
this.disablePushOn = device.disablePushOn;
|
|
428
|
-
}
|
|
429
|
-
}
|
|
430
|
-
|
|
431
|
-
async disablePushOffChanges(device: irdevice & irDevicesConfig): Promise<void> {
|
|
432
|
-
if (device.disablePushOff === undefined) {
|
|
433
|
-
this.disablePushOff = false;
|
|
434
|
-
} else {
|
|
435
|
-
this.disablePushOff = device.disablePushOff;
|
|
436
|
-
}
|
|
437
|
-
}
|
|
438
|
-
|
|
439
|
-
async disablePushDetailChanges(device: irdevice & irDevicesConfig): Promise<void> {
|
|
440
|
-
if (device.disablePushDetail === undefined) {
|
|
441
|
-
this.disablePushDetail = false;
|
|
442
|
-
} else {
|
|
443
|
-
this.disablePushDetail = device.disablePushDetail;
|
|
444
|
-
}
|
|
445
|
-
}
|
|
446
|
-
|
|
447
|
-
async commandType(): Promise<string> {
|
|
448
|
-
let commandType: string;
|
|
449
|
-
if (this.device.customize) {
|
|
450
|
-
commandType = 'customize';
|
|
451
|
-
} else {
|
|
452
|
-
commandType = 'command';
|
|
453
|
-
}
|
|
454
|
-
return commandType;
|
|
455
|
-
}
|
|
456
|
-
|
|
457
|
-
async commandOn(): Promise<string> {
|
|
458
|
-
let command: string;
|
|
459
|
-
if (this.device.customize && this.device.customOn) {
|
|
460
|
-
command = this.device.customOn;
|
|
399
|
+
if (this.Television.ActiveIdentifier === undefined) {
|
|
400
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} ActiveIdentifier: ${this.Television.ActiveIdentifier}`);
|
|
461
401
|
} else {
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
async commandOff(): Promise<string> {
|
|
468
|
-
let command: string;
|
|
469
|
-
if (this.device.customize && this.device.customOff) {
|
|
470
|
-
command = this.device.customOff;
|
|
471
|
-
} else {
|
|
472
|
-
command = 'turnOff';
|
|
473
|
-
}
|
|
474
|
-
return command;
|
|
475
|
-
}
|
|
476
|
-
|
|
477
|
-
async statusCode(statusCode: number): Promise<void> {
|
|
478
|
-
switch (statusCode) {
|
|
479
|
-
case 151:
|
|
480
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Command not supported by this deviceType, statusCode: ${statusCode}`);
|
|
481
|
-
break;
|
|
482
|
-
case 152:
|
|
483
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Device not found, statusCode: ${statusCode}`);
|
|
484
|
-
break;
|
|
485
|
-
case 160:
|
|
486
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Command is not supported, statusCode: ${statusCode}`);
|
|
487
|
-
break;
|
|
488
|
-
case 161:
|
|
489
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Device is offline, statusCode: ${statusCode}`);
|
|
490
|
-
break;
|
|
491
|
-
case 171:
|
|
492
|
-
this.errorLog(
|
|
493
|
-
`${this.device.remoteType}: ${this.accessory.displayName} Hub Device is offline, statusCode: ${statusCode}. ` +
|
|
494
|
-
`Hub: ${this.device.hubDeviceId}`,
|
|
495
|
-
);
|
|
496
|
-
break;
|
|
497
|
-
case 190:
|
|
498
|
-
this.errorLog(
|
|
499
|
-
`${this.device.remoteType}: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,` +
|
|
500
|
-
` Or command format is invalid, statusCode: ${statusCode}`,
|
|
501
|
-
);
|
|
502
|
-
break;
|
|
503
|
-
case 100:
|
|
504
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Command successfully sent, statusCode: ${statusCode}`);
|
|
505
|
-
break;
|
|
506
|
-
case 200:
|
|
507
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Request successful, statusCode: ${statusCode}`);
|
|
508
|
-
break;
|
|
509
|
-
case 400:
|
|
510
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Bad Request, The client has issued an invalid request. `
|
|
511
|
-
+ `This is commonly used to specify validation errors in a request payload, statusCode: ${statusCode}`);
|
|
512
|
-
break;
|
|
513
|
-
case 401:
|
|
514
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Unauthorized, Authorization for the API is required, `
|
|
515
|
-
+ `but the request has not been authenticated, statusCode: ${statusCode}`);
|
|
516
|
-
break;
|
|
517
|
-
case 403:
|
|
518
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Forbidden, The request has been authenticated but does not `
|
|
519
|
-
+ `have appropriate permissions, or a requested resource is not found, statusCode: ${statusCode}`);
|
|
520
|
-
break;
|
|
521
|
-
case 404:
|
|
522
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Not Found, Specifies the requested path does not exist, `
|
|
523
|
-
+ `statusCode: ${statusCode}`);
|
|
524
|
-
break;
|
|
525
|
-
case 406:
|
|
526
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Not Acceptable, The client has requested a MIME type via `
|
|
527
|
-
+ `the Accept header for a value not supported by the server, statusCode: ${statusCode}`);
|
|
528
|
-
break;
|
|
529
|
-
case 415:
|
|
530
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Unsupported Media Type, The client has defined a contentType `
|
|
531
|
-
+ `header that is not supported by the server, statusCode: ${statusCode}`);
|
|
532
|
-
break;
|
|
533
|
-
case 422:
|
|
534
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Unprocessable Entity, The client has made a valid request, but `
|
|
535
|
-
+ `the server cannot process it. This is often used for APIs for which certain limits have been exceeded, statusCode: ${statusCode}`);
|
|
536
|
-
break;
|
|
537
|
-
case 429:
|
|
538
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Too Many Requests, The client has exceeded the number of `
|
|
539
|
-
+ `requests allowed for a given time window, statusCode: ${statusCode}`);
|
|
540
|
-
break;
|
|
541
|
-
case 500:
|
|
542
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Internal Server Error, An unexpected error on the SmartThings `
|
|
543
|
-
+ `servers has occurred. These errors should be rare, statusCode: ${statusCode}`);
|
|
544
|
-
break;
|
|
545
|
-
default:
|
|
546
|
-
this.infoLog(
|
|
547
|
-
`${this.device.remoteType}: ${this.accessory.displayName} Unknown statusCode: ` +
|
|
548
|
-
`${statusCode}, Submit Bugs Here: ' + 'https://tinyurl.com/SwitchBotBug`,
|
|
549
|
-
);
|
|
402
|
+
this.accessory.context.ActiveIdentifier = this.Television.ActiveIdentifier;
|
|
403
|
+
this.Television.Service.updateCharacteristic(this.hap.Characteristic.ActiveIdentifier, this.Television.ActiveIdentifier);
|
|
404
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic`
|
|
405
|
+
+ ` ActiveIdentifier: ${this.Television.ActiveIdentifier}`);
|
|
550
406
|
}
|
|
551
407
|
}
|
|
552
408
|
|
|
553
409
|
async apiError(e: any): Promise<void> {
|
|
554
|
-
this.
|
|
555
|
-
this.
|
|
556
|
-
}
|
|
557
|
-
|
|
558
|
-
async deviceContext() {
|
|
559
|
-
if (this.Active === undefined) {
|
|
560
|
-
this.Active = this.hap.Characteristic.Active.INACTIVE;
|
|
561
|
-
} else {
|
|
562
|
-
this.Active = this.accessory.context.Active;
|
|
563
|
-
}
|
|
564
|
-
if (this.ActiveIdentifier === undefined) {
|
|
565
|
-
this.ActiveIdentifier = 1;
|
|
566
|
-
} else {
|
|
567
|
-
this.ActiveIdentifier = this.accessory.context.ActiveIdentifier;
|
|
568
|
-
}
|
|
569
|
-
if (this.FirmwareRevision === undefined) {
|
|
570
|
-
this.FirmwareRevision = this.platform.version;
|
|
571
|
-
this.accessory.context.FirmwareRevision = this.FirmwareRevision;
|
|
572
|
-
}
|
|
573
|
-
}
|
|
574
|
-
|
|
575
|
-
async deviceConfig(device: irdevice & irDevicesConfig): Promise<void> {
|
|
576
|
-
let config = {};
|
|
577
|
-
if (device.irtv) {
|
|
578
|
-
config = device.irtv;
|
|
579
|
-
}
|
|
580
|
-
if (device.logging !== undefined) {
|
|
581
|
-
config['logging'] = device.logging;
|
|
582
|
-
}
|
|
583
|
-
if (device.connectionType !== undefined) {
|
|
584
|
-
config['connectionType'] = device.connectionType;
|
|
585
|
-
}
|
|
586
|
-
if (device.external !== undefined) {
|
|
587
|
-
config['external'] = device.external;
|
|
588
|
-
}
|
|
589
|
-
if (device.customOn !== undefined) {
|
|
590
|
-
config['customOn'] = device.customOn;
|
|
591
|
-
}
|
|
592
|
-
if (device.customOff !== undefined) {
|
|
593
|
-
config['customOff'] = device.customOff;
|
|
594
|
-
}
|
|
595
|
-
if (device.customize !== undefined) {
|
|
596
|
-
config['customize'] = device.customize;
|
|
597
|
-
}
|
|
598
|
-
if (device.disablePushOn !== undefined) {
|
|
599
|
-
config['disablePushOn'] = device.disablePushOn;
|
|
600
|
-
}
|
|
601
|
-
if (device.disablePushOff !== undefined) {
|
|
602
|
-
config['disablePushOff'] = device.disablePushOff;
|
|
603
|
-
}
|
|
604
|
-
if (device.disablePushDetail !== undefined) {
|
|
605
|
-
config['disablePushDetail'] = device.disablePushDetail;
|
|
606
|
-
}
|
|
607
|
-
if (Object.entries(config).length !== 0) {
|
|
608
|
-
this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
|
|
609
|
-
}
|
|
610
|
-
}
|
|
611
|
-
|
|
612
|
-
async deviceLogs(device: irdevice & irDevicesConfig): Promise<void> {
|
|
613
|
-
if (this.platform.debugMode) {
|
|
614
|
-
this.deviceLogging = this.accessory.context.logging = 'debugMode';
|
|
615
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
|
|
616
|
-
} else if (device.logging) {
|
|
617
|
-
this.deviceLogging = this.accessory.context.logging = device.logging;
|
|
618
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
|
|
619
|
-
} else if (this.platform.config.options?.logging) {
|
|
620
|
-
this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
|
|
621
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
|
|
622
|
-
} else {
|
|
623
|
-
this.deviceLogging = this.accessory.context.logging = 'standard';
|
|
624
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`);
|
|
625
|
-
}
|
|
626
|
-
}
|
|
627
|
-
|
|
628
|
-
/**
|
|
629
|
-
* Logging for Device
|
|
630
|
-
*/
|
|
631
|
-
infoLog(...log: any[]): void {
|
|
632
|
-
if (this.enablingDeviceLogging()) {
|
|
633
|
-
this.platform.log.info(String(...log));
|
|
634
|
-
}
|
|
635
|
-
}
|
|
636
|
-
|
|
637
|
-
warnLog(...log: any[]): void {
|
|
638
|
-
if (this.enablingDeviceLogging()) {
|
|
639
|
-
this.platform.log.warn(String(...log));
|
|
640
|
-
}
|
|
641
|
-
}
|
|
642
|
-
|
|
643
|
-
debugWarnLog(...log: any[]): void {
|
|
644
|
-
if (this.enablingDeviceLogging()) {
|
|
645
|
-
if (this.deviceLogging?.includes('debug')) {
|
|
646
|
-
this.platform.log.warn('[DEBUG]', String(...log));
|
|
647
|
-
}
|
|
648
|
-
}
|
|
649
|
-
}
|
|
650
|
-
|
|
651
|
-
errorLog(...log: any[]): void {
|
|
652
|
-
if (this.enablingDeviceLogging()) {
|
|
653
|
-
this.platform.log.error(String(...log));
|
|
654
|
-
}
|
|
655
|
-
}
|
|
656
|
-
|
|
657
|
-
debugErrorLog(...log: any[]): void {
|
|
658
|
-
if (this.enablingDeviceLogging()) {
|
|
659
|
-
if (this.deviceLogging?.includes('debug')) {
|
|
660
|
-
this.platform.log.error('[DEBUG]', String(...log));
|
|
661
|
-
}
|
|
662
|
-
}
|
|
663
|
-
}
|
|
664
|
-
|
|
665
|
-
debugLog(...log: any[]): void {
|
|
666
|
-
if (this.enablingDeviceLogging()) {
|
|
667
|
-
if (this.deviceLogging === 'debug') {
|
|
668
|
-
this.platform.log.info('[DEBUG]', String(...log));
|
|
669
|
-
} else {
|
|
670
|
-
this.platform.log.debug(String(...log));
|
|
671
|
-
}
|
|
672
|
-
}
|
|
673
|
-
}
|
|
674
|
-
|
|
675
|
-
enablingDeviceLogging(): boolean {
|
|
676
|
-
return this.deviceLogging.includes('debug') || this.deviceLogging === 'standard';
|
|
410
|
+
this.Television.Service.updateCharacteristic(this.hap.Characteristic.Active, e);
|
|
411
|
+
this.Television.Service.updateCharacteristic(this.hap.Characteristic.ActiveIdentifier, e);
|
|
677
412
|
}
|
|
678
413
|
}
|