homebridge-plejd 1.3.8 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +10 -2
- package/config.schema.json +2 -2
- package/dist/{plejdPlatformAccessory.d.ts → PlejdHbAccessory.d.ts} +5 -5
- package/dist/{plejdPlatformAccessory.js → PlejdHbAccessory.js} +8 -27
- package/dist/PlejdHbAccessory.js.map +1 -0
- package/dist/{plejdPlatform.d.ts → PlejdHbPlatform.d.ts} +9 -9
- package/dist/{plejdPlatform.js → PlejdHbPlatform.js} +30 -43
- package/dist/PlejdHbPlatform.js.map +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/dist/plejdApi.d.ts +4 -8
- package/dist/plejdApi.js +70 -118
- package/dist/plejdApi.js.map +1 -1
- package/dist/plejdService.d.ts +20 -17
- package/dist/plejdService.js +140 -199
- package/dist/plejdService.js.map +1 -1
- package/dist/plejdUtils.js +8 -8
- package/dist/settings.d.ts +2 -1
- package/dist/settings.js +2 -1
- package/dist/settings.js.map +1 -1
- package/dist/utils.d.ts +1 -0
- package/dist/utils.js +2 -0
- package/dist/utils.js.map +1 -0
- package/package.json +3 -6
- package/dist/plejdPlatform.js.map +0 -1
- package/dist/plejdPlatformAccessory.js.map +0 -1
package/CHANGELOG.md
CHANGED
@@ -1,8 +1,16 @@
|
|
1
|
-
#### 1.
|
1
|
+
#### 1.4.0 (2024-06-21)
|
2
|
+
|
3
|
+
Move to async/await paradigm and fix flickering ouccuring when updating device brightness from home assistant and other sources.
|
4
|
+
|
5
|
+
#### 1.3.9 (2024-06-21)
|
6
|
+
|
7
|
+
Clear out dependencies & refactor
|
8
|
+
|
9
|
+
#### 1.3.8 (2024-06-20)
|
2
10
|
|
3
11
|
Updated plejd ble characteristict
|
4
12
|
|
5
|
-
#### 1.3.
|
13
|
+
#### 1.3.7 (2024-06-20)
|
6
14
|
|
7
15
|
Fix import issues and update configurations
|
8
16
|
|
package/config.schema.json
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
"pluginAlias": "Plejd",
|
3
3
|
"pluginType": "platform",
|
4
4
|
"headerDisplay": "Plejd Setup",
|
5
|
-
"footerDisplay": "Either use your login or add devices and crypto key manually.",
|
5
|
+
"footerDisplay": "Either use your login or add devices and crypto key manually. Crypto key and device info is printed as debug logs at startup",
|
6
6
|
"singular": true,
|
7
7
|
"schema": {
|
8
8
|
"username": {
|
@@ -79,4 +79,4 @@
|
|
79
79
|
}
|
80
80
|
}
|
81
81
|
}
|
82
|
-
}
|
82
|
+
}
|
@@ -1,18 +1,18 @@
|
|
1
|
-
import { PlatformAccessory } from
|
2
|
-
import { Device } from
|
3
|
-
import {
|
1
|
+
import { PlatformAccessory } from 'homebridge';
|
2
|
+
import { Device } from './model/device.js';
|
3
|
+
import { PlejdHbPlatform } from './PlejdHbPlatform.js';
|
4
4
|
/**
|
5
5
|
* Platform Accessory
|
6
6
|
* An instance of this class is created for each accessory your platform registers
|
7
7
|
* Each accessory may expose multiple services of different service types.
|
8
8
|
*/
|
9
|
-
export declare class
|
9
|
+
export declare class PlejdHbAccessory {
|
10
10
|
private readonly platform;
|
11
11
|
private readonly accessory;
|
12
12
|
readonly device: Device;
|
13
13
|
private service;
|
14
14
|
private state;
|
15
|
-
constructor(platform:
|
15
|
+
constructor(platform: PlejdHbPlatform, accessory: PlatformAccessory, device: Device);
|
16
16
|
updateState: (isOn: boolean, brightness?: number) => void;
|
17
17
|
private setOn;
|
18
18
|
private getOn;
|
@@ -1,10 +1,10 @@
|
|
1
|
-
import { PLATFORM_NAME } from
|
1
|
+
import { PLATFORM_NAME } from './settings.js';
|
2
2
|
/**
|
3
3
|
* Platform Accessory
|
4
4
|
* An instance of this class is created for each accessory your platform registers
|
5
5
|
* Each accessory may expose multiple services of different service types.
|
6
6
|
*/
|
7
|
-
export class
|
7
|
+
export class PlejdHbAccessory {
|
8
8
|
platform;
|
9
9
|
accessory;
|
10
10
|
device;
|
@@ -14,7 +14,6 @@ export class PlejdPlatformAccessoryHandler {
|
|
14
14
|
this.platform = platform;
|
15
15
|
this.accessory = accessory;
|
16
16
|
this.device = device;
|
17
|
-
platform.log.debug(`Adding handler for a ${this.device.model} with id ${this.device.identifier}`);
|
18
17
|
this.state = {
|
19
18
|
brightness: accessory.context.brightness ?? 100,
|
20
19
|
isOn: accessory.context.isOn ?? false,
|
@@ -48,40 +47,22 @@ export class PlejdPlatformAccessoryHandler {
|
|
48
47
|
this.service.setCharacteristic(this.platform.Characteristic.Name, this.device.name);
|
49
48
|
}
|
50
49
|
updateState = (isOn, brightness) => {
|
50
|
+
this.platform.log.debug(`Updating Homekit state from ${this.device.name} device state`);
|
51
51
|
this.state.isOn = isOn;
|
52
|
-
this.platform.log.debug("updateState | Sending isOn", isOn);
|
53
52
|
this.service
|
54
53
|
.getCharacteristic(this.platform.Characteristic.On)
|
55
54
|
.updateValue(isOn);
|
56
55
|
if (brightness) {
|
57
56
|
this.state.brightness = Math.round(brightness);
|
58
|
-
this.platform.log.debug("update state | Sending brightness", this.state.brightness);
|
59
57
|
this.service
|
60
58
|
.getCharacteristic(this.platform.Characteristic.Brightness)
|
61
59
|
.updateValue(this.state.brightness);
|
62
60
|
}
|
63
61
|
this.accessory.context = this.state;
|
64
|
-
this.platform.log.debug(`State updated | ${JSON.stringify(this.state)}`);
|
65
|
-
};
|
66
|
-
setOn = async (value) => {
|
67
|
-
const newVal = value;
|
68
|
-
this.platform.log.info(`Updating state | ${this.device.name} | to ${newVal ? "On" : "off"} | from ${this.state.isOn ? "On" : "Off"}`);
|
69
|
-
this.updateState(newVal, this.state.brightness);
|
70
|
-
this.platform.plejdService?.updateState(this.device.identifier, newVal, null);
|
71
|
-
};
|
72
|
-
getOn = async () => {
|
73
|
-
this.platform.log.debug("Get Characteristic On", this.device.name, this.state.isOn);
|
74
|
-
return this.state.isOn;
|
75
|
-
};
|
76
|
-
setBrightness = async (value) => {
|
77
|
-
const newVal = value; // Number between 1-100
|
78
|
-
this.platform.log.debug(`Updating brightness | ${this.device.name} | to ${newVal} | from ${this.state.brightness}`);
|
79
|
-
this.updateState(this.state.isOn, newVal);
|
80
|
-
this.platform.plejdService?.updateState(this.device.identifier, this.state.isOn, newVal);
|
81
|
-
};
|
82
|
-
getBrightness = async () => {
|
83
|
-
this.platform.log.debug("Get Characteristic Brightness", this.device.name, this.state.brightness);
|
84
|
-
return this.state.brightness;
|
85
62
|
};
|
63
|
+
setOn = async (value) => await this.platform.plejdService?.updateState(this.device.identifier, value, null);
|
64
|
+
getOn = () => this.state.isOn;
|
65
|
+
setBrightness = async (value) => await this.platform.plejdService?.updateState(this.device.identifier, this.state.isOn, value);
|
66
|
+
getBrightness = () => this.state.brightness;
|
86
67
|
}
|
87
|
-
//# sourceMappingURL=
|
68
|
+
//# sourceMappingURL=PlejdHbAccessory.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"PlejdHbAccessory.js","sourceRoot":"","sources":["../src/PlejdHbAccessory.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAO9C;;;;GAIG;AACH,MAAM,OAAO,gBAAgB;IAKR;IACA;IACD;IANV,OAAO,CAAU;IACjB,KAAK,CAAc;IAE3B,YACmB,QAAyB,EACzB,SAA4B,EAC7B,MAAc;QAFb,aAAQ,GAAR,QAAQ,CAAiB;QACzB,cAAS,GAAT,SAAS,CAAmB;QAC7B,WAAM,GAAN,MAAM,CAAQ;QAE9B,IAAI,CAAC,KAAK,GAAG;YACX,UAAU,EAAE,SAAS,CAAC,OAAO,CAAC,UAAU,IAAI,GAAG;YAC/C,IAAI,EAAE,SAAS,CAAC,OAAO,CAAC,IAAI,IAAI,KAAK;SACtC,CAAC;QAEF,4BAA4B;QAC5B,IAAI,CAAC,SAAS;aACX,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,oBAAoB,CAAE;aACvD,iBAAiB,CAChB,IAAI,CAAC,QAAQ,CAAC,cAAc,CAAC,YAAY,EACzC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,MAAM,IAAI,CAAC,QAAQ,CAAC,YAAY,EAAE,WAAW,CACzG,IAAI,CAAC,MAAM,CAAC,UAAU,EACtB,IAAI,CAAC,KAAK,CAAC,IAAI,EACf,KAAe,CAChB,CAAC;IAEM,aAAa,GAAG,GAAwB,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC;CAC1E"}
|
@@ -1,10 +1,10 @@
|
|
1
|
-
import { API, DynamicPlatformPlugin, Logger, PlatformAccessory, PlatformConfig, Service, Characteristic } from
|
2
|
-
import {
|
3
|
-
import { UserInputConfig } from
|
4
|
-
import { Device } from
|
5
|
-
import { PlejdService } from
|
6
|
-
import { Site } from
|
7
|
-
export declare class
|
1
|
+
import { API, DynamicPlatformPlugin, Logger, PlatformAccessory, PlatformConfig, Service, Characteristic } from 'homebridge';
|
2
|
+
import { PlejdHbAccessory } from './PlejdHbAccessory.js';
|
3
|
+
import { UserInputConfig } from './model/userInputConfig.js';
|
4
|
+
import { Device } from './model/device.js';
|
5
|
+
import { PlejdService } from './plejdService.js';
|
6
|
+
import { Site } from './model/plejdSite.js';
|
7
|
+
export declare class PlejdHbPlatform implements DynamicPlatformPlugin {
|
8
8
|
readonly log: Logger;
|
9
9
|
readonly config: PlatformConfig;
|
10
10
|
readonly homebridgeApi: API;
|
@@ -13,9 +13,9 @@ export declare class PlejdPlatform implements DynamicPlatformPlugin {
|
|
13
13
|
userInputConfig?: UserInputConfig;
|
14
14
|
plejdService?: PlejdService;
|
15
15
|
readonly accessories: PlatformAccessory[];
|
16
|
-
readonly
|
16
|
+
readonly plejdHbAccessories: PlejdHbAccessory[];
|
17
17
|
constructor(log: Logger, config: PlatformConfig, homebridgeApi: API);
|
18
|
-
configurePlejd: () => void
|
18
|
+
configurePlejd: () => Promise<void>;
|
19
19
|
configureDevices: (log: Logger, config: PlatformConfig, site?: Site) => void;
|
20
20
|
/**
|
21
21
|
* This function is invoked when homebridge restores cached accessories from disk at startup.
|
@@ -1,8 +1,8 @@
|
|
1
|
-
import { PLATFORM_NAME, PLEJD_ADDONS, PLEJD_LIGHTS, PLUGIN_NAME, } from
|
2
|
-
import {
|
3
|
-
import { PlejdService } from
|
4
|
-
import PlejdRemoteApi from
|
5
|
-
export class
|
1
|
+
import { PLATFORM_NAME, PLEJD_ADDONS, PLEJD_LIGHTS, PLUGIN_NAME, } from './settings.js';
|
2
|
+
import { PlejdHbAccessory } from './PlejdHbAccessory.js';
|
3
|
+
import { PlejdService } from './plejdService.js';
|
4
|
+
import PlejdRemoteApi from './plejdApi.js';
|
5
|
+
export class PlejdHbPlatform {
|
6
6
|
log;
|
7
7
|
config;
|
8
8
|
homebridgeApi;
|
@@ -12,34 +12,31 @@ export class PlejdPlatform {
|
|
12
12
|
plejdService;
|
13
13
|
// this is used to track restored cached accessories
|
14
14
|
accessories = [];
|
15
|
-
|
15
|
+
plejdHbAccessories = [];
|
16
16
|
constructor(log, config, homebridgeApi) {
|
17
17
|
this.log = log;
|
18
18
|
this.config = config;
|
19
19
|
this.homebridgeApi = homebridgeApi;
|
20
|
-
|
21
|
-
homebridgeApi.on("didFinishLaunching", this.configurePlejd);
|
20
|
+
homebridgeApi.on('didFinishLaunching', this.configurePlejd);
|
22
21
|
this.Characteristic = homebridgeApi.hap.Characteristic;
|
23
22
|
this.Service = homebridgeApi.hap.Service;
|
24
23
|
}
|
25
|
-
configurePlejd = () => {
|
24
|
+
configurePlejd = async () => {
|
26
25
|
if (this.config.password && this.config.site && this.config.username) {
|
27
|
-
this.log.info(
|
28
|
-
|
26
|
+
this.log.info('Using login information to fetch devices & crypto key\n' +
|
27
|
+
'Any devices added manually will override the remote site information');
|
29
28
|
const pApi = new PlejdRemoteApi(this.log, this.config.site, this.config.username, this.config.password, true);
|
30
|
-
pApi
|
31
|
-
|
32
|
-
.then((site) => this.configureDevices(this.log, this.config, site))
|
33
|
-
.catch((e) => this.log.error(`Plejd remote access error: ${e}`));
|
29
|
+
const site = await pApi.getPlejdRemoteSite();
|
30
|
+
this.configureDevices(this.log, this.config, site);
|
34
31
|
}
|
35
32
|
else if (this.config.crypto_key &&
|
36
33
|
this.config.devices &&
|
37
34
|
this.config.devices.count > 0) {
|
38
|
-
this.log.info(
|
35
|
+
this.log.info('Using supplied crypto key & devices');
|
39
36
|
this.configureDevices(this.log, this.config, undefined);
|
40
37
|
}
|
41
38
|
else {
|
42
|
-
this.log.warn(
|
39
|
+
this.log.warn('No settings are prepared, either supply crypto key & devices OR username, password & site');
|
43
40
|
}
|
44
41
|
};
|
45
42
|
configureDevices = (log, config, site) => {
|
@@ -58,7 +55,7 @@ export class PlejdPlatform {
|
|
58
55
|
}
|
59
56
|
const room = site.rooms.find((x) => x.roomId === item.roomId);
|
60
57
|
let identifier = site.inputAddress[id][0];
|
61
|
-
if (dim.endsWith(
|
58
|
+
if (dim.endsWith('-02') &&
|
62
59
|
items.find((a) => a.identifier === identifier) !== undefined) {
|
63
60
|
identifier += 1;
|
64
61
|
}
|
@@ -77,7 +74,7 @@ export class PlejdPlatform {
|
|
77
74
|
const pre = devices.findIndex((x) => x.identifier === item.identifier);
|
78
75
|
if (pre !== -1) {
|
79
76
|
if (devices[pre].hidden) {
|
80
|
-
log.debug(
|
77
|
+
log.debug('Hiding device |', devices[pre]);
|
81
78
|
devices.splice(pre);
|
82
79
|
}
|
83
80
|
else {
|
@@ -94,25 +91,25 @@ export class PlejdPlatform {
|
|
94
91
|
devices[i].isDimmer = PLEJD_LIGHTS.includes(devices[i].model);
|
95
92
|
}
|
96
93
|
else {
|
97
|
-
log.error(
|
94
|
+
log.error('Missing device model |', devices[i].name);
|
98
95
|
}
|
99
96
|
if (devices[i].identifier) {
|
100
97
|
devices[i].uuid = this.generateId(devices[i].identifier.toString());
|
101
98
|
}
|
102
99
|
else {
|
103
|
-
log.error(
|
100
|
+
log.error('Missing device identifier |', devices[i].name);
|
104
101
|
}
|
105
102
|
}
|
106
103
|
if (!config.crypto_key) {
|
107
|
-
log.error(
|
104
|
+
log.error('No Crypto key was found in the configuration. Check the plugin documentation for more info');
|
108
105
|
}
|
109
|
-
const cryptoKey = Buffer.from(config.crypto_key.replace(/-/g,
|
106
|
+
const cryptoKey = Buffer.from(config.crypto_key.replace(/-/g, ''), 'hex');
|
110
107
|
this.userInputConfig = {
|
111
108
|
devices: devices,
|
112
109
|
cryptoKey: cryptoKey,
|
113
110
|
};
|
114
|
-
log.
|
115
|
-
log.
|
111
|
+
log.debug('Plejd Crypto Key:', config.crypto_key);
|
112
|
+
log.debug('Plejd Devices connected to HomeKit:', this.userInputConfig.devices);
|
116
113
|
this.plejdService = new PlejdService(this.userInputConfig, log, this.onPlejdUpdates.bind(this));
|
117
114
|
this.discoverDevices();
|
118
115
|
};
|
@@ -121,7 +118,6 @@ export class PlejdPlatform {
|
|
121
118
|
* It should be used to setup event handlers for characteristics and update respective values.
|
122
119
|
*/
|
123
120
|
configureAccessory = (accessory) => {
|
124
|
-
this.log.info("Loading accessory from cache | ", accessory.displayName);
|
125
121
|
this.accessories.push(accessory);
|
126
122
|
};
|
127
123
|
discoverDevices = () => {
|
@@ -130,14 +126,13 @@ export class PlejdPlatform {
|
|
130
126
|
if (notRegistered.length > 0) {
|
131
127
|
this.homebridgeApi.unregisterPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, notRegistered);
|
132
128
|
}
|
133
|
-
this.log.debug("registering devices", this.userInputConfig?.devices);
|
134
129
|
for (const device of this.userInputConfig.devices) {
|
135
130
|
if (device.hidden) {
|
136
131
|
continue;
|
137
132
|
}
|
138
133
|
const existingAccessory = this.accessories.find((accessory) => accessory.UUID === device.uuid);
|
139
134
|
if (existingAccessory) {
|
140
|
-
this.
|
135
|
+
this.plejdHbAccessories.push(new PlejdHbAccessory(this, existingAccessory, device));
|
141
136
|
}
|
142
137
|
else {
|
143
138
|
this.addNewDevice(device);
|
@@ -145,15 +140,10 @@ export class PlejdPlatform {
|
|
145
140
|
}
|
146
141
|
};
|
147
142
|
addNewDevice = (device) => {
|
148
|
-
let name = device.name;
|
149
|
-
this.log.info("Adding new accessory |", name);
|
150
|
-
if (device.room) {
|
151
|
-
name = device.room + " - " + name;
|
152
|
-
}
|
153
143
|
const accessory = new this.homebridgeApi.platformAccessory(device.name, device.uuid);
|
154
144
|
accessory.context.device = device;
|
155
145
|
// See above.
|
156
|
-
this.
|
146
|
+
this.plejdHbAccessories.push(new PlejdHbAccessory(this, accessory, device));
|
157
147
|
// link the accessory to your platform
|
158
148
|
this.homebridgeApi.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [
|
159
149
|
accessory,
|
@@ -170,16 +160,16 @@ export class PlejdPlatform {
|
|
170
160
|
}
|
171
161
|
const existingAccessory = this.accessories.find((accessory) => accessory.UUID === uuid);
|
172
162
|
const device = this.userInputConfig.devices.find((dev) => dev.identifier === identifier);
|
173
|
-
const
|
174
|
-
if (existingAccessory && device &&
|
163
|
+
const plejdHbAccessory = this.plejdHbAccessories.find((dev) => dev.device.identifier === identifier);
|
164
|
+
if (existingAccessory && device && plejdHbAccessory) {
|
175
165
|
if (device.isDimmer) {
|
176
166
|
const ser = existingAccessory.getService(this.Service.Lightbulb);
|
177
167
|
if (!ser) {
|
178
|
-
this.log.warn(
|
168
|
+
this.log.warn('Unable to get service');
|
179
169
|
}
|
180
170
|
const on = ser?.getCharacteristic(this.Characteristic.On);
|
181
171
|
if (!on) {
|
182
|
-
this.log.warn(
|
172
|
+
this.log.warn('Unable to get Characteristic [On]');
|
183
173
|
}
|
184
174
|
on?.updateValue(isOn);
|
185
175
|
if (brightness !== undefined) {
|
@@ -194,20 +184,17 @@ export class PlejdPlatform {
|
|
194
184
|
?.getCharacteristic(this.Characteristic.On)
|
195
185
|
?.updateValue(isOn);
|
196
186
|
}
|
197
|
-
|
187
|
+
plejdHbAccessory.updateState(isOn, brightness);
|
198
188
|
}
|
199
189
|
else {
|
200
190
|
if (device) {
|
201
191
|
this.addNewDevice(device);
|
202
192
|
this.onPlejdUpdates(identifier, isOn, brightness);
|
203
193
|
}
|
204
|
-
else {
|
205
|
-
this.log.info("Unable find HomKit device associated with incoming Plejd update |", device);
|
206
|
-
}
|
207
194
|
}
|
208
195
|
};
|
209
196
|
generateId = (input) => {
|
210
197
|
return this.homebridgeApi.hap.uuid.generate(input);
|
211
198
|
};
|
212
199
|
}
|
213
|
-
//# sourceMappingURL=
|
200
|
+
//# sourceMappingURL=PlejdHbPlatform.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"PlejdHbPlatform.js","sourceRoot":"","sources":["../src/PlejdHbPlatform.ts"],"names":[],"mappings":"AAUA,OAAO,EACL,aAAa,EACb,YAAY,EACZ,YAAY,EACZ,WAAW,GACZ,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAGzD,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,cAAc,MAAM,eAAe,CAAC;AAG3C,MAAM,OAAO,eAAe;IAaR;IACA;IACA;IAdF,OAAO,CAAiB;IACxB,cAAc,CAAwB;IAE/C,eAAe,CAAmB;IAClC,YAAY,CAAgB;IAEnC,oDAAoD;IACpC,WAAW,GAAwB,EAAE,CAAC;IAEtC,kBAAkB,GAAuB,EAAE,CAAC;IAE5D,YACkB,GAAW,EACX,MAAsB,EACtB,aAAkB;QAFlB,QAAG,GAAH,GAAG,CAAQ;QACX,WAAM,GAAN,MAAM,CAAgB;QACtB,kBAAa,GAAb,aAAa,CAAK;QAElC,aAAa,CAAC,EAAE,CAAC,oBAAoB,EAAE,IAAI,CAAC,cAAc,CAAC,CAAC;QAC5D,IAAI,CAAC,cAAc,GAAG,aAAa,CAAC,GAAG,CAAC,cAAc,CAAC;QACvD,IAAI,CAAC,OAAO,GAAG,aAAa,CAAC,GAAG,CAAC,OAAO,CAAC;IAC3C,CAAC;IAED,cAAc,GAAG,KAAK,IAAI,EAAE;QAC1B,IAAI,IAAI,CAAC,MAAM,CAAC,QAAQ,IAAI,IAAI,CAAC,MAAM,CAAC,IAAI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 +1,9 @@
|
|
1
|
-
import { PLATFORM_NAME, PLUGIN_NAME } from
|
2
|
-
import {
|
1
|
+
import { PLATFORM_NAME, PLUGIN_NAME } from './settings.js';
|
2
|
+
import { PlejdHbPlatform } from './PlejdHbPlatform.js';
|
3
3
|
/**
|
4
4
|
* This method registers the platform with Homebridge
|
5
5
|
*/
|
6
6
|
export default (api) => {
|
7
|
-
api.registerPlatform(PLUGIN_NAME, PLATFORM_NAME,
|
7
|
+
api.registerPlatform(PLUGIN_NAME, PLATFORM_NAME, PlejdHbPlatform);
|
8
8
|
};
|
9
9
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC3D,OAAO,EAAE,
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC3D,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAEvD;;GAEG;AACH,eAAe,CAAC,GAAQ,EAAE,EAAE;IAC1B,GAAG,CAAC,gBAAgB,CAAC,WAAW,EAAE,aAAa,EAAE,eAAe,CAAC,CAAC;AACpE,CAAC,CAAC"}
|
package/dist/plejdApi.d.ts
CHANGED
@@ -1,17 +1,13 @@
|
|
1
|
-
|
2
|
-
import
|
3
|
-
|
4
|
-
import { Site } from "./model/plejdSite.js";
|
5
|
-
export default class PlejdRemoteApi extends EventEmitter {
|
1
|
+
import { Logger } from 'homebridge';
|
2
|
+
import { Site } from './model/plejdSite.js';
|
3
|
+
export default class PlejdRemoteApi {
|
6
4
|
log: Logger;
|
7
5
|
siteName: string;
|
8
6
|
username: string;
|
9
7
|
password: string;
|
10
8
|
includeRoomsAsLights: boolean;
|
11
|
-
sessionToken?: string;
|
12
|
-
site?: Site;
|
13
9
|
constructor(log: Logger, siteName: string, username: string, password: string, includeRoomsAsLights: boolean);
|
14
|
-
getPlejdRemoteSite
|
10
|
+
getPlejdRemoteSite(): Promise<Site>;
|
15
11
|
private login;
|
16
12
|
private getSites;
|
17
13
|
private getSite;
|
package/dist/plejdApi.js
CHANGED
@@ -1,143 +1,95 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
const
|
4
|
-
const
|
5
|
-
const
|
6
|
-
|
7
|
-
const API_SITE_DETAILS_URL = "functions/getSiteById";
|
8
|
-
export default class PlejdRemoteApi extends EventEmitter {
|
1
|
+
const API_APP_ID = 'zHtVqXt8k4yFyk2QGmgp48D9xZr2G94xWYnF4dak';
|
2
|
+
const API_BASE_URL = 'https://cloud.plejd.com/parse/';
|
3
|
+
const API_LOGIN_URL = 'login';
|
4
|
+
const API_SITE_LIST_URL = 'functions/getSiteList';
|
5
|
+
const API_SITE_DETAILS_URL = 'functions/getSiteById';
|
6
|
+
export default class PlejdRemoteApi {
|
9
7
|
log;
|
10
8
|
siteName;
|
11
9
|
username;
|
12
10
|
password;
|
13
11
|
includeRoomsAsLights;
|
14
|
-
sessionToken;
|
15
|
-
site;
|
16
12
|
constructor(log, siteName, username, password, includeRoomsAsLights) {
|
17
|
-
super();
|
18
13
|
this.log = log;
|
19
14
|
this.includeRoomsAsLights = includeRoomsAsLights;
|
20
15
|
this.siteName = siteName;
|
21
16
|
this.username = username;
|
22
17
|
this.password = password;
|
23
18
|
}
|
24
|
-
getPlejdRemoteSite
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
resolve(site);
|
33
|
-
})
|
34
|
-
.catch((e) => {
|
35
|
-
this.log.error(`${e}`);
|
36
|
-
reject(e);
|
37
|
-
});
|
38
|
-
})
|
39
|
-
.catch((e) => {
|
40
|
-
this.log.error(`${e}`);
|
41
|
-
reject(e);
|
42
|
-
});
|
43
|
-
})
|
44
|
-
.catch((e) => {
|
45
|
-
this.log.error(`${e}`);
|
46
|
-
reject(e);
|
47
|
-
});
|
48
|
-
});
|
49
|
-
};
|
50
|
-
login = () => {
|
51
|
-
const instance = axios.create({
|
52
|
-
baseURL: API_BASE_URL,
|
19
|
+
async getPlejdRemoteSite() {
|
20
|
+
const token = await this.login();
|
21
|
+
const site = await this.getSites(token);
|
22
|
+
return await this.getSite(site, token);
|
23
|
+
}
|
24
|
+
async login() {
|
25
|
+
const response = await fetch(API_BASE_URL + API_LOGIN_URL, {
|
26
|
+
method: 'POST',
|
53
27
|
headers: {
|
54
|
-
|
55
|
-
|
28
|
+
'X-Parse-Application-Id': API_APP_ID,
|
29
|
+
'Content-Type': 'application/json',
|
56
30
|
},
|
57
|
-
|
58
|
-
return new Promise((resolve, reject) => {
|
59
|
-
instance
|
60
|
-
.post(API_LOGIN_URL, {
|
31
|
+
body: JSON.stringify({
|
61
32
|
username: this.username,
|
62
33
|
password: this.password,
|
63
|
-
})
|
64
|
-
.then((response) => {
|
65
|
-
this.log.debug("plejd-api: got session token response");
|
66
|
-
this.sessionToken = response.data.sessionToken;
|
67
|
-
if (!this.sessionToken) {
|
68
|
-
reject("no session token received.");
|
69
|
-
return;
|
70
|
-
}
|
71
|
-
resolve(response.data.sessionToken);
|
72
|
-
})
|
73
|
-
.catch((error) => {
|
74
|
-
if (error.response.status === 400) {
|
75
|
-
reject("error: server returned status 400. probably invalid credentials, please verify.");
|
76
|
-
}
|
77
|
-
else {
|
78
|
-
reject("error: unable to retrieve session token response: " + error);
|
79
|
-
}
|
80
|
-
});
|
34
|
+
}),
|
81
35
|
});
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
36
|
+
if (!response.ok) {
|
37
|
+
if (response.status === 400) {
|
38
|
+
throw new Error('error: server returned status 400. probably invalid credentials, please verify.');
|
39
|
+
}
|
40
|
+
else {
|
41
|
+
throw new Error('error: unable to retrieve session token response: ' + response.statusText);
|
42
|
+
}
|
43
|
+
}
|
44
|
+
const data = await response.json();
|
45
|
+
if (!data.sessionToken) {
|
46
|
+
throw new Error('no session token received.');
|
47
|
+
}
|
48
|
+
return data.sessionToken;
|
49
|
+
}
|
50
|
+
async getSites(token) {
|
51
|
+
const response = await fetch(API_BASE_URL + API_SITE_LIST_URL, {
|
52
|
+
method: 'POST',
|
86
53
|
headers: {
|
87
|
-
|
88
|
-
|
89
|
-
|
54
|
+
'X-Parse-Application-Id': API_APP_ID,
|
55
|
+
'X-Parse-Session-Token': token,
|
56
|
+
'Content-Type': 'application/json',
|
90
57
|
},
|
91
58
|
});
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
.catch((error) => {
|
106
|
-
return reject("plejd-api: unable to retrieve list of sites. error: " + error);
|
107
|
-
});
|
108
|
-
});
|
109
|
-
};
|
110
|
-
getSite = (site) => {
|
111
|
-
const instance = axios.create({
|
112
|
-
baseURL: API_BASE_URL,
|
59
|
+
if (!response.ok) {
|
60
|
+
throw new Error('plejd-api: unable to retrieve list of sites. error: ' + response.statusText);
|
61
|
+
}
|
62
|
+
const data = await response.json();
|
63
|
+
const site = data.result.find((x) => x.site.title === this.siteName);
|
64
|
+
if (!site) {
|
65
|
+
throw new Error('failed to find a site named ' + this.siteName);
|
66
|
+
}
|
67
|
+
return site;
|
68
|
+
}
|
69
|
+
async getSite(site, token) {
|
70
|
+
const response = await fetch(API_BASE_URL + API_SITE_DETAILS_URL, {
|
71
|
+
method: 'POST',
|
113
72
|
headers: {
|
114
|
-
|
115
|
-
|
116
|
-
|
73
|
+
'X-Parse-Application-Id': API_APP_ID,
|
74
|
+
'X-Parse-Session-Token': token,
|
75
|
+
'Content-Type': 'application/json',
|
117
76
|
},
|
77
|
+
body: JSON.stringify({ siteId: site.site.siteId }),
|
118
78
|
});
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
reject("No Crypto has been retrieved yet");
|
135
|
-
}
|
136
|
-
})
|
137
|
-
.catch((error) => {
|
138
|
-
return reject("plejd-api: unable to retrieve the crypto key. error: " + error);
|
139
|
-
});
|
140
|
-
});
|
141
|
-
};
|
79
|
+
if (!response.ok) {
|
80
|
+
throw new Error('plejd-api: unable to retrieve the crypto key. error: ' + response.statusText);
|
81
|
+
}
|
82
|
+
const data = await response.json();
|
83
|
+
if (data.result.length === 0) {
|
84
|
+
throw new Error('No devices found');
|
85
|
+
}
|
86
|
+
const res = data.result[0];
|
87
|
+
if (res) {
|
88
|
+
return res;
|
89
|
+
}
|
90
|
+
else {
|
91
|
+
throw new Error('No Crypto has been retrieved yet');
|
92
|
+
}
|
93
|
+
}
|
142
94
|
}
|
143
95
|
//# sourceMappingURL=plejdApi.js.map
|