@switchbot/homebridge-switchbot 0.1.2-beta.7 → 0.2.0-alpha.1

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 (106) hide show
  1. package/.github/ISSUE_TEMPLATE/feature-request.yml +1 -1
  2. package/.github/dependabot.yml +2 -0
  3. package/.github/workflows/codeql-analysis.yml +71 -0
  4. package/CHANGELOG.md +5 -1
  5. package/README.md +2 -1
  6. package/config.schema.json +420 -471
  7. package/dist/devices/bots.d.ts +19 -5
  8. package/dist/devices/bots.d.ts.map +1 -1
  9. package/dist/devices/bots.js +172 -148
  10. package/dist/devices/bots.js.map +1 -1
  11. package/dist/devices/bulb.d.ts +8 -6
  12. package/dist/devices/bulb.d.ts.map +1 -1
  13. package/dist/devices/bulb.js +45 -28
  14. package/dist/devices/bulb.js.map +1 -1
  15. package/dist/devices/contact.d.ts +10 -5
  16. package/dist/devices/contact.d.ts.map +1 -1
  17. package/dist/devices/contact.js +94 -63
  18. package/dist/devices/contact.js.map +1 -1
  19. package/dist/devices/curtains.d.ts +14 -5
  20. package/dist/devices/curtains.d.ts.map +1 -1
  21. package/dist/devices/curtains.js +174 -120
  22. package/dist/devices/curtains.js.map +1 -1
  23. package/dist/devices/humidifiers.d.ts +6 -6
  24. package/dist/devices/humidifiers.d.ts.map +1 -1
  25. package/dist/devices/humidifiers.js +78 -94
  26. package/dist/devices/humidifiers.js.map +1 -1
  27. package/dist/devices/indoorcam.d.ts +43 -0
  28. package/dist/devices/indoorcam.d.ts.map +1 -0
  29. package/dist/devices/indoorcam.js +241 -0
  30. package/dist/devices/indoorcam.js.map +1 -0
  31. package/dist/devices/meters.d.ts +8 -5
  32. package/dist/devices/meters.d.ts.map +1 -1
  33. package/dist/devices/meters.js +126 -92
  34. package/dist/devices/meters.js.map +1 -1
  35. package/dist/devices/motion.d.ts +9 -5
  36. package/dist/devices/motion.d.ts.map +1 -1
  37. package/dist/devices/motion.js +74 -59
  38. package/dist/devices/motion.js.map +1 -1
  39. package/dist/devices/plugs.d.ts +5 -4
  40. package/dist/devices/plugs.d.ts.map +1 -1
  41. package/dist/devices/plugs.js +65 -56
  42. package/dist/devices/plugs.js.map +1 -1
  43. package/dist/irdevices/airconditioners.d.ts +3 -3
  44. package/dist/irdevices/airconditioners.d.ts.map +1 -1
  45. package/dist/irdevices/airconditioners.js +12 -7
  46. package/dist/irdevices/airconditioners.js.map +1 -1
  47. package/dist/irdevices/airpurifiers.d.ts +3 -3
  48. package/dist/irdevices/airpurifiers.d.ts.map +1 -1
  49. package/dist/irdevices/airpurifiers.js +1 -1
  50. package/dist/irdevices/airpurifiers.js.map +1 -1
  51. package/dist/irdevices/cameras.d.ts +3 -3
  52. package/dist/irdevices/cameras.d.ts.map +1 -1
  53. package/dist/irdevices/cameras.js +1 -1
  54. package/dist/irdevices/cameras.js.map +1 -1
  55. package/dist/irdevices/fans.d.ts +3 -3
  56. package/dist/irdevices/fans.d.ts.map +1 -1
  57. package/dist/irdevices/fans.js +11 -12
  58. package/dist/irdevices/fans.js.map +1 -1
  59. package/dist/irdevices/lights.d.ts +3 -3
  60. package/dist/irdevices/lights.d.ts.map +1 -1
  61. package/dist/irdevices/lights.js +1 -1
  62. package/dist/irdevices/lights.js.map +1 -1
  63. package/dist/irdevices/others.d.ts +3 -3
  64. package/dist/irdevices/others.d.ts.map +1 -1
  65. package/dist/irdevices/others.js +8 -8
  66. package/dist/irdevices/others.js.map +1 -1
  67. package/dist/irdevices/tvs.d.ts +3 -3
  68. package/dist/irdevices/tvs.d.ts.map +1 -1
  69. package/dist/irdevices/tvs.js +16 -6
  70. package/dist/irdevices/tvs.js.map +1 -1
  71. package/dist/irdevices/vacuumcleaners.d.ts +3 -3
  72. package/dist/irdevices/vacuumcleaners.d.ts.map +1 -1
  73. package/dist/irdevices/vacuumcleaners.js +2 -3
  74. package/dist/irdevices/vacuumcleaners.js.map +1 -1
  75. package/dist/irdevices/waterheaters.d.ts +3 -3
  76. package/dist/irdevices/waterheaters.d.ts.map +1 -1
  77. package/dist/irdevices/waterheaters.js +2 -2
  78. package/dist/irdevices/waterheaters.js.map +1 -1
  79. package/dist/platform.d.ts +14 -5
  80. package/dist/platform.d.ts.map +1 -1
  81. package/dist/platform.js +420 -418
  82. package/dist/platform.js.map +1 -1
  83. package/dist/settings.d.ts +18 -15
  84. package/dist/settings.d.ts.map +1 -1
  85. package/package.json +65 -65
  86. package/src/devices/bots.ts +188 -165
  87. package/src/devices/bulb.ts +48 -40
  88. package/src/devices/contact.ts +100 -73
  89. package/src/devices/curtains.ts +192 -140
  90. package/src/devices/humidifiers.ts +82 -124
  91. package/src/devices/indoorcam.ts +303 -0
  92. package/src/devices/meters.ts +130 -110
  93. package/src/devices/motion.ts +80 -69
  94. package/src/devices/plugs.ts +67 -65
  95. package/src/irdevices/airconditioners.ts +14 -10
  96. package/src/irdevices/airpurifiers.ts +4 -4
  97. package/src/irdevices/cameras.ts +4 -4
  98. package/src/irdevices/fans.ts +14 -18
  99. package/src/irdevices/lights.ts +4 -4
  100. package/src/irdevices/others.ts +12 -14
  101. package/src/irdevices/tvs.ts +21 -10
  102. package/src/irdevices/vacuumcleaners.ts +5 -9
  103. package/src/irdevices/waterheaters.ts +5 -5
  104. package/src/platform.ts +455 -619
  105. package/src/settings.ts +19 -15
  106. package/.github/workflows/issue-validate.yml +0 -18
