homebridge-cmd4 6.0.0 → 6.0.4

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,281 +0,0 @@
1
- /* jshint node: true,esversion: 9, -W014, -W033 */
2
- /* eslint-disable new-cap */
3
- 'use strict'
4
-
5
- const { HomebridgePluginUiServer } = require('@homebridge/plugin-ui-utils');
6
- const { RequestError } = require('@homebridge/plugin-ui-utils');
7
- const fs = require('fs')
8
-
9
- // Settings, Globals and Constants
10
- let settings = require( "../cmd4Settings" );
11
- const constants = require( "../cmd4Constants" );
12
-
13
-
14
- // These would already be initialized by index.js
15
- let CMD4_ACC_TYPE_ENUM = require( "../lib/CMD4_ACC_TYPE_ENUM" );
16
- let CMD4_DEVICE_TYPE_ENUM = require( "../lib/CMD4_DEVICE_TYPE_ENUM" );
17
-
18
-
19
- //orig const { AuthorizationCode } = require('simple-oauth2');
20
-
21
- class UiServer extends HomebridgePluginUiServer
22
- {
23
- constructor ()
24
- {
25
-
26
- super();
27
- console.log("settings=%s", settings.PLUGIN_NAME);
28
-
29
-
30
- // Allow main.js to access Cmd4 Static variables as html files cannot
31
- // require Cmd4 javascript files
32
- this.onRequest('/startButtonPressed', this.startButtonPressed.bind(this));
33
- this.onRequest('/backButtonPressed', this.backButtonPressed.bind(this));
34
- this.onRequest('/showConfigureGlobalsPage', this.showConfigureGlobalsPage.bind(this));
35
- this.onRequest('/showQueueGlobalsPage', this.showQueueGlobalsPage.bind(this));
36
-
37
-
38
-
39
- this.onRequest('/getCachedAccessories', this.getCachedAccessories.bind(this));
40
-
41
- this.onRequest('/cmd4StaticVariable', this.cmd4StaticVariable.bind(this));
42
- this.onRequest('/ACC_Info', this.cmd4AccInfo.bind(this));
43
- this.onRequest('/DEVICE_Info', this.cmd4DeviceInfo.bind(this));
44
-
45
- this.fromPage = "#start";
46
- this.toPage = null;
47
- this.pages = [ ];
48
-
49
- this.pluginConfig = null;
50
-
51
- this.cachedAccessories = this.getCachedAccessories;
52
-
53
- this.ready();
54
- }
55
-
56
- async createSchemaForExistingAccessory( accessory )
57
- {
58
- let schema=
59
- {
60
- name:
61
- {
62
- title: "Name",
63
- description: "Name of accessory",
64
- type: "string",
65
- default: accessory.name,
66
- required: true
67
- },
68
- displayName:
69
- {
70
- title: "DisplayNamw",
71
- description: "Name of accessory",
72
- type: "string",
73
- default: accessory.displayNameame,
74
- required: true
75
- },
76
- manufacturer:
77
- {
78
- name: "Manufacturer",
79
- type: "string",
80
- placeholder: accessory.manufacturer || "",
81
- description: "Set the manufacturer name for display in the Home app.",
82
- required: false
83
- },
84
- model:
85
- {
86
- name: "Model",
87
- type: "string",
88
- placeholder: accessory.model || "",
89
- description: "Set the modal name for display in the Home app.",
90
- required: false
91
- },
92
- serialNumber:
93
- {
94
- name: "SerialNumber",
95
- type: "string",
96
- placeholder: accessory.serialNumber || "",
97
- description: "Set the serial number for display in the Home app.",
98
- required: false
99
- },
100
- stateChangeResponseTime:
101
- {
102
- name: "StateChangeResponseTime",
103
- type: "nummber",
104
- min: 0,
105
- max: 300,
106
- placeholder: accessory.stateChangeResponseTime,
107
- description: "Set the accessory's state chane response time (sec).",
108
- required: false
109
- },
110
- timeout:
111
- {
112
- name: "Timeout",
113
- type: "nummber",
114
- min: 0,
115
- max: 300,
116
- placeholder: accessory.timeout,
117
- description: "Set the accessory's timeout (msec).",
118
- required: true
119
- }
120
- };
121
- if ( typeof accessory.polling == "boolean" )
122
- {
123
- schema.polling =
124
- {
125
- title: "Polling",
126
- type: "boolean",
127
- default: accessory.polling,
128
- description: "Polling interval in seconds.",
129
- required: false
130
- };
131
- } else {
132
- schema.polling =
133
- {
134
- title: "Polling",
135
- type: "array",
136
- items: {
137
- }
138
- }
139
- accessory.polling.forEach( ( entry, index ) =>
140
- {
141
- schema.polling.items[ index ] =
142
- {
143
- title: "Characteristic",
144
- type: "string",
145
- placeholder: entry.characteristic,
146
- required: true
147
- },
148
- {
149
- title: "Timeout",
150
- type: "number",
151
- min: 0,
152
- max: 300,
153
- placeholder: entry.timeout,
154
- description: "Set the accessory's timeout (msec).",
155
- required: false
156
- },
157
- {
158
- title: "StateChangeResponseTime",
159
- type: "number",
160
- min: 0,
161
- max: 300,
162
- placeholder: entry.stateChangeResponseTime,
163
- description: "Set the accessory's state chane response time (sec).",
164
- required: false
165
- };
166
- });
167
- }
168
- }
169
-
170
- // A native method getCachedAccessories() was introduced in config-ui-x v4.37.0
171
- // The following is for users who have a lower version of config-ui-x
172
- async getCachedAccessories( )
173
- {
174
- try {
175
- // Define the plugin and create the array to return
176
- const plugin = settings.PLUGIN_NAME;
177
- const devicesToReturn = []
178
-
179
- // The path and file of the cached accessories
180
- const accFile = this.homebridgeStoragePath + '/accessories/cachedAccessories'
181
-
182
- // Check the file exists
183
- if (fs.existsSync(accFile)) {
184
- // Read the cached accessories file
185
- let cachedAccessories = await fs.promises.readFile(accFile)
186
-
187
- // Parse the JSON
188
- cachedAccessories = JSON.parse(cachedAccessories)
189
-
190
- // We only want the accessories for this plugin
191
- cachedAccessories
192
- .filter(accessory => accessory.plugin === plugin)
193
- .forEach(accessory => devicesToReturn.push(accessory))
194
- }
195
-
196
- // Return the array
197
- return devicesToReturn
198
- } catch (err) {
199
- // Just return an empty accessory list in case of any errors
200
- return []
201
- }
202
- }
203
-
204
-
205
- // A method for main.js to access Static Cmd4 variables
206
- async cmd4StaticVariable( variableString )
207
- {
208
- //console.log("server.js for %s returning: %s", variableString, eval(variableString));
209
- console.log("server.js for %s", variableString );
210
- return eval( variableString );
211
- }
212
- async cmd4AccInfo( accTypeEnumIndex )
213
- {
214
- return CMD4_ACC_TYPE_ENUM.properties[ accTypeEnumIndex ];
215
- }
216
- async cmd4DeviceInfo( deviceTypeEnumIndex )
217
- {
218
- return CMD4_DEVICE_TYPE_ENUM.properties[ deviceTypeEnumIndex ];
219
- }
220
-
221
- async startButtonPressed( pluginConfig )
222
- {
223
- console.log("Server.js in start() pluginConfig: %s", pluginConfig );
224
- console.log("Server.js in start() pluginConfig.length: %s", pluginConfig.length );
225
- this.pluginConfig = pluginConfig;
226
- this.pluginConfig.forEach( ( entry, index ) =>
227
- {
228
- console.log("Server.js pluginConfig[ %s ]: %s", index, entry );
229
- });
230
-
231
- let fromPage = "#start";
232
- let toPage = "";
233
- if ( pluginConfig && pluginConfig.length >= 1 && pluginConfig[0].accessories.length >= 1 )
234
- toPage = "#selectExistingAccessory";
235
- else
236
- toPage = "#newAccessory";
237
-
238
- this.pages.push( fromPage );
239
- this.pages.push( toPage );
240
- this.pushEvent('my-pageEvent', { from: fromPage, // from: is hide
241
- to: toPage } // to: is show
242
- );
243
-
244
- }
245
- async backButtonPressed( )
246
- {
247
- let fromPage = this.pages.pop();
248
- let toPage = this.pages[ this.pages.length -1];
249
- console.log("Server.js in back() toPage: %s fromPage", toPage, fromPage );
250
- this.pushEvent('my-pageEvent', { from: fromPage, // from: is hide
251
- to: toPage } // to: is show
252
- );
253
- }
254
- async showConfigureGlobalsPage( )
255
- {
256
- let fromPage = this.pages[ this.pages.length -1];
257
- let toPage = "#configureGlobals";
258
- console.log("Server.js in globals() toPage: %s fromPage", toPage, fromPage );
259
-
260
- this.pages.push( toPage );
261
- this.pushEvent('my-pageEvent', { from: fromPage, // from: is hide
262
- to: toPage } // to: is show
263
- );
264
- }
265
- async showQueueGlobalsPage( )
266
- {
267
- let fromPage = this.pages[ this.pages.length -1];
268
- let toPage = "#queueGlobalsPage";
269
- console.log("Server.js toPage: %s fromPage", toPage, fromPage );
270
-
271
- this.pages.push( toPage );
272
- this.pushEvent('my-pageEvent', { from: fromPage, // from: is hide
273
- to: toPage } // to: is show
274
- );
275
- }
276
- }
277
-
278
- (() =>
279
- {
280
- return new UiServer;
281
- })();
@@ -1,281 +0,0 @@
1
- /* jshint node: true,esversion: 9, -W014, -W033 */
2
- /* eslint-disable new-cap */
3
- 'use strict'
4
-
5
- const { HomebridgePluginUiServer } = require('@homebridge/plugin-ui-utils');
6
- const { RequestError } = require('@homebridge/plugin-ui-utils');
7
- const fs = require('fs')
8
-
9
- // Settings, Globals and Constants
10
- let settings = require( "../cmd4Settings" );
11
- const constants = require( "../cmd4Constants" );
12
-
13
-
14
- // These would already be initialized by index.js
15
- let CMD4_ACC_TYPE_ENUM = require( "../lib/CMD4_ACC_TYPE_ENUM" );
16
- let CMD4_DEVICE_TYPE_ENUM = require( "../lib/CMD4_DEVICE_TYPE_ENUM" );
17
-
18
-
19
- //orig const { AuthorizationCode } = require('simple-oauth2');
20
-
21
- class UiServer extends HomebridgePluginUiServer
22
- {
23
- constructor ()
24
- {
25
-
26
- super();
27
- console.log("settings=%s", settings.PLUGIN_NAME);
28
-
29
-
30
- // Allow main.js to access Cmd4 Static variables as html files cannot
31
- // require Cmd4 javascript files
32
- this.onRequest('/startButtonPressed', this.startButtonPressed.bind(this));
33
- this.onRequest('/backButtonPressed', this.backButtonPressed.bind(this));
34
- this.onRequest('/showConfigureGlobalsPage', this.showConfigureGlobalsPage.bind(this));
35
- this.onRequest('/showQueueGlobalsPage', this.showQueueGlobalsPage.bind(this));
36
-
37
-
38
-
39
- this.onRequest('/getCachedAccessories', this.getCachedAccessories.bind(this));
40
-
41
- this.onRequest('/cmd4StaticVariable', this.cmd4StaticVariable.bind(this));
42
- this.onRequest('/ACC_Info', this.cmd4AccInfo.bind(this));
43
- this.onRequest('/DEVICE_Info', this.cmd4DeviceInfo.bind(this));
44
-
45
- this.fromPage = "#start";
46
- this.toPage = null;
47
- this.pages = [ ];
48
-
49
- this.pluginConfig = null;
50
-
51
- this.cachedAccessories = this.getCachedAccessories;
52
-
53
- this.ready();
54
- }
55
-
56
- async createSchemaForExistingAccessory( accessory )
57
- {
58
- let schema=
59
- {
60
- name:
61
- {
62
- title: "Name",
63
- description: "Name of accessory",
64
- type: "string",
65
- default: accessory.name,
66
- required: true
67
- },
68
- displayName:
69
- {
70
- title: "DisplayNamw",
71
- description: "Name of accessory",
72
- type: "string",
73
- default: accessory.displayNameame,
74
- required: true
75
- },
76
- manufacturer:
77
- {
78
- name: "Manufacturer",
79
- type: "string",
80
- placeholder: accessory.manufacturer || "",
81
- description: "Set the manufacturer name for display in the Home app.",
82
- required: false
83
- },
84
- model:
85
- {
86
- name: "Model",
87
- type: "string",
88
- placeholder: accessory.model || "",
89
- description: "Set the modal name for display in the Home app.",
90
- required: false
91
- },
92
- serialNumber:
93
- {
94
- name: "SerialNumber",
95
- type: "string",
96
- placeholder: accessory.serialNumber || "",
97
- description: "Set the serial number for display in the Home app.",
98
- required: false
99
- },
100
- stateChangeResponseTime:
101
- {
102
- name: "StateChangeResponseTime",
103
- type: "nummber",
104
- min: 0,
105
- max: 300,
106
- placeholder: accessory.stateChangeResponseTime,
107
- description: "Set the accessory's state chane response time (sec).",
108
- required: false
109
- },
110
- timeout:
111
- {
112
- name: "Timeout",
113
- type: "nummber",
114
- min: 0,
115
- max: 300,
116
- placeholder: accessory.timeout,
117
- description: "Set the accessory's timeout (msec).",
118
- required: true
119
- }
120
- };
121
- if ( typeof accessory.polling == "boolean" )
122
- {
123
- schema.polling =
124
- {
125
- title: "Polling",
126
- type: "boolean",
127
- default: accessory.polling,
128
- description: "Polling interval in seconds.",
129
- required: false
130
- };
131
- } else {
132
- schema.polling =
133
- {
134
- title: "Polling",
135
- type: "array",
136
- items: {
137
- }
138
- }
139
- accessory.polling.forEach( ( entry, index ) =>
140
- {
141
- schema.polling.items[ index ] =
142
- {
143
- title: "Characteristic",
144
- type: "string",
145
- placeholder: entry.characteristic,
146
- required: true
147
- },
148
- {
149
- title: "Timeout",
150
- type: "number",
151
- min: 0,
152
- max: 300,
153
- placeholder: entry.timeout,
154
- description: "Set the accessory's timeout (msec).",
155
- required: false
156
- },
157
- {
158
- title: "StateChangeResponseTime",
159
- type: "number",
160
- min: 0,
161
- max: 300,
162
- placeholder: entry.stateChangeResponseTime,
163
- description: "Set the accessory's state chane response time (sec).",
164
- required: false
165
- };
166
- });
167
- }
168
- }
169
-
170
- // A native method getCachedAccessories() was introduced in config-ui-x v4.37.0
171
- // The following is for users who have a lower version of config-ui-x
172
- async getCachedAccessories( )
173
- {
174
- try {
175
- // Define the plugin and create the array to return
176
- const plugin = settings.PLUGIN_NAME;
177
- const devicesToReturn = []
178
-
179
- // The path and file of the cached accessories
180
- const accFile = this.homebridgeStoragePath + '/accessories/cachedAccessories'
181
-
182
- // Check the file exists
183
- if (fs.existsSync(accFile)) {
184
- // Read the cached accessories file
185
- let cachedAccessories = await fs.promises.readFile(accFile)
186
-
187
- // Parse the JSON
188
- cachedAccessories = JSON.parse(cachedAccessories)
189
-
190
- // We only want the accessories for this plugin
191
- cachedAccessories
192
- .filter(accessory => accessory.plugin === plugin)
193
- .forEach(accessory => devicesToReturn.push(accessory))
194
- }
195
-
196
- // Return the array
197
- return devicesToReturn
198
- } catch (err) {
199
- // Just return an empty accessory list in case of any errors
200
- return []
201
- }
202
- }
203
-
204
-
205
- // A method for main.js to access Static Cmd4 variables
206
- async cmd4StaticVariable( variableString )
207
- {
208
- //console.log("server.js for %s returning: %s", variableString, eval(variableString));
209
- console.log("server.js for %s", variableString );
210
- return eval( variableString );
211
- }
212
- async cmd4AccInfo( accTypeEnumIndex )
213
- {
214
- return CMD4_ACC_TYPE_ENUM.properties[ accTypeEnumIndex ];
215
- }
216
- async cmd4DeviceInfo( deviceTypeEnumIndex )
217
- {
218
- return CMD4_DEVICE_TYPE_ENUM.properties[ deviceTypeEnumIndex ];
219
- }
220
-
221
- async startButtonPressed( pluginConfig )
222
- {
223
- console.log("Server.js in start() pluginConfig: %s", pluginConfig );
224
- console.log("Server.js in start() pluginConfig.length: %s", pluginConfig.length );
225
- this.pluginConfig = pluginConfig;
226
- this.pluginConfig.forEach( ( entry, index ) =>
227
- {
228
- console.log("Server.js pluginConfig[ %s ]: %s", index, entry );
229
- });
230
-
231
- let fromPage = "#start";
232
- let toPage = "";
233
- if ( pluginConfig && pluginConfig.length >= 1 && pluginConfig[0].accessories.length >= 1 )
234
- toPage = "#selectExistingAccessory";
235
- else
236
- toPage = "#newAccessory";
237
-
238
- this.pages.push( fromPage );
239
- this.pages.push( toPage );
240
- this.pushEvent('my-pageEvent', { from: fromPage, // from: is hide
241
- to: toPage } // to: is show
242
- );
243
-
244
- }
245
- async backButtonPressed( )
246
- {
247
- let fromPage = this.pages.pop();
248
- let toPage = this.pages[ this.pages.length -1];
249
- console.log("Server.js in back() toPage: %s fromPage", toPage, fromPage );
250
- this.pushEvent('my-pageEvent', { from: fromPage, // from: is hide
251
- to: toPage } // to: is show
252
- );
253
- }
254
- async showConfigureGlobalsPage( )
255
- {
256
- let fromPage = this.pages[ this.pages.length -1];
257
- let toPage = "#configureGlobals";
258
- console.log("Server.js in globals() toPage: %s fromPage", toPage, fromPage );
259
-
260
- this.pages.push( toPage );
261
- this.pushEvent('my-pageEvent', { from: fromPage, // from: is hide
262
- to: toPage } // to: is show
263
- );
264
- }
265
- async showQueueGlobalsPage( )
266
- {
267
- let fromPage = this.pages[ this.pages.length -1];
268
- let toPage = "#queueGlobalsPage";
269
- console.log("Server.js toPage: %s fromPage", toPage, fromPage );
270
-
271
- this.pages.push( toPage );
272
- this.pushEvent('my-pageEvent', { from: fromPage, // from: is hide
273
- to: toPage } // to: is show
274
- );
275
- }
276
- }
277
-
278
- (() =>
279
- {
280
- return new UiServer;
281
- })();