homebridge-melcloud-control 4.1.2-beta.57 → 4.1.2-beta.59

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 (2) hide show
  1. package/package.json +1 -1
  2. package/src/functions.js +28 -87
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "displayName": "MELCloud Control",
3
3
  "name": "homebridge-melcloud-control",
4
- "version": "4.1.2-beta.57",
4
+ "version": "4.1.2-beta.59",
5
5
  "description": "Homebridge plugin to control Mitsubishi Air Conditioner, Heat Pump and Energy Recovery Ventilation.",
6
6
  "license": "MIT",
7
7
  "author": "grzegorz914",
package/src/functions.js CHANGED
@@ -68,136 +68,79 @@ class Functions extends EventEmitter {
68
68
  const arch = archOut.trim();
69
69
  if (this.logDebug) this.emit('debug', `Detected architecture: ${arch}`);
70
70
 
71
- // --- Detect Docker environment ---
71
+ // --- Detect Docker ---
72
72
  let isDocker = false;
73
+ try { await access('/.dockerenv', fs.constants.F_OK); isDocker = true; } catch { }
73
74
  try {
74
- await access('/.dockerenv', fs.constants.F_OK);
75
- isDocker = true;
76
- } catch {
77
- try {
78
- const { stdout } = await execPromise('cat /proc/1/cgroup || true');
79
- if (stdout.includes('docker') || stdout.includes('containerd'))
80
- isDocker = true;
81
- } catch { }
82
- }
83
-
75
+ const { stdout } = await execPromise('cat /proc/1/cgroup || true');
76
+ if (stdout.includes('docker') || stdout.includes('containerd')) isDocker = true;
77
+ } catch { }
84
78
  if (isDocker && this.logDebug) this.emit('debug', 'Running inside Docker container.');
85
79
 
86
80
  // === macOS ===
87
81
  if (osName === 'Darwin') {
88
82
  chromiumPath = '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome';
89
- try {
90
- await access(chromiumPath, fs.constants.X_OK);
91
- if (this.logDebug) this.emit('debug', `Using system Chrome at ${chromiumPath}`);
92
- return chromiumPath;
93
- } catch {
94
- return null;
95
- }
83
+ try { await access(chromiumPath, fs.constants.X_OK); return chromiumPath; } catch { return null; }
96
84
  }
97
85
 
