homebridge-myplace 2.1.3 → 2.2.0

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.
Files changed (37) hide show
  1. package/CHANGELOG.md +2 -4
  2. package/Cmd5Accessory.js +5 -5
  3. package/Cmd5Platform.js +81 -18
  4. package/README.md +23 -79
  5. package/RUNNING_CHANGELOG.md +8 -0
  6. package/config.schema.json +8 -333
  7. package/homebridge-ui/public/index.html +25 -157
  8. package/index.js +2 -43
  9. package/lib/CMD5_ACC_TYPE_ENUM.js +6 -6
  10. package/lib/CMD5_DEVICE_TYPE_ENUM.js +5 -5
  11. package/package.json +1 -1
  12. package/utils/Cmd5Storage.js +3 -3
  13. package/utils/{indexOfEnum.js → Cmd5indexOfEnum.js} +1 -1
  14. package/utils/createMyPlaceConfig.js +648 -0
  15. package/utils/isAccDirective.js +2 -2
  16. package/utils/isDevDirective.js +2 -2
  17. package/CheckConfig.js +0 -605
  18. package/CheckConfig.sh +0 -310
  19. package/ConfigCreator.sh +0 -1341
  20. package/Extras/Cmd5Scripts/CheckYourScript.sh +0 -135
  21. package/Extras/Cmd5Scripts/Examples/AirPurifier.js +0 -396
  22. package/Extras/Cmd5Scripts/Examples/AnyDevice +0 -451
  23. package/Extras/Cmd5Scripts/Examples/DoorLock.sh +0 -75
  24. package/Extras/Cmd5Scripts/Examples/ExampleJavaScript_template.js +0 -148
  25. package/Extras/Cmd5Scripts/Examples/ExampleShellScript_template.sh +0 -139
  26. package/Extras/Cmd5Scripts/Examples/PS4.sh +0 -128
  27. package/Extras/Cmd5Scripts/Examples/PS5.sh +0 -133
  28. package/Extras/Cmd5Scripts/Examples/SecuritySystem.js +0 -368
  29. package/Extras/Cmd5Scripts/Examples/advanced_ping.sh +0 -84
  30. package/Extras/Cmd5Scripts/Examples/basic_ping.sh +0 -79
  31. package/Extras/Cmd5Scripts/Examples/middleWare.sh +0 -5
  32. package/Extras/Cmd5Scripts/Examples/wakeonlan.sh +0 -128
  33. package/Extras/Cmd5Scripts/State.js +0 -4062
  34. package/Extras/a.out +0 -0
  35. package/Extras/config.json +0 -780
  36. package/Extras/config.min.json +0 -2135
  37. package/Extras/jsmin.c +0 -284
package/CHANGELOG.md CHANGED
@@ -1,6 +1,4 @@
1
1
  ### Homebridge-myplace - An independent plugin for Homebridge bringing Advantage Air MyPlace system, its smaller siblings (E-zone, MyAir, MyAir4, etc) and its cousins (e.g. Fujitsu AnywAir) to Homekit
2
- ##### v2.1.3 (2024-12-30)
2
+ ##### v2.2.0 (2025-06-27)
3
3
 
4
- ###### (1) Updated complatibility of the package json file to node 22
5
- ###### (2) Minor under the hood code changes to improve the running of this plugin
6
- ###### (3) And some minor bug fixes
4
+ ###### (1) Simplified the setup process
package/Cmd5Accessory.js CHANGED
@@ -21,9 +21,9 @@ let lcFirst = require( "./utils/lcFirst" );
21
21
  let trueTypeOf = require( "./utils/trueTypeOf" );
22
22
 
23
23
  // The sObject.defineProperty is to resolve a lint issue.
24
- // See utils/indexOfEnumLintTest.js for further information.
25
- let indexOfEnum = require( "./utils/indexOfEnum" );
26
- Object.defineProperty( exports, "indexOfEnum", { enumerable: true, get: function ( ){ return indexOfEnum.indexOfEnum; } });
24
+ // See utils/Cmd5indexOfEnumLintTest.js for further information.
25
+ let Cmd5indexOfEnum = require( "./utils/Cmd5indexOfEnum" );
26
+ Object.defineProperty( exports, "Cmd5indexOfEnum", { enumerable: true, get: function ( ){ return Cmd5indexOfEnum.Cmd5indexOfEnum; } });
27
27
 
