homebridge-melcloud-control 4.0.0-beta.444 → 4.0.0-beta.445
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 +1 -1
- package/src/functions.js +28 -18
- package/src/melcloud.js +5 -2
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.
|
|
4
|
+
"version": "4.0.0-beta.445",
|
|
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
|
@@ -3,11 +3,16 @@ import util from 'util';
|
|
|
3
3
|
import { promises as fsPromises } from 'fs';
|
|
4
4
|
import { exec } from 'child_process';
|
|
5
5
|
import puppeteer from 'puppeteer';
|
|
6
|
+
import EventEmitter from 'events';
|
|
6
7
|
const access = util.promisify(fs.access);
|
|
7
8
|
const execPromise = util.promisify(exec);
|
|
8
9
|
|
|
9
|
-
class Functions {
|
|
10
|
-
constructor() {
|
|
10
|
+
class Functions extends EventEmitter {
|
|
11
|
+
constructor(logWarn, logError, logDebug) {
|
|
12
|
+
super();
|
|
13
|
+
this.logWarn = logWarn;
|
|
14
|
+
this.logError = logError;
|
|
15
|
+
this.logDebug = logDebug;
|
|
11
16
|
}
|
|
12
17
|
|
|
13
18
|
async saveData(path, data, stringify = true) {
|
|
@@ -57,12 +62,12 @@ class Functions {
|
|
|
57
62
|
// --- Detect architecture ---
|
|
58
63
|
const { stdout: archOut } = await execPromise('uname -m');
|
|
59
64
|
const arch = archOut.trim();
|
|
60
|
-
|
|
65
|
+
if (this.logDebug) this.emit('debug', `Detected architecture: ${arch}`);
|
|
61
66
|
|
|
62
67
|
// --- Detect OS ---
|
|
63
68
|
const { stdout: osOut } = await execPromise('uname -s');
|
|
64
69
|
const osName = osOut.trim();
|
|
65
|
-
|
|
70
|
+
if (this.logDebug) this.emit('debug', `Detected OS: ${osName}`);
|
|
66
71
|
|
|
67
72
|
// --- macOS fallback ---
|
|
68
73
|
if (osName === 'Darwin') {
|
|
@@ -70,12 +75,11 @@ class Functions {
|
|
|
70
75
|
|
|
71
76
|
try {
|
|
72
77
|
await access(chromiumPath, fs.constants.X_OK);
|
|
73
|
-
|
|
78
|
+
if (this.logDebug) this.emit('debug', `Using system Chrome at ${chromiumPath}`);
|
|
74
79
|
} catch {
|
|
75
|
-
|
|
80
|
+
if (this.logError) this.emit('error', 'System Chrome not found. Falling back to Puppeteer bundled Chromium.');
|
|
76
81
|
chromiumPath = puppeteer.executablePath();
|
|
77
82
|
}
|
|
78
|
-
|
|
79
83
|
return chromiumPath;
|
|
80
84
|
}
|
|
81
85
|
|
|
@@ -85,9 +89,9 @@ class Functions {
|
|
|
85
89
|
const { stdout: distroOut } = await execPromise('cat /etc/os-release');
|
|
86
90
|
linuxDistro = distroOut.split('\n')[0] || 'unknown';
|
|
87
91
|
} catch {
|
|
88
|
-
|
|
92
|
+
if (this.logError) this.emit('error', '/etc/os-release not found, skipping OS detection.');
|
|
89
93
|
}
|
|
90
|
-
|
|
94
|
+
if (this.logDebug) this.emit('debug', `Linux distro: ${linuxDistro}`);
|
|
91
95
|
|
|
92
96
|
// --- Check if Chromium exists ---
|
|
93
97
|
let chromiumCheck = '';
|
|
@@ -97,36 +101,42 @@ class Functions {
|
|
|
97
101
|
} catch { }
|
|
98
102
|
if (chromiumCheck) {
|
|
99
103
|
chromiumPath = chromiumCheck;
|
|
100
|
-
|
|
104
|
+
if (this.logDebug) this.emit('debug', `Found system Chromium: ${chromiumPath}`);
|
|
101
105
|
return chromiumPath;
|
|
102
106
|
}
|
|
103
107
|
|
|
104
|
-
|
|
108
|
+
if (this.logWarn) this.emit('warn', 'Chromium not found. Attempting installation...');
|
|
105
109
|
|
|
106
110
|
// --- apt-get ---
|
|
107
111
|
try {
|
|
108
112
|
await execPromise('sudo apt-get update -y && sudo apt-get install -y chromium-browser chromium-codecs-ffmpeg');
|
|
109
|
-
|
|
113
|
+
if (this.logDebug) this.emit('debug', 'Chromium installed successfully via apt-get.');
|
|
110
114
|
return chromiumPath;
|
|
111
|
-
} catch {
|
|
115
|
+
} catch {
|
|
116
|
+
if (this.logError) this.emit('error', 'apt-get install failed. Trying apk or yum...');
|
|
117
|
+
}
|
|
112
118
|
|
|
113
119
|
// --- apk (Alpine) ---
|
|
114
120
|
try {
|
|
115
121
|
await execPromise('sudo apk add --no-cache chromium ffmpeg');
|
|
116
|
-
|
|
122
|
+
if (this.logDebug) this.emit('debug', 'Chromium installed successfully via apk.');
|
|
117
123
|
return chromiumPath;
|
|
118
|
-
} catch {
|
|
124
|
+
} catch {
|
|
125
|
+
if (this.logError) this.emit('error', 'apk install failed. Trying yum...');
|
|
126
|
+
}
|
|
119
127
|
|
|
120
128
|
// --- yum (RHEL/CentOS) ---
|
|
121
129
|
try {
|
|
122
130
|
await execPromise('sudo yum install -y chromium chromium-codecs-ffmpeg');
|
|
123
|
-
|
|
131
|
+
if (this.logDebug) this.emit('debug', 'Chromium installed successfully via yum.');
|
|
124
132
|
return chromiumPath;
|
|
125
|
-
} catch {
|
|
133
|
+
} catch {
|
|
134
|
+
if (this.logError) this.emit('error', 'yum install failed. Falling back to Puppeteer bundled Chromium.');
|
|
135
|
+
}
|
|
126
136
|
|
|
127
137
|
// --- Fallback Puppeteer ---
|
|
128
138
|
chromiumPath = puppeteer.executablePath();
|
|
129
|
-
|
|
139
|
+
if (this.logDebug) this.emit('debug', `Using bundled Puppeteer Chromium at ${chromiumPath || 'not found'}`);
|
|
130
140
|
return chromiumPath;
|
|
131
141
|
|
|
132
142
|
} catch (error) {
|
package/src/melcloud.js
CHANGED
|
@@ -21,8 +21,11 @@ class MelCloud extends EventEmitter {
|
|
|
21
21
|
this.devicesFile = devicesFile;
|
|
22
22
|
this.devicesId = [];
|
|
23
23
|
this.contextKey = '';
|
|
24
|
-
this.functions = new Functions(
|
|
25
|
-
|
|
24
|
+
this.functions = new Functions({
|
|
25
|
+
logWarn: this.logWarn,
|
|
26
|
+
logError: this.logError,
|
|
27
|
+
logDebug: this.logDebug,
|
|
28
|
+
})
|
|
26
29
|
|
|
27
30
|
if (pluginStart) {
|
|
28
31
|
//lock flags
|