@@ -0,0 +1,241 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.IndoorCam = void 0;
4
+ const rxjs_1 = require("rxjs");
5
+ const operators_1 = require("rxjs/operators");
6
+ const settings_1 = require("../settings");
7
+ class IndoorCam {
8
+ constructor(platform, accessory, device) {
9
+ this.platform = platform;
10
+ this.accessory = accessory;
11
+ this.device = device;
12
+ // default placeholders
13
+ this.On = false;
14
+ this.OutletInUse = true;
15
+ // BLE Connections
16
+ if (device.ble) {
17
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
18
+ const SwitchBot = require('node-switchbot');
19
+ this.switchbot = new SwitchBot();
20
+ const colon = device.deviceId.match(/.{1,2}/g);
21
+ const bleMac = colon.join(':'); //returns 1A:23:B4:56:78:9A;
22
+ this.device.bleMac = bleMac.toLowerCase();
23
+ this.platform.device(this.device.bleMac.toLowerCase());
24
+ }
25
+ // this is subject we use to track when we need to POST changes to the SwitchBot API
26
+ this.doCameraUpdate = new rxjs_1.Subject();
27
+ this.cameraUpdateInProgress = false;
28
+ // Retrieve initial values and updateHomekit
29
+ this.refreshStatus();
30
+ // set accessory information
31
+ accessory
32
+ .getService(this.platform.Service.AccessoryInformation)
33
+ .setCharacteristic(this.platform.Characteristic.Manufacturer, 'SwitchBot')
34
+ .setCharacteristic(this.platform.Characteristic.Model, 'SWITCHBOT-CAMERA-')
35
+ .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId);
36
+ // get the WindowCovering service if it exists, otherwise create a new WindowCovering service
37
+ // you can create multiple services for each accessory
38
+ (this.service =
39
+ accessory.getService(this.platform.Service.Outlet) ||
40
+ accessory.addService(this.platform.Service.Outlet)), `${accessory.displayName} Indoor Camera`;
41
+ // To avoid "Cannot add a Service with the same UUID another Service without also defining a unique 'subtype' property." error,
42
+ // when creating multiple services of the same type, you need to use the following syntax to specify a name and subtype id:
43
+ // accessory.getService('NAME') ?? accessory.addService(this.platform.Service.Lightbulb, 'NAME', 'USER_DEFINED_SUBTYPE');
44
+ // set the service name, this is what is displayed as the default name on the Home app
45
+ // in this example we are using the name we stored in the `accessory.context` in the `discoverDevices` method.
46
+ this.service.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
47
+ // each service must implement at-minimum the "required characteristics" for the given service type
48
+ // see https://developers.homebridge.io/#/service/WindowCovering
49
+ // create handlers for required characteristics
50
+ this.service.getCharacteristic(this.platform.Characteristic.On).onSet(this.OnSet.bind(this));
51
+ this.service.setCharacteristic(this.platform.Characteristic.OutletInUse, this.OutletInUse || true);
52
+ // Update Homekit
53
+ this.updateHomeKitCharacteristics();
54
+ // Start an update interval
55
+ (0, rxjs_1.interval)(this.platform.config.options.refreshRate * 1000)
56
+ .pipe((0, operators_1.skipWhile)(() => this.cameraUpdateInProgress))
57
+ .subscribe(() => {
58
+ this.refreshStatus();
59
+ });
60
+ // Watch for Camera change events
61
+ // We put in a debounce of 100ms so we don't make duplicate calls
62
+ this.doCameraUpdate
63
+ .pipe((0, operators_1.tap)(() => {
64
+ this.cameraUpdateInProgress = true;
65
+ }), (0, operators_1.debounceTime)(this.platform.config.options.pushRate * 1000))
66
+ .subscribe(async () => {
67
+ try {
68
+ await this.pushChanges();
69
+ }
70
+ catch (e) {
71
+ this.platform.log.error(JSON.stringify(e.message));
72
+ this.platform.debug(`Camera ${accessory.displayName} - ${JSON.stringify(e)}`);
73
+ this.apiError(e);
74
+ }
75
+ this.cameraUpdateInProgress = false;
76
+ });
77
+ }
78
+ parseStatus() {
79
+ switch (this.deviceStatus.body.power) {
80
+ case 'on':
81
+ this.On = true;
82
+ break;
83
+ default:
84
+ this.On = false;
85
+ }
86
+ this.platform.debug(`Camera ${this.accessory.displayName} On: ${this.On}`);
87
+ }
88
+ async refreshStatus() {
89
+ if (this.device.ble) {
90
+ this.platform.device('BLE');
91
+ await this.BLErefreshStatus();
92
+ }
93
+ else {
94
+ this.platform.device('OpenAPI');
95
+ await this.openAPIRefreshStatus();
96
+ }
97
+ }
98
+ async BLErefreshStatus() {
99
+ this.platform.debug('IndoorCam BLE Device RefreshStatus');
100
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
101
+ const Switchbot = require('node-switchbot');
102
+ const switchbot = new Switchbot();
103
+ const colon = this.device.deviceId.match(/.{1,2}/g);
104
+ const bleMac = colon.join(':'); //returns 1A:23:B4:56:78:9A;
105
+ this.device.bleMac = bleMac.toLowerCase();
106
+ this.platform.device(this.device.bleMac);
107
+ switchbot.onadvertisement = (ad) => {
108
+ this.platform.debug(JSON.stringify(ad, null, ' '));
109
+ this.platform.device(`ad: ${JSON.stringify(ad)}`);
110
+ };
111
+ switchbot
112
+ .startScan({
113
+ id: this.device.bleMac,
114
+ })
115
+ .then(() => {
116
+ return switchbot.wait(this.platform.config.options.refreshRate * 1000);
117
+ })
118
+ .then(() => {
119
+ switchbot.stopScan();
120
+ })
121
+ .catch(async (error) => {
122
+ this.platform.log.error(error);
123
+ await this.openAPIRefreshStatus();
124
+ });
125
+ setInterval(() => {
126
+ this.platform.log.info('Start scan ' + this.device.deviceName + '(' + this.device.bleMac + ')');
127
+ switchbot
128
+ .startScan({
129
+ mode: 'T',
130
+ id: bleMac,
131
+ })
132
+ .then(() => {
133
+ return switchbot.wait(this.platform.config.options.refreshRate * 1000);
134
+ })
135
+ .then(() => {
136
+ switchbot.stopScan();
137
+ this.platform.log.info('Stop scan ' + this.device.deviceName + '(' + this.device.bleMac + ')');
138
+ })
139
+ .catch(async (error) => {
140
+ this.platform.log.error(error);
141
+ await this.openAPIRefreshStatus();
142
+ });
143
+ }, this.platform.config.options.refreshRate * 60000);
144
+ }
145
+ async openAPIRefreshStatus() {
146
+ try {
147
+ this.deviceStatus = (await this.platform.axios.get(`${settings_1.DeviceURL}/${this.device.deviceId}/status`)).data;
148
+ this.platform.device(`Camera ${this.accessory.displayName} refreshStatus: ${JSON.stringify(this.deviceStatus)}`);
149
+ this.parseStatus();
150
+ this.updateHomeKitCharacteristics();
151
+ }
152
+ catch (e) {
153
+ this.platform.log.error(`IndoorCam ${this.accessory.displayName} failed to refresh status, Error Message: ${JSON.stringify(e.message)}`);
154
+ this.platform.debug(`IndoorCam ${this.accessory.displayName}, Error: ${JSON.stringify(e)}`);
155
+ this.apiError(e);
156
+ }
157
+ }
158
+ /**
159
+ * Pushes the requested changes to the SwitchBot API
160
+ * deviceType commandType Command command parameter Description
161
+ * Camera - "command" "turnOff" "default" = set to OFF state
162
+ * Camera - "command" "turnOn" "default" = set to ON state
163
+ */
164
+ async pushChanges() {
165
+ const payload = {
166
+ commandType: 'command',
167
+ parameter: 'default',
168
+ };
169
+ if (this.On) {
170
+ payload.command = 'turnOn';
171
+ }
172
+ else {
173
+ payload.command = 'turnOff';
174
+ }
175
+ this.platform.log.info('Sending request for', this.accessory.displayName, 'to SwitchBot API. command:', payload.command, 'parameter:', payload.parameter, 'commandType:', payload.commandType);
176
+ this.platform.debug(`Camera ${this.accessory.displayName} pushchanges: ${JSON.stringify(payload)}`);
177
+ // Make the API request
178
+ const push = await this.platform.axios.post(`${settings_1.DeviceURL}/${this.device.deviceId}/commands`, payload);
179
+ this.platform.debug(`Camera ${this.accessory.displayName} Changes pushed: ${JSON.stringify(push.data)}`);
180
+ this.statusCode(push);
181
+ }
182
+ updateHomeKitCharacteristics() {
183
+ if (this.On === undefined) {
184
+ this.platform.debug(`Camera ${this.accessory.displayName} On: ${this.On}`);
185
+ }
186
+ else {
187
+ this.service.updateCharacteristic(this.platform.Characteristic.On, this.On);
188
+ this.platform.device(`Camera ${this.accessory.displayName} updateCharacteristic On: ${this.On}`);
189
+ }
190
+ if (this.OutletInUse === undefined) {
191
+ this.platform.debug(`Camera ${this.accessory.displayName} OutletInUse: ${this.OutletInUse}`);
192
+ }
193
+ else {
194
+ this.service.updateCharacteristic(this.platform.Characteristic.OutletInUse, this.OutletInUse);
195
+ this.platform.device(`Camera ${this.accessory.displayName} updateCharacteristic OutletInUse: ${this.OutletInUse}`);
196
+ }
197
+ }
198
+ apiError(e) {
199
+ this.service.updateCharacteristic(this.platform.Characteristic.On, e);
200
+ this.service.updateCharacteristic(this.platform.Characteristic.OutletInUse, e);
201
+ }
202
+ statusCode(push) {
203
+ switch (push.data.statusCode) {
204
+ case 151:
205
+ this.platform.log.error('Command not supported by this device type.');
206
+ break;
207
+ case 152:
208
+ this.platform.log.error('Device not found.');
209
+ break;
210
+ case 160:
211
+ this.platform.log.error('Command is not supported.');
212
+ break;
213
+ case 161:
214
+ this.platform.log.error('Device is offline.');
215
+ break;
216
+ case 171:
217
+ this.platform.log.error('Hub Device is offline.');
218
+ break;
219
+ case 190:
220
+ this.platform.log.error('Device internal error due to device states not synchronized with server. Or command fomrat is invalid.');
221
+ break;
222
+ case 100:
223
+ if (this.platform.config.options?.debug) {
224
+ this.platform.log.info('Command successfully sent.');
225
+ }
226
+ break;
227
+ default:
228
+ this.platform.debug('Unknown statusCode.');
229
+ }
230
+ }
231
+ /**
232
+ * Handle requests to set the value of the "On" characteristic
233
+ */
234
+ OnSet(value) {
235
+ this.platform.debug(`Camera ${this.accessory.displayName} - Set On: ${value}`);
236
+ this.On = value;
237
+ this.doCameraUpdate.next();
238
+ }
239
+ }
240
+ exports.IndoorCam = IndoorCam;
241
+ //# sourceMappingURL=indoorcam.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"indoorcam.js","sourceRoot":"","sources":["../../src/devices/indoorcam.ts"],"names":[],"mappings":";;;AAEA,+BAAyC;AACzC,8CAA8D;AAC9D,0CAA+D;AAE/D,MAAa,SAAS;IA6BpB,YACmB,QAA2B,EACpC,SAA4B,EAC7B,MAA8B;QAFpB,aAAQ,GAAR,QAAQ,CAAmB;QACpC,cAAS,GAAT,SAAS,CAAmB;QAC7B,WAAM,GAAN,MAAM,CAAwB;QAErC,uBAAuB;QACvB,IAAI,CAAC,EAAE,GAAG,KAAK,CAAC;QAChB,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;QAExB,kBAAkB;QAClB,IAAI,MAAM,CAAC,GAAG,EAAE;YACd,8DAA8D;YAC9D,MAAM,SAAS,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC;YAC5C,IAAI,CAAC,SAAS,GAAG,IAAI,SAAS,EAAE,CAAC;YACjC,MAAM,KAAK,GAAG,MAAM,CAAC,QAAS,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;YAChD,MAAM,MAAM,GAAG,KAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,4BAA4B;YAC7D,IAAI,CAAC,MAAM,CAAC,MAAM,GAAG,MAAM,CAAC,WAAW,EAAE,CAAC;YAC1C,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,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@
1
1
  import { Service, PlatformAccessory, CharacteristicValue, MacAddress } from 'homebridge';