28
28
  // For changing validValue Constants to Values and back again
29
29
  var { transposeConstantToValidValue,
@@ -389,7 +389,7 @@ class Cmd5Accessory
389
389
  let devProperties = CMD5_DEVICE_TYPE_ENUM.properties[ this.typeIndex ];
390
390
 
391
391
  // See if the characteristic index is in the required characteristics of the device
392
- let requiredIndex = devProperties.requiredCharacteristics.indexOfEnum( i => i.type === accTypeEnumIndex );
392
+ let requiredIndex = devProperties.requiredCharacteristics.Cmd5indexOfEnum( i => i.type === accTypeEnumIndex );
393
393
 
394
394
  let format = CMD5_ACC_TYPE_ENUM.properties[ accTypeEnumIndex ].props.format;
395
395
 
@@ -506,7 +506,7 @@ class Cmd5Accessory
506
506
  default:
507
507
  {
508
508
  // Is this still useful?
509
- accTypeEnumIndex = CMD5_ACC_TYPE_ENUM.indexOfEnum( key );
509
+ accTypeEnumIndex = CMD5_ACC_TYPE_ENUM.Cmd5indexOfEnum( key );
510
510
 
511
511
  if ( accTypeEnumIndex < 0 )
512
512
  // throw new Error( `OOPS: "${ key }" not found while parsing for characteristic polling. There something wrong with your config.json file?` );
package/Cmd5Platform.js CHANGED
@@ -5,9 +5,6 @@ const { getAccessoryName,
5
5
  getAccessoryDisplayName } = require( "./utils/getAccessoryNameFunctions" );
6
6
  const { parseAddQueueTypes } = require( "./Cmd5PriorityPollingQueue" );
7
7
 
8
-
9
-
10
-
11
8
  let Logger = require( "./utils/Logger" );
12
9
  let getAccessoryUUID = require( "./utils/getAccessoryUUID" );
13
10
  let lcFirst = require( "./utils/lcFirst" );
@@ -17,6 +14,8 @@ let trueTypeOf = require( "./utils/trueTypeOf" );
17
14
  // Hierarchy variables
18
15
  let HV = require( "./utils/HV" );
19
16
 
17
+ // Essential variables
18
+ const { spawnSync } = require('child_process');
20
19
  let createAccessorysInformationService = require( "./utils/createAccessorysInformationService" );
21
20
 
22
21
  // Pretty Colors
@@ -37,6 +36,8 @@ const Cmd5Accessory = require( "./Cmd5Accessory" ).Cmd5Accessory;
37
36
  // Settings, Globals and Constants
38
37
  let settings = require( "./cmd5Settings" );
39
38
  const constants = require( "./cmd5Constants" );
39
+ const path = require('path');
40
+ const fs = require('fs');
40
41
 
41
42
  // Platform definition
42
43
  class Cmd5Platform
@@ -102,23 +103,85 @@ class Cmd5Platform
102
103
  // Create the hierarhy variables
103
104
  this.hV = new HV();
104
105
 
105
- this.parseConfigForCmd5Directives( this.config );
106
-
107
- // Update the namespace for stored variables
108
- // like timeout, stateChangeResponseTime ... As it may require
109
- // changes from parseConfig.
110
- this.hV.update( this );
111
-
112
- this.processNewCharacteristicDefinitions( );
113
-
114
-
115
106
  // didFinishLaunching is only called after the
116
107
  // registerPlatform completes.
117
108
  api.on( "didFinishLaunching", ( ) =>
118
109
  {
119
- this.log.info( chalk.blue( "Cmd5Platform didFinishLaunching" ) );
110
+ this.log.info( chalk.green( "MyPlace Platform didFinishLaunching" ) );
111
+
112
+ // Remove MyPlace shell script temporary working directories on Homebridge RESTART
113
+ this.log.info( chalk.yellow( "Removing temporary working directories" ) );
114
+ try {
115
+ const directoryPath = process.env.TMPDIR || "/tmp";
116
+ const files = fs.readdirSync(directoryPath);
117
+ const filteredFiles = files.filter(file => file.match(/^(AA|BB)-\d{3}$/));
118
+
119
+ filteredFiles.forEach(file => {
120
+ const sdir = `${directoryPath}/${file}`;
121
+
122
+ try {
123
+ fs.rmSync(sdir, { recursive: true, force: true });
124
+ this.log.info(`Temporary working directory ${sdir} removed`);
125
+ } catch (err) {
126
+ this.log.error(` Unable to remove temporary working directory ${sdir}: [${err}]`);
127
+ }
128
+ });
129
+ } catch (err) {
130
+ this.log.error(`Unable to scan and remove temporary working directory: [${err}]`);
131
+ }
132
+
133
+ // Run ConfigCreator to update/refresh the MyPlace config
134
+ this.log.info( chalk.yellow( "Running createMyPlacConfig..." ) );
135
+ try {
136
+ // Build args for up to 3 devices
137
+ let args = [];
138
+ for (let i = 0; i < 3; i++) {
139
+ const device = this.config.devices[i];
140
+ if (device) {
141
+ const ipPort = `${device.ipAddress || ''}:${device.port || ''}`;
142
+ const name = device.name || '';
143
+ const extraTimers = device.extraTimers ?? false;
144
+ const debug = device.debug ?? false;
145
+ args.push(ipPort, name, extraTimers, debug);
146
+ } else {
147
+ // If device is missing, push empty args
148
+ args.push('', '', '', '');
149
+ }
150
+ }
151
+
152
+ // Add __dirname and "homebridge" as last two arguments
153
+ args.push(`${__dirname}/MyPlace.sh`);
154
+
155
+ // Run the createMyPlaceconfig.js script
156
+ const scriptPath = path.resolve(__dirname, 'utils', 'createMyPlaceConfig.js');
157
+ this.log.debug('Running script:', scriptPath, args);
158
+
159
+ const result = spawnSync('node', [scriptPath, ...args], { encoding: 'utf8' });
160
+ const feedback = result.stdout.trim();
161
+
162
+ const lines = feedback.split('\n');
163
+ const status = lines.shift();
164
+ const jsonText = lines.join('\n').trim();
165
+
166
+ if (status.includes('DONE')) {
167
+ this.config = JSON.parse(jsonText);
168
+ this.log.info(status);
169
+ this.log.debug('Updated config:\n' + JSON.stringify(this.config, null, 2));
170
+ } else {
171
+ this.log.error('ERROR: Errors encountered running createMyPlaceConfig', status);
172
+ this.log.warn('Proceeding with original config — no accessories will be created.');
173
+ }
174
+ } catch (err) {
175
+ this.log.warn('ERROR: createMyPlaceConfig failed:', err);
176
+ this.log.warn('Proceeding with original config — no accessories will be created.');
177
+ }
178
+
179
+ // Now process these using the updated config
180
+ this.parseConfigForCmd5Directives( this.config );
181
+ this.hV.update( this );
182
+ this.processNewCharacteristicDefinitions( );
120
183
 
121
- this.log.info( chalk.magenta( "Scanning config.json and the cache for devices to be removed/restored from cache" ) );
184
+ this.log.info( chalk.yellow( "Scanning the config and the cache for devices to be removed or restored from cache" ) );
122
185
  // scan the platform devices to identify which ones to be restored from cache
123
186
  this.scanToBeRestoredDevices( this.log );
124
187
 
@@ -289,7 +352,7 @@ class Cmd5Platform
289
352
  throw new Error( `definition.props.format at index: ${ definitionIndex } is not a String.` );
290
353
 
291
354
  // Need to check if format is correct
292
- let formatIndex = CMD5_FORMAT_TYPE_ENUM.properties.indexOfEnum( i => i.type === definition.props.format );
355
+ let formatIndex = CMD5_FORMAT_TYPE_ENUM.properties.Cmd5indexOfEnum( i => i.type === definition.props.format );
293
356
  if ( formatIndex < 0 )
294
357
  throw new Error( `definition.props.format at index: ${ definitionIndex } is not a valid format.` );
295
358
 
@@ -300,7 +363,7 @@ class Cmd5Platform
300
363
  throw new Error( `definition.props.units at index: ${ definitionIndex } is not a String.` );
301
364
 
302
365
  // Need to check if units is correct
303
- let unitsIndex = CMD5_UNITS_TYPE_ENUM.properties.indexOfEnum( i => i.type === definition.props.units );
366
+ let unitsIndex = CMD5_UNITS_TYPE_ENUM.properties.Cmd5indexOfEnum( i => i.type === definition.props.units );
304
367
  if ( unitsIndex < 0 )
305
368
  throw new Error( `definition.props.units at index: ${ definitionIndex } is not a valid unit.` );
306
369
 
@@ -326,7 +389,7 @@ class Cmd5Platform
326
389
 
327
390
  definition.props.perms.forEach( ( perm ) =>
328
391
  {
329
- let permIndex = CMD5_PERMS_TYPE_ENUM.properties.indexOfEnum( i => i.type === perm );
392
+ let permIndex = CMD5_PERMS_TYPE_ENUM.properties.Cmd5indexOfEnum( i => i.type === perm );
330
393
  if ( permIndex < 0 )
331
394
  throw new Error( `definition.props.perms at index: ${ definitionIndex } ${ perm } is not a valid perm.` );
332
395
 
package/README.md CHANGED
@@ -25,99 +25,43 @@ An independent plugin bringing [Advantage Air](https://www.advantageair.com.au/)
25
25
  * [Fujitsu anywAIR](https://apps.apple.com/au/app/anywair/id1509639853)
26
26
 
27
27
  ## Installation
28
- ### Raspbian/HOOBS/macOS/NAS
29
28
  1. Install Homebridge via these instructions for [Raspbian](https://github.com/homebridge/homebridge/wiki/Install-Homebridge-on-Raspbian), [HOOBS](https://support.hoobs.org/docs) or [macOS](https://github.com/homebridge/homebridge/wiki/Install-Homebridge-on-macOS), if you have not already.
30
29
 
31
- 2. Check if <B>jq</B> and <B>curl</B> are installed (<B>curl</B> should already be):
32
- ```shell
33
- jq --version
34
- curl --version
35
- ```
36
- If they are installed, the above command should return a version number. If not, install them:
37
- ##### For Raspbian/Hoobs:
38
- ```shell
39
- sudo apt-get install <jq or curl>
40
- ```
41
- ##### For MacOS:
42
- ```shell
43
- brew install <jq or curl>
44
- ```
45
- ##### For Synology NAS:
46
- ```shell
47
- apt-get install <jq or curl>
48
- ```
49
- ##### For QNAP NAS:
50
- ```shell
51
- apk add <jq or curl>
52
- ```
53
- #### Important note:
54
- At the time of updating this README, the `apt-get insatall` only allow jq-1.6 to be installed, which is notorously slow! To install the lastest and **MUCH faster** version of jq-1.7.1, please follow the step-by-step guide below:
55
- 1. Download the Source Code:
56
-
57
- You can download the source code "jq-1.7.1.tar.gz" for jq 1.7.1 from the official GitHub releases page (https://github.com/jqlang/jq/releases) or use the link below:
58
- ```shell
59
- wget https://github.com/jqlang/jq/releases/download/jq-1.7.1/jq-1.7.1.tar.gz
60
- ```
61
- 2. Install Dependencies:
62
-
63
- Ensure you have the necessary build tools and dependencies installed. You can do this by running:
64
- ```shell
65
- sudo apt-get update
66
- sudo apt-get install -y autoconf automake libtool make gcc
67
- ```
68
- 3. Extract and Build:
69
-
70
- Extract the downloaded tarball and navigate to the directory:
71
- ```shell
72
- tar -xvzf jq-1.7.1.tar.gz
73
- cd jq-1.7.1
74
- chmod +x configure
75
- ```
76
- 4. Run the following commands to build and install jq:
77
- ```shell
78
- ./configure
79
- make
80
- sudo make install
81
- ```
82
- 5. Verify Installation:
83
-
84
- After installation, you can verify that jq is installed correctly by running:
85
- ```shell
86
- jq --version
87
- ```
30
+ 2. Make sure that <B>jq</B> and <B>curl</B> are installed. Try to install <B>jq-1.7</B> if you can. It is much faster.
31
+
88
32
  3. Find the `homebridge-myplace` plugin via the Homebridge UI 'Plugins' tab search function, once found, click the blue *down-arrow* at the bottom right to install.
89
33
 
90
34
  <p align="left">
91
35
  <img width="400px" src="Screenshots/MyPlaceInstall3.png">
92
36
  </p>
93
37
 
94
- Once install, `Config: homebridge-myplace` UI will pop up, then follow the steps shown in Step 4 below.
38
+ Once installed, `Config: homebridge-myplace` UI will pop up, then follow the steps outlined in Step 4 below.
39
+
40
+ ![MyPlace_setting_UI](https://github.com/user-attachments/assets/49d49852-908b-4479-aebc-81337c820b1a)
95
41
 
96
42
  If for some reasons, the `Config: homebridge-myplace` UI did not pop up, locate your newly installed `Homebridge Myplace` plugin and click on the three dots at the bottom right and select `Plugin Config` to get the `Config: homebridge-myplace` UI.
97
43
 
98
- 4. Create MyPlace configuration file:
44
+ 5. Configuring MyPlace plugin:
99
45
 
100
- This is the `Config: homebridge-myplace` UI where you register your system parameters and create/check the required configuration file to run this plugin.
101
- <p align="left">
102
- <img width="600px" src="Screenshots/MyPlaceConfigCreator.png">
103
- </p>
104
-
105
- In <B>Device Settings</B> area, fill out the `Name`, `IP Address` and `PORT used` fields (default PORT is `2025` for most users, Fujitsu anywAIR users set this to `10211` ) and check/uncheck the self-explanatory checkboxes for `Include extra timers` and `Enable detailed debug log`, then click `SAVE`. This is to save your system parameters. Click `CLOSE` if a pop up urging you to `RESTART`.
46
+ In <B>Device Settings</B> area, fill out the `Name`, `IP Address` and `PORT used` fields (default PORT is `2025` for most users, Fujitsu anywAIR users set this to `10211` ) and check/uncheck the self-explanatory checkboxes for `Include extra timers` and `Enable detailed debug log`, click `SAVE` then `RESTART`.
106
47
 
107
- Go back to `Config: homebridge-myplace` UI agina (by clicking the the 3 dots at the bottom right and click `Plugin Config`) and press the `CREATE CONFIGURATION` button to create the required configuration file.
108
-
109
- On a sucess, you may click `CHECK CONFIGURATION`to check the configuration file just created is in order. On a success it will say `Passed`; if something is incorrect, an error message will pop up telling you what needs to be fixed.
110
-
111
- Otherwise, click `SAVE` then `RESTART`.
112
-
113
- **HOOBS** users who do not have access to Homebridge UI (for now!) will have to run the Config Creator on a terminal:
114
- ```shell
115
- cd
116
- <Plugin Path>/node_modules/homebridge-myplace/ConfigCreator.sh
48
+ For users who do not have access to Homebridge UI have to make sure that a config, as shown in the example below, is in the homebridge config.json:
49
+
50
+ ```
51
+ {
52
+ "name": "MyPlace",
53
+ "devices": [
54
+ {
55
+ "name": "Aircon",
56
+ "ipAddress": "192.168.1.3",
57
+ "port": 2025,
58
+ "extraTimers": true,
59
+ "debug": false
60
+ }
61
+ ],
62
+ "platform": "MyPlace"
63
+ }
117
64
  ```
118
- then follow the on-screen instructions.
119
-
120
- *typical `<Plugin Path>` is `/var/lib/hoobs/<bridge>`
121
65
 
122
66
  ## How it Looks and Works
123
67
  ### (A) Aircon System (MyAir, E-zone, etc) has the following typical Homekit tiles:
@@ -1,4 +1,12 @@
1
1
  ### Homebridge-myplace - An independent plugin for Homebridge bringing Advantage Air MyPlace system, its smaller siblings (E-zone, MyAir, MyAir4, etc) and its cousins (e.g. Fujitsu AnywAir) to Homekit
2
+ ##### v2.2.0 (2025-06-27)
3
+
4
+ ###### (1) Simplified the setup process
5
+
6
+ ##### v2.1.4 (2025-03-10)
7
+
8
+ ###### (1) A minor bug fix to resolve the `TypeError` while loading plugin if `homebridge-cmd4` is also installed
9
+
2
10
  ##### v2.1.3 (2024-12-30)
3
11
 
4
12
  ###### (1) Updated complatibility of the package json file to node 22