@evops/lightwaverf 0.0.6 → 0.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.
package/LICENSE CHANGED
@@ -0,0 +1,7 @@
1
+ Copyright 2022 Evops Limited
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md CHANGED
@@ -1,83 +1,3 @@
1
- node-lightwaverf
2
- ================
3
-
4
- A NodeJS library for controlling devices using the LightwaveRF Wi-Fi Link
5
-
6
- ## Installation
7
-
8
- npm install lightwaverf
9
-
10
- ## Usage
11
-
12
- ### Initialize
13
-
14
- var LightwaveRF = require("lightwaverf");
15
- var lw = new LightwaveRF({ip:"192.168.1.123",email:"name@host.com",pin:"0123"});
16
-
17
- Or to read from a [LightwareRF Gem](https://github.com/pauly/lightwaverf) format YAML file:
18
-
19
- var lw = new LightwaveRF({ip:"192.168.1.123", file:"/a/config/file.yml"});
20
-
21
- ### Turn a device on
22
-
23
- To turn a device on you need to have set it up using the mobile or web app. You need the room ID and the device ID.
24
-
25
- lw.turnDeviceOn(1 /*roomId*/, 1 /*deviceId*/, function(error, content) {
26
- if (error) {
27
- console.log("Error turning device on " + error.message);
28
- } else {
29
- console.log("Response: " + content);
30
- }
31
- });
32
-
33
- ### Turn a device off
34
-
35
- To turn a device off you need to have set it up using the mobile or web app. You need the room ID and the device ID.
36
-
37
- lw.turnDeviceOff(1 /*roomId*/, 1 /*deviceId*/, function(error, content) {
38
- if (error) {
39
- console.log("Error turning device off " + error.message);
40
- } else {
41
- console.log("Response: " + content);
42
- }
43
- });
44
-
45
- ### Dim the device in a room
46
-
47
- To turn a dim the device in a room you need to have set it up using the mobile or web app. You need the room ID and device ID.
48
-
49
- lw.setDeviceDim(1 /*roomId*/, 1 /*deviceId*/, 50 /*percentage from 0-100*/, function(error, content) {
50
- if (error) {
51
- console.log("Error changing dim of device " + error.message);
52
- } else {
53
- console.log("Response: " + content);
54
- }
55
- });
56
-
57
- ### Turn a room off
58
-
59
- To turn a room off you need to have set it up using the mobile or web app. You need the room ID.
60
-
61
- lw.turnRoomOff(1 /*roomId*/, function(error, content) {
62
- if (error) {
63
- console.log("Error turning room off " + error.message);
64
- } else {
65
- console.log("Response: " + content);
66
- }
67
- });
68
-
69
- ### Request the energy status
70
-
71
- To get the current status from the LightwaveRF Energy Monitor Smart Meter you need to have linked it to the Wi-Fi Link first.
72
-
73
- lw.requestEnergy(function(error, data) {
74
- if (error) {
75
- console.log("Error turning device off " + error.message);
76
- } else {
77
- //data: { current: 300, max: 620, today: 850, yesterday: 0 }
78
- console.log("Energy ", data);
79
- }
80
- });
81
-
82
-
1
+ # LightwaveRF client library
83
2
 
3
+ Originally based on https://github.com/ollieparsley/node-lightwaverf
@@ -0,0 +1,159 @@
1
+ /// <reference types="node" />
2
+ import { EventEmitter } from 'events';
3
+ import dgram from 'dgram';
4
+ declare class LightwaveRFConfiguration {
5
+ timeout?: number;
6
+ ip?: string;
7
+ file?: any;
8
+ host?: any;
9
+ email?: any;
10
+ pin?: any;
11
+ }
12
+ interface LightwaveRFDevice {
13
+ roomId: number;
14
+ deviceId: number;
15
+ roomName: string;
16
+ deviceName: string;
17
+ deviceType: string;
18
+ }
19
+ declare interface LightwaveRF {
20
+ on(event: 'deviceTurnedOn', listener: (roomId: number, deviceId: number) => void): this;
21
+ on(event: 'deviceTurnedOff', listener: (roomId: number, deviceId: number) => void): this;
22
+ }
23
+ /**
24
+ * LightwaveRF API
25
+ *
26
+ * @param object config The config
27
+ *
28
+ * An instance of the LightwaveRF API
29
+ */
30
+ declare class LightwaveRF extends EventEmitter {
31
+ timeout: number;
32
+ queue: any;
33
+ ready: boolean;
34
+ awaitRegistrration: boolean;
35
+ currentTransactionNumber: number;
36
+ devices: Array<LightwaveRFDevice>;
37
+ messageCounter: number;
38
+ config: LightwaveRFConfiguration;
39
+ sendSocket: dgram.Socket;
40
+ receiveSocket: dgram.Socket;
41
+ responseListeners: Map<number, any>;
42
+ constructor(config: LightwaveRFConfiguration, callback: (config: any, error: any) => void);
43
+ stop(): void;
44
+ initialiseConfiguration(callback: (config: any, error: string) => void): void;
45
+ /**
46
+ * Register this device with the Wi-Fi Link
47
+ *
48
+ * @param Function callback The callback function
49
+ *
50
+ * @return void
51
+ */
52
+ register(callback: any): void;
53
+ /**
54
+ * Request energy
55
+ *
56
+ * @param Function callback The callback function
57
+ *
58
+ * @return void
59
+ */
60
+ requestEnergy(callback: any): void;
61
+ /**
62
+ * Turn a device off
63
+ *
64
+ * @param integer roomId The room ID
65
+ * @param integer deviceId The device ID
66
+ * @param Function callback The callback for if there are any errors
67
+ *
68
+ * @return void
69
+ */
70
+ turnDeviceOff(roomId: string, deviceId: string, callback?: any): void;
71
+ /**
72
+ * Turn a device on
73
+ *
74
+ * @param integer roomId The room ID
75
+ * @param integer deviceId The device ID
76
+ * @param Function callback The callback for if there are any errors
77
+ *
78
+ * @return void
79
+ */
80
+ turnDeviceOn(roomId: string, deviceId: string, callback?: any): void;
81
+ /**
82
+ * Open a device
83
+ *
84
+ * @param integer roomId The room ID
85
+ * @param integer deviceId The device ID
86
+ * @param Function callback The callback for if there are any errors
87
+ *
88
+ * @return void
89
+ */
90
+ openDevice(roomId: string, deviceId: string, callback: any): void;
91
+ /**
92
+ * Close a device
93
+ *
94
+ * @param integer roomId The room ID
95
+ * @param integer deviceId The device ID
96
+ * @param Function callback The callback for if there are any errors
97
+ *
98
+ * @return void
99
+ */
100
+ closeDevice(roomId: string, deviceId: string, callback: any): void;
101
+ /**
102
+ * Stop a device
103
+ *
104
+ * @param integer roomId The room ID
105
+ * @param integer deviceId The device ID
106
+ * @param Function callback The callback for if there are any errors
107
+ *
108
+ * @return void
109
+ */
110
+ stopDevice(roomId: string, deviceId: string, callback: any): void;
111
+ /**
112
+ * Turn all devices in a room off
113
+ *
114
+ * @param integer roomId The room ID
115
+ * @param Function callback The callback for if there are any errors
116
+ *
117
+ * @return void
118
+ */
119
+ turnRoomOff(roomId: string, callback: any): void;
120
+ /**
121
+ * Set the dim percentage of a device
122
+ *
123
+ * @param integer roomId The room ID
124
+ * @param integer deviceId The device ID
125
+ * @param integer dimPercentage The percentage to set the device dim
126
+ * @param Function callback The callback for if there are any errors
127
+ *
128
+ * @return void
129
+ */
130
+ setDeviceDim(roomId: string, deviceId: string, dimPercentage: number, callback: any): void;
131
+ /**
132
+ * Get message code
133
+ *
134
+ * @return string
135
+ */
136
+ private getTransactionNumber;
137
+ private exec;
138
+ private send;
139
+ /**
140
+ * Send a message over udp
141
+ *
142
+ * @param string message The message to send
143
+ * @param Function callback The callback for if there are any errors
144
+ *
145
+ * @return void
146
+ */
147
+ private sendUdp;
148
+ private process;
149
+ /**
150
+ * Parser to get de devices from https POST
151
+ */
152
+ getDevices(roomsString: string, devicesString: string, typesString: string, callback: (object: any, lw: this) => void): void;
153
+ parseRooms(lightwaveResponse: any, callback: any): void;
154
+ /**
155
+ * Connect to the server and obtain the configuration
156
+ */
157
+ getConfiguration(email: string, pin: string, manager_host: string, callback: any): void;
158
+ }
159
+ export default LightwaveRF;