@evops/lightwaverf 1.0.5 → 1.0.7

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.
@@ -1,5 +1,63 @@
1
1
  import Debug, { Debugger } from "debug";
2
2
  import { LightwaveDevice } from "./LightwaveDevice";
3
+ type LightwaveRfResponse = {
4
+ UserProfile: {
5
+ estate: {};
6
+ location: {};
7
+ room: Record<string, {
8
+ room_id: string;
9
+ name: string;
10
+ created: string;
11
+ updated: string;
12
+ user_id: string;
13
+ location_id: string;
14
+ zone_id: string;
15
+ active: string;
16
+ room_number: string;
17
+ wfl_id: string;
18
+ mood_1: string;
19
+ mood_2: string;
20
+ mood_3: string;
21
+ image_hash: string;
22
+ image_ext: string;
23
+ rank: string;
24
+ zone: [];
25
+ mood: [];
26
+ }>;
27
+ device: Record<string, {
28
+ device_id: string;
29
+ name: string;
30
+ location_id: string;
31
+ room_id: string;
32
+ zone_id: string;
33
+ created: string;
34
+ updated: string;
35
+ user_id: string;
36
+ active: string;
37
+ device_type_id: string;
38
+ device_type_value: string;
39
+ device_number: string;
40
+ wfl_id: string;
41
+ serial: string;
42
+ dm_id: string;
43
+ last_command_id: string;
44
+ last_command: string;
45
+ last_command_value: string;
46
+ rank: string;
47
+ energy_rank: string;
48
+ trigger_rank: string;
49
+ heating_rank: string;
50
+ unit_rate: string;
51
+ device_type_name: string;
52
+ wfl_code: string;
53
+ is_heating: string;
54
+ }>;
55
+ timer: {};
56
+ event: {};
57
+ mood: {};
58
+ user: {};
59
+ };
60
+ };
3
61
  export declare class LightwaveAccount {
4
62
  debug: Debug.Debugger;
5
63
  email: string;
@@ -7,5 +65,6 @@ export declare class LightwaveAccount {
7
65
  mainDebug: Debug.Debugger;
8
66
  constructor(debug: Debugger, email: string, pin: string);
9
67
  getConfiguration(callback?: (devices: LightwaveDevice[], error: any) => void): Promise<LightwaveDevice[] | undefined>;
10
- parseRooms(lightwaveResponse: any, callback?: (devices: LightwaveDevice[], error: Error | null) => void): LightwaveDevice[] | undefined;
68
+ parseRooms(lightwaveResponse: LightwaveRfResponse["UserProfile"], callback?: (devices: LightwaveDevice[], error: Error | null) => void): LightwaveDevice[] | undefined;
11
69
  }
70
+ export {};
@@ -20,11 +20,22 @@ class LightwaveAccount {
20
20
  this.debug("Getting rooms from LightWave");
21
21
  var self = this;
22
22
  var host = "https://control-api.lightwaverf.com";
23
- function assertResponse(response) {
23
+ async function assertResponse(response) {
24
24
  if (!response.ok) {
25
- throw new Error("Network response was not ok: " + response.statusText);
25
+ const responseText = await response.text();
26
+ throw new Error("Network response was not ok: " + response.statusText, {
27
+ cause: responseText,
28
+ });
29
+ }
30
+ try {
31
+ return response.json();
32
+ }
33
+ catch (error) {
34
+ const responseText = await response.text();
35
+ throw new Error("Failed to parse response as JSON", {
36
+ cause: responseText,
37
+ });
26
38
  }
27
- return response.json();
28
39
  }
29
40
  let token = "";
30
41
  try {
@@ -45,7 +56,7 @@ class LightwaveAccount {
45
56
  },
46
57
  });
47
58
  const something = await assertResponse(deviceTypeResponse);
48
- const userProfileResponse = await fetch(host + "/v1/user_profile?nested=1", {
59
+ const userProfileResponse = await fetch(host + "/v1/user_profile?nested=0", {
49
60
  headers: {
50
61
  "X-LWRF-token": token,
51
62
  "X-LWRF-platform": "ios",
@@ -64,13 +75,14 @@ class LightwaveAccount {
64
75
  }
65
76
  }
66
77
  parseRooms(lightwaveResponse, callback) {
67
- this.debug("Parsing lightwaveResponse: ", lightwaveResponse.content.estates[0].locations[0].zones[0].rooms[0]
68
- .devices);
69
- const home = lightwaveResponse.content.estates[0].locations[0].zones[0];
78
+ this.debug("Parsing lightwaveResponse: ", lightwaveResponse.estate);
79
+ const roomInfos = Object.values(lightwaveResponse.room);
80
+ const deviceInfos = Object.values(lightwaveResponse.device);
70
81
  const devices = [];
71
- for (var i = 0; i < home.rooms.length; i++) {
72
- var r = home.rooms[i];
73
- this.debug("Room " + r.name + " with " + r.devices?.length + " devices");
82
+ for (var i = 0; i < roomInfos.length; i++) {
83
+ const roomInfo = roomInfos[i];
84
+ const roomDevices = deviceInfos.filter((d) => d.room_id === roomInfo.room_id);
85
+ this.debug("Room " + roomInfo.name + " with " + roomDevices.length + " devices");
74
86
  // Get device types
75
87
  // O: On/Off Switch
76
88
  // D: Dimmer
@@ -81,12 +93,12 @@ class LightwaveAccount {
81
93
  // M: Mood (active)
82
94
  // o: All Off
83
95
  var deviceTypeMapping = new Map();
84
- deviceTypeMapping.set(1, LightwaveDevice_1.LightwaveDeviceType.OnOff);
85
- deviceTypeMapping.set(2, LightwaveDevice_1.LightwaveDeviceType.Dimmer);
86
- deviceTypeMapping.set(3, LightwaveDevice_1.LightwaveDeviceType.OnOff);
87
- for (var j = 0; j < r.devices?.length; j++) {
88
- var d = r.devices[j];
89
- const device = new LightwaveDevice_1.LightwaveDevice(this.mainDebug, r.room_number, d.device_number, r.name, d.name, deviceTypeMapping.get(d.device_type_id));
96
+ deviceTypeMapping.set("1", LightwaveDevice_1.LightwaveDeviceType.OnOff);
97
+ deviceTypeMapping.set("2", LightwaveDevice_1.LightwaveDeviceType.Dimmer);
98
+ deviceTypeMapping.set("3", LightwaveDevice_1.LightwaveDeviceType.OnOff);
99
+ for (var j = 0; j < roomDevices?.length; j++) {
100
+ const deviceInfo = roomDevices[j];
101
+ const device = new LightwaveDevice_1.LightwaveDevice(this.mainDebug, Number(roomInfo.room_number), Number(deviceInfo.device_number), roomInfo.name, deviceInfo.name, deviceTypeMapping.get(deviceInfo.device_type_id));
90
102
  devices.push(device);
91
103
  }
92
104
  }
@@ -10,7 +10,7 @@ const LightwaveAccount_1 = require("./LightwaveAccount");
10
10
  (0, vitest_1.describe)("LightwaveAccount tests", () => {
11
11
  fetch_vcr_1.default.configure({
12
12
  fixturePath: __dirname + "/.fixtures",
13
- mode: "playback",
13
+ mode: "record",
14
14
  });
15
15
  global.fetch = fetch_vcr_1.default;
16
16
  (0, vitest_1.beforeEach)(() => {
@@ -19,8 +19,8 @@ const LightwaveAccount_1 = require("./LightwaveAccount");
19
19
  debug_1.default.enable(process.env.DEBUG);
20
20
  });
21
21
  (0, vitest_1.it)("should parse configuration into rooms", async () => {
22
- const account = new LightwaveAccount_1.LightwaveAccount((0, debug_1.default)("lightwave-rf:test"), "some@user.com", "1234");
22
+ const account = new LightwaveAccount_1.LightwaveAccount((0, debug_1.default)("lightwave-rf:test"), "stan@wozniak.com", "2212");
23
23
  const devices = await account.getConfiguration();
24
- (0, vitest_1.expect)(devices?.length).toBe(20);
24
+ (0, vitest_1.expect)(devices?.length).toBe(19);
25
25
  });
26
26
  });
@@ -21,17 +21,16 @@ const _1 = __importDefault(require("."));
21
21
  (0, vitest_1.it)("should allow device linking", async () => {
22
22
  lw = new _1.default({
23
23
  email: "some@user.com",
24
- pin: "1234",
24
+ pin: "12341234",
25
25
  });
26
26
  // const devices = await lw.getDevices();
27
27
  await lw.connect();
28
28
  await lw.ensureRegistration();
29
- await lw.lwClient.disconnect();
30
29
  });
31
30
  (0, vitest_1.it)("should turn device on", async () => {
32
31
  lw = new _1.default({
33
32
  email: "some@user.com",
34
- pin: "1234",
33
+ pin: "12341234",
35
34
  // Disabling link display updates as they cause buffer issues in the link
36
35
  // device
37
36
  linkDisplayUpdates: true,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@evops/lightwaverf",
3
3
  "description": "Lightwave RF client library",
4
- "version": "1.0.5",
4
+ "version": "1.0.7",
5
5
  "exports": {
6
6
  ".": {
7
7
  "types": "./.dist/index.d.ts",
package/.dist/Queue.d.ts DELETED
@@ -1,7 +0,0 @@
1
- export declare class Queue<T> {
2
- items: T[];
3
- busy: boolean;
4
- get length(): number;
5
- add(item: T): void;
6
- next(): T | undefined;
7
- }
package/.dist/Queue.js DELETED
@@ -1,17 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Queue = void 0;
4
- class Queue {
5
- items = [];
6
- busy = false;
7
- get length() {
8
- return this.items.length;
9
- }
10
- add(item) {
11
- this.items.push(item);
12
- }
13
- next() {
14
- return this.items.shift();
15
- }
16
- }
17
- exports.Queue = Queue;