98
- // === ARM (e.g. Raspberry Pi) ===
86
+ // === ARM ===
99
87
  if (arch.startsWith('arm')) {
100
- try {
101
- await access('/usr/bin/chromium-browser', fs.constants.X_OK);
102
- if (this.logDebug) this.emit('debug', 'Using system Chromium on ARM platform.');
103
- return '/usr/bin/chromium-browser';
104
- } catch {
105
- if (this.logWarn) this.emit('warn', 'System Chromium not found on ARM. Attempting installation...');
106
- try {
107
- await execPromise('sudo apt-get update -y && sudo apt-get install -y chromium-browser chromium-codecs-ffmpeg');
108
- if (this.logDebug) this.emit('debug', 'Chromium installed successfully on ARM.');
109
- return '/usr/bin/chromium-browser';
110
- } catch {
111
- return null;
112
- }
88
+ try { await access('/usr/bin/chromium-browser', fs.constants.X_OK); return '/usr/bin/chromium-browser'; }
89
+ catch {
90
+ try { await execPromise('sudo apt-get update -y && sudo apt-get install -y chromium-browser chromium-codecs-ffmpeg'); return '/usr/bin/chromium-browser'; }
91
+ catch { return null; }
113
92
  }
114
93
  }
115
94
 
116
- // === Linux (x64, Docker, QNAP etc.) ===
95
+ // === Linux x64 ===
117
96
  if (osName === 'Linux') {
118
97
  try {
119
98
  const { stdout: checkOut } = await execPromise('which chromium || which chromium-browser || true');
120
99
  chromiumPath = checkOut.trim();
121
- if (chromiumPath) {
122
- if (this.logDebug) this.emit('debug', `Found system Chromium: ${chromiumPath}`);
123
- return chromiumPath;
124
- }
100
+ if (chromiumPath) return chromiumPath;
125
101
  } catch { }
126
102
 
127
103
  if (this.logWarn) this.emit('warn', 'Chromium not found. Attempting installation...');
128
104
 
129
105
  // --- Detect Entware (QNAP) ---
130
106
  let entwareExists = false;
131
- try {
132
- await access('/opt/bin/opkg', fs.constants.X_OK);
133
- entwareExists = true;
134
- } catch { }
107
+ try { await access('/opt/bin/opkg', fs.constants.X_OK); entwareExists = true; } catch { }
135
108
 
136
109
  if (entwareExists) {
137
110
  try {
138
- if (this.logDebug) this.emit('debug', 'Detected Entware. Attempting installation via opkg...');
111
+ if (this.logDebug) this.emit('debug', 'Detected Entware. Installing Chromium and libraries via opkg...');
139
112
  await execPromise('/opt/bin/opkg update');
140
113
  await execPromise('/opt/bin/opkg install chromium');
141
- const { stdout: checkOut } = await execPromise('which chromium || which chromium-browser || true');
142
- chromiumPath = checkOut.trim() || '/opt/bin/chromium';
143
- if (chromiumPath) {
144
- if (this.logDebug) this.emit('debug', `Chromium installed successfully via Entware at ${chromiumPath}`);
145
- return chromiumPath;
146
- }
147
- } catch (error) {
148
- if (this.logDebug) this.emit('debug', `Entware installation failed: ${error.message}`);
149
- }
150
114
 
151
- // === 🔧 Additional dependency install for QNAP/Entware ===
152
- try {
153
- if (this.logDebug) this.emit('debug', 'Installing missing libraries required for Chromium (libnspr4, nss, X11, etc.)...');
115
+ // Install all essential dependencies
154
116
  await execPromise('/opt/bin/opkg install nspr nss libx11 libxcomposite libxdamage libxrandr libatk libatk-bridge libcups libdrm libgbm libasound');
155
- if (this.logDebug) this.emit('debug', 'Chromium dependencies installed successfully.');
156
- } catch (depErr) {
157
- if (this.logError) this.emit('error', `Failed to install Chromium dependencies: ${depErr.message}`);
158
- }
159
117
 
160
- // Try again to locate Chromium
161
- try {
118
+ // Add Entware lib path to LD_LIBRARY_PATH
119
+ process.env.LD_LIBRARY_PATH = '/opt/lib:' + (process.env.LD_LIBRARY_PATH || '');
120
+ if (this.logDebug) this.emit('debug', 'LD_LIBRARY_PATH set for Chromium');
121
+
122
+ // Verify binary exists
162
123
  const { stdout: checkOut } = await execPromise('which chromium || which chromium-browser || true');
163
124
  chromiumPath = checkOut.trim() || '/opt/bin/chromium';
164
- if (chromiumPath) {
165
- return chromiumPath;
166
- }
167
- } catch { }
125
+ if (chromiumPath) return chromiumPath;
126
+ } catch (error) {
127
+ if (this.logError) this.emit('error', `Entware Chromium/libs installation failed: ${error.message}`);
128
+ }
168
129
  }
169
130
 
170
- // --- Try install (Docker-optimized first) ---
131
+ // --- Generic Linux install ---
171
132
  const installCommands = [
172
133
  'apt-get update -y && apt-get install -y chromium chromium-browser chromium-codecs-ffmpeg',
173
134
  'apk add --no-cache chromium ffmpeg',
174
135
  'yum install -y chromium chromium-codecs-ffmpeg'
175
136
  ];
176
-
177
137
  for (const cmd of installCommands) {
178
138
  try {
179
- if (this.logDebug) this.emit('debug', `Trying installation: ${cmd}`);
180
139
  await execPromise(`sudo ${cmd}`);
181
140
  const { stdout: checkOut } = await execPromise('which chromium || which chromium-browser || true');
182
141
  chromiumPath = checkOut.trim() || '/usr/bin/chromium';
183
- if (chromiumPath) {
184
- if (this.logDebug) this.emit('debug', `Chromium installed successfully at ${chromiumPath}`);
185
- return chromiumPath;
186
- }
187
- } catch (error) {
188
- if (this.logDebug) this.emit('debug', `Install attempt failed: ${cmd} → ${error.message}`);
189
- }
190
- }
191
-
192
- if (isDocker) {
193
- try {
194
- await execPromise('sudo apt-get update -y && sudo apt-get install -y chromium');
195
- await access('/usr/bin/chromium', fs.constants.X_OK);
196
- if (this.logDebug) this.emit('debug', 'Chromium installed successfully inside Docker at /usr/bin/chromium');
197
- return '/usr/bin/chromium';
198
- } catch {
199
- return null;
200
- }
142
+ if (chromiumPath) return chromiumPath;
143
+ } catch { }
201
144
  }
202
145
 
203
146
  return null;
@@ -211,7 +154,5 @@ class Functions extends EventEmitter {
211
154
  }
212
155
  }
213
156
 
214
-
215
-
216
157
  }
217
158
  export default Functions