2
2
  import { SwitchBotPlatform } from '../platform';
3
- import { device, deviceStatusResponse } from '../settings';
3
+ import { device, devicesConfig } from '../settings';
4
4
  /**
5
5
  * Platform Accessory
6
6
  * An instance of this class is created for each accessory your platform registers
@@ -9,7 +9,7 @@ import { device, deviceStatusResponse } from '../settings';
9
9
  export declare class Meter {
10
10
  private readonly platform;
11
11
  private accessory;
12
- device: device;
12
+ device: device & devicesConfig;
13
13
  private service;
14
14
  temperatureservice?: Service;
15
15
  humidityservice?: Service;
@@ -20,7 +20,7 @@ export declare class Meter {
20
20
  StatusLowBattery: CharacteristicValue;
21
21
  Active: CharacteristicValue;
22
22
  WaterLevel: CharacteristicValue;
23
- deviceStatus: deviceStatusResponse;
23
+ deviceStatus: any;
24
24
  BLEtemperature: number;
25
25
  BLEHumidity: number;
26
26
  switchbot: {
@@ -34,15 +34,18 @@ export declare class Meter {
34
34
  };
35
35
  meterUpdateInProgress: boolean;
36
36
  doMeterUpdate: any;
37
- constructor(platform: SwitchBotPlatform, accessory: PlatformAccessory, device: device);
37
+ constructor(platform: SwitchBotPlatform, accessory: PlatformAccessory, device: device & devicesConfig);
38
38
  /**
39
39
  * Parse the device status from the SwitchBot api
40
40
  */
41
- parseStatus(): void;
41
+ parseStatus(): Promise<void>;
42
+ private BLEparseStatus;
43
+ private openAPIparseStatus;
42
44
  /**
43
45
  * Asks the SwitchBot API for the latest device information
44
46
  */
45
47
  refreshStatus(): Promise<void>;
48
+ private BLErefreshStatus;
46
49
  private openAPIRefreshStatus;
47
50
  /**
48
51
  * Updates the status for each of the HomeKit Characteristics
@@ -1 +1 @@
1
- {"version":3,"file":"meters.d.ts","sourceRoot":"","sources":["../../src/devices/meters.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,iBAAiB,EAAS,mBAAmB,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAChG,OAAO,EAAE,iBAAiB,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