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 CHANGED
@@ -1,8 +1,16 @@
1
- #### 1.3.6 (2024-06-20)
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.6 (2024-06-20)
13
+ #### 1.3.7 (2024-06-20)
6
14
 
7
15
  Fix import issues and update configurations
8
16
 
@@ -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 "homebridge";
2
- import { Device } from "./model/device.js";
3
- import { PlejdPlatform } from "./plejdPlatform.js";
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 PlejdPlatformAccessoryHandler {
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: PlejdPlatform, accessory: PlatformAccessory, device: Device);
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 "./settings.js";
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 PlejdPlatformAccessoryHandler {
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=plejdPlatformAccessory.js.map
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;aAC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AAI,CAAC;IAEnD,aAAa,GAAG,KAAK,EAAE,KAA0B,EAAE,EAAE,CAAC,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 "homebridge";
2
- import { PlejdPlatformAccessoryHandler } from "./plejdPlatformAccessory.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 PlejdPlatform implements DynamicPlatformPlugin {
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 plejdHandlers: PlejdPlatformAccessoryHandler[];
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 "./settings.js";
2
- import { PlejdPlatformAccessoryHandler } from "./plejdPlatformAccessory.js";
3
- import { PlejdService } from "./plejdService.js";
4
- import PlejdRemoteApi from "./plejdApi.js";
5
- export class PlejdPlatform {
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
- plejdHandlers = [];
15
+ plejdHbAccessories = [];
16
16
  constructor(log, config, homebridgeApi) {
17
17
  this.log = log;
18
18
  this.config = config;
19
19
  this.homebridgeApi = homebridgeApi;
20
- this.log.debug("Finished initializing platform:", this.config.platform);
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("Using login information to fetch devices & crypto key");
28
- this.log.info("Any devices added manually will update the downloaded devices");
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
- .getPlejdRemoteSite()
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("Using supplied crypto key & devices");
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("No settings are prepared, either supply crypto key & devices OR username, password & site");
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("-02") &&
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("Hiding device |", devices[pre]);
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("Missing device model |", devices[i].name);
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("Missing device identifier |", devices[i].name);
100
+ log.error('Missing device identifier |', devices[i].name);
104
101
  }
105
102
  }
106
103
  if (!config.crypto_key) {
107
- log.error("No Crypto key was found in the configuration. Check the plugin documentation for more info");
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, ""), "hex");
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.info("Plejd Crypto Key:", config.crypto_key);
115
- log.info("Plejd Devices connected to HomeKit:", this.userInputConfig.devices);
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.plejdHandlers.push(new PlejdPlatformAccessoryHandler(this, existingAccessory, device));
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.plejdHandlers.push(new PlejdPlatformAccessoryHandler(this, accessory, device));
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 plejdHandler = this.plejdHandlers.find((dev) => dev.device.identifier === identifier);
174
- if (existingAccessory && device && plejdHandler) {
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("Unable to get service");
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("Unable to get Characteristic [On]");
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
- plejdHandler.updateState(isOn, brightness);
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=plejdPlatform.js.map
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,IAAI,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC;YACrE,IAAI,CAAC,GAAG,CAAC,IAAI,CACX,yDAAyD;gBACzD,sEAAsE,CAAC,CAAC;YAC1E,MAAM,IAAI,GAAG,IAAI,cAAc,CA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AAc,CAAC,EAAE,CAAC,CAAC;gBAE1D,IAAI,CAAC,EAAE,EAAE,CAAC;oBACR,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,mCAAmC,CAAC,CAAC;gBACrD,CAAC;gBAED,EAAE,EAAE,WAAW,CAAC,IAAI,CAAC,CAAC;gBAEtB,IAAI,UAAU,KAAK,SAAS,EAAE,CAAC;oBAC7B,GAAG;wBACD,EAAE,iBAAiB,CAAC,IAAI,CAAC,cAAc,CAAC,UAAU,CAAC;yBAClD,WAAW,CAAC,UAAU,CAAC,CAAC;gBAC7B,CAAC;YACH,CAAC;iBAAM,CAAC;gBACN,iBAAiB;qBACd,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC;oBAChC,EAAE,iBAAiB,CAAC,IAAI,CAAC,cAAc,CAAC,EAAE,CAAC;oBAC3C,EAAE,WAAW,CAAC,IAAI,CAAC,CAAC;YACxB,CAAC;YAED,gBAAgB,CAAC,WAAW,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;QACjD,CAAC;aAAM,CAAC;YACN,IAAI,MAAM,EAAE,CAAC;gBACX,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;gBAC1B,IAAI,CAAC,cAAc,CAAC,UAAU,EAAE,IAAI,EAAE,UAAU,CAAC,CAAC;YACpD,CAAC;QACH,CAAC;IACH,CAAC,CAAC;IAEM,UAAU,GAAG,CAAC,KAAa,EAAU,EAAE;QAC7C,OAAO,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IACrD,CAAC,CAAC;CACH"}
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { API } from "homebridge";
1
+ import { API } from 'homebridge';
2
2
  /**
3
3
  * This method registers the platform with Homebridge
4
4
  */
package/dist/index.js CHANGED
@@ -1,9 +1,9 @@
1
- import { PLATFORM_NAME, PLUGIN_NAME } from "./settings.js";
2
- import { PlejdPlatform } from "./plejdPlatform.js";
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, PlejdPlatform);
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,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD;;GAEG;AACH,eAAe,CAAC,GAAQ,EAAE,EAAE;IAC1B,GAAG,CAAC,gBAAgB,CAAC,WAAW,EAAE,aAAa,EAAE,aAAa,CAAC,CAAC;AAClE,CAAC,CAAC"}
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"}
@@ -1,17 +1,13 @@
1
- /// <reference types="node" />
2
- import EventEmitter from "events";
3
- import { Logger } from "homebridge";
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: () => Promise<Site>;
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
- import axios from "axios";
2
- import EventEmitter from "events";
3
- const API_APP_ID = "zHtVqXt8k4yFyk2QGmgp48D9xZr2G94xWYnF4dak";
4
- const API_BASE_URL = "https://cloud.plejd.com/parse/";
5
- const API_LOGIN_URL = "login";
6
- const API_SITE_LIST_URL = "functions/getSiteList";
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
- return new Promise((resolve, reject) => {
26
- this.login()
27
- .then(() => {
28
- this.getSites()
29
- .then((site) => {
30
- this.getSite(site)
31
- .then((site) => {
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
- "X-Parse-Application-Id": API_APP_ID,
55
- "Content-Type": "application/json",
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
- getSites = () => {
84
- const instance = axios.create({
85
- baseURL: API_BASE_URL,
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
- "X-Parse-Application-Id": API_APP_ID,
88
- "X-Parse-Session-Token": this.sessionToken,
89
- "Content-Type": "application/json",
54
+ 'X-Parse-Application-Id': API_APP_ID,
55
+ 'X-Parse-Session-Token': token,
56
+ 'Content-Type': 'application/json',
90
57
  },
91
58
  });
92
- return new Promise((resolve, reject) => {
93
- this.log.debug("Sending POST to " + API_BASE_URL + API_SITE_LIST_URL);
94
- instance
95
- .post(API_SITE_LIST_URL)
96
- .then((response) => {
97
- this.log.debug("plejd-api: got detailed sites response");
98
- const site = response.data.result.find((x) => x.site.title === this.siteName);
99
- if (!site) {
100
- reject("failed to find a site named " + this.siteName);
101
- return;
102
- }
103
- resolve(site);
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
- "X-Parse-Application-Id": API_APP_ID,
115
- "X-Parse-Session-Token": this.sessionToken,
116
- "Content-Type": "application/json",
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
- return new Promise((resolve, reject) => {
120
- this.log.debug("Sending POST to " + API_BASE_URL + API_SITE_DETAILS_URL);
121
- instance
122
- .post(API_SITE_DETAILS_URL, { siteId: site.site.siteId })
123
- .then((response) => {
124
- this.log.debug("plejd-api: got site details response");
125
- if (response.data.result.length === 0) {
126
- reject("No devices fount");
127
- return;
128
- }
129
- this.site = response.data.result[0];
130
- if (this.site) {
131
- resolve(this.site);
132
- }
133
- else {
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