homebridge-melcloud-control 4.0.0-beta.460 → 4.0.0-beta.462

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "displayName": "MELCloud Control",
3
3
  "name": "homebridge-melcloud-control",
4
- "version": "4.0.0-beta.460",
4
+ "version": "4.0.0-beta.462",
5
5
  "description": "Homebridge plugin to control Mitsubishi Air Conditioner, Heat Pump and Energy Recovery Ventilation.",
6
6
  "license": "MIT",
7
7
  "author": "grzegorz914",
@@ -37,9 +37,10 @@
37
37
  "dependencies": {
38
38
  "@homebridge/plugin-ui-utils": "^2.1.0",
39
39
  "async-mqtt": "^2.6.3",
40
- "axios": "^1.13.0",
40
+ "axios": "^1.13.1",
41
41
  "express": "^5.1.0",
42
- "puppeteer": "^24.26.1"
42
+ "puppeteer": "^24.26.1",
43
+ "util": "^0.12.5"
43
44
  },
44
45
  "keywords": [
45
46
  "homebridge",
package/src/functions.js CHANGED
@@ -1,10 +1,9 @@
1
1
  import fs from 'fs';
2
- import util from 'util';
2
+ import { promisify } from 'util';
3
3
  import { exec } from 'child_process';
4
- import { promises as fsPromises } from 'fs';
5
4
  import EventEmitter from 'events';
6
- const access = util.promisify(fs.access);
7
- const execPromise = util.promisify(exec);
5
+ const execPromise = promisify(exec);
6
+ const access = fs.promises.access;
8
7
 
9
8
  class Functions extends EventEmitter {
10
9
  constructor(logWarn, logError, logDebug) {
@@ -68,6 +67,21 @@ class Functions extends EventEmitter {
68
67
  const arch = archOut.trim();
69
68
  if (this.logDebug) this.emit('debug', `Detected architecture: ${arch}`);
70
69
 
70
+ // --- Detect Docker environment ---
71
+ let isDocker = false;
72
+ try {
73
+ await access('/.dockerenv', fs.constants.F_OK);
74
+ isDocker = true;
75
+ } catch {
76
+ try {
77
+ const { stdout } = await execPromise('cat /proc/1/cgroup || true');
78
+ if (stdout.includes('docker') || stdout.includes('containerd'))
79
+ isDocker = true;
80
+ } catch { }
81
+ }
82
+
83
+ if (isDocker && this.logDebug) this.emit('debug', 'Running inside Docker container.');
84
+
71
85
  // === macOS ===
72
86
  if (osName === 'Darwin') {
73
87
  chromiumPath = '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome';
@@ -95,15 +109,15 @@ class Functions extends EventEmitter {
95
109
  return '/usr/bin/chromium-browser';
96
110
  } catch {
97
111
  if (this.logError) this.emit('error', 'Failed to install Chromium on ARM. Bundled Chromium will likely not work.');
98
- if (this.logDebug) this.emit('debug', 'Falling back to Puppeteer bundled Chromium.');
99
112
  return null;
100
113
  }
101
114
  }
102
115
  }
103
116
 
104
- // === Linux (x64 etc.) ===
117
+ // === Linux (x64, Docker, etc.) ===
105
118
  if (osName === 'Linux') {
106
119
  try {
120
+ // --- Try detect common Chromium binaries ---
107
121
  const { stdout: checkOut } = await execPromise('which chromium || which chromium-browser || true');
108
122
  chromiumPath = checkOut.trim();
109
123
  if (chromiumPath) {
@@ -114,25 +128,40 @@ class Functions extends EventEmitter {
114
128
 
115
129
  if (this.logWarn) this.emit('warn', 'Chromium not found. Attempting installation...');
116
130
 
117
- try {
118
- await execPromise('sudo apt-get update -y && sudo apt-get install -y chromium-browser chromium-codecs-ffmpeg');
119
- if (this.logDebug) this.emit('debug', 'Chromium installed successfully via apt-get.');
120
- return '/usr/bin/chromium-browser';
121
- } catch {
122
- if (this.logError) this.emit('error', 'apt-get failed. Trying apk or yum...');
123
- }
131
+ // --- Try install (Docker-optimized first) ---
132
+ const installCommands = [
133
+ 'apt-get update -y && apt-get install -y chromium chromium-browser chromium-codecs-ffmpeg',
134
+ 'apk add --no-cache chromium ffmpeg',
135
+ 'yum install -y chromium chromium-codecs-ffmpeg'
136
+ ];
124
137
 
125
- try {
126
- await execPromise('sudo apk add --no-cache chromium ffmpeg');
127
- if (this.logDebug) this.emit('debug', 'Chromium installed successfully via apk.');
128
- return '/usr/bin/chromium-browser';
129
- } catch { }
138
+ for (const cmd of installCommands) {
139
+ try {
140
+ if (this.logDebug) this.emit('debug', `Trying installation: ${cmd}`);
141
+ await execPromise(`sudo ${cmd}`);
142
+ // Check for binary after install
143
+ const { stdout: checkOut } = await execPromise('which chromium || which chromium-browser || true');
144
+ chromiumPath = checkOut.trim() || '/usr/bin/chromium';
145
+ if (chromiumPath) {
146
+ if (this.logDebug) this.emit('debug', `Chromium installed successfully at ${chromiumPath}`);
147
+ return chromiumPath;
148
+ }
149
+ } catch (err) {
150
+ if (this.logDebug) this.emit('debug', `Install attempt failed: ${cmd} → ${err.message}`);
151
+ }
152
+ }
130
153
 
131
- try {
132
- await execPromise('sudo yum install -y chromium chromium-codecs-ffmpeg');
133
- if (this.logDebug) this.emit('debug', 'Chromium installed successfully via yum.');
134
- return '/usr/bin/chromium-browser';
135
- } catch { }
154
+ if (isDocker) {
155
+ // Docker fallback specific
156
+ try {
157
+ await execPromise('sudo apt-get update -y && sudo apt-get install -y chromium');
158
+ await access('/usr/bin/chromium', fs.constants.X_OK);
159
+ if (this.logDebug) this.emit('debug', 'Chromium installed successfully inside Docker at /usr/bin/chromium');
160
+ return '/usr/bin/chromium';
161
+ } catch {
162
+ if (this.logError) this.emit('error', 'Failed to install Chromium inside Docker.');
163
+ }
164
+ }
136
165
 
137
166
  if (this.logDebug) this.emit('debug', 'Chromium not found on Linux. Using Puppeteer bundled Chromium.');
138
167
  return null;
@@ -149,5 +178,6 @@ class Functions extends EventEmitter {
149
178
  }
150
179
  }
151
180
 
181
+
152
182
  }
153
183
  export default Functions
package/src/melcloud.js CHANGED
@@ -447,7 +447,7 @@ class MelCloud extends EventEmitter {
447
447
  }
448
448
 
449
449
  async connect(refresh) {
450
- const TIMEOUT_MS = 30000;
450
+ const TIMEOUT_MS = 45000;
451
451
 
452
452
  try {
453
453
  const result = await Promise.race([