homebridge-melcloud-control 4.0.0-beta.434 → 4.0.0-beta.436

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.434",
4
+ "version": "4.0.0-beta.436",
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
@@ -1,5 +1,7 @@
1
1
  import fs from 'fs';
2
2
  import { promises as fsPromises } from 'fs';
3
+ import { exec } from 'child_process';
4
+ import puppeteer from 'puppeteer-core';
3
5
 
4
6
  class Functions {
5
7
  constructor() {
@@ -45,110 +47,116 @@ class Functions {
45
47
  }
46
48
  }
47
49
 
48
- async ensureChromiumInstalled() {
49
- let chromiumPath = '/usr/bin/chromium-browser';
50
+ async ensureChromiumInstalled() {
51
+ let chromiumPath = '/usr/bin/chromium-browser';
50
52
 
51
- try {
52
- // --- Detect architecture ---
53
- let arch = '';
54
53
  try {
55
- arch = (await new Promise((res, rej) =>
56
- require('child_process').exec('uname -m', (e, stdout) => e ? rej(e) : res(stdout))
57
- )).trim();
58
- if (this.logDebug) this.emit('debug', `Detected architecture: ${arch}`);
59
- } catch (err) {
60
- if (this.logWarn) this.emit('warn', `Failed to detect architecture: ${err.message}`);
61
- }
54
+ // --- Detect architecture ---
55
+ let arch = '';
56
+ try {
57
+ const { stdout } = await new Promise((res, rej) =>
58
+ exec('uname -m', (e, out) => e ? rej(e) : res({ stdout: out }))
59
+ );
60
+ arch = stdout.trim();
61
+ console.log('debug', `Detected architecture: ${arch}`);
62
+ } catch (err) {
63
+ if (this.logWarn) this.emit('warn', `Failed to detect architecture: ${err.message}`);
64
+ }
62
65
 
63
- // --- Detect OS ---
64
- let osName = '';
65
- try {
66
- osName = (await new Promise((res, rej) =>
67
- require('child_process').exec('uname -s', (e, stdout) => e ? rej(e) : res(stdout))
68
- )).trim();
69
- if (this.logDebug) this.emit('debug', `Detected OS: ${osName}`);
70
- } catch (err) {
71
- if (this.logWarn) this.emit('warn', `Failed to detect OS: ${err.message}`);
72
- }
66
+ // --- Detect OS ---
67
+ let osName = '';
68
+ try {
69
+ const { stdout } = await new Promise((res, rej) =>
70
+ exec('uname -s', (e, out) => e ? rej(e) : res({ stdout: out }))
71
+ );
72
+ osName = stdout.trim();
73
+ console.log('debug', `Detected OS: ${osName}`);
74
+ } catch (err) {
75
+ if (this.logWarn) this.emit('warn', `Failed to detect OS: ${err.message}`);
76
+ }
73
77
 
74
- // --- macOS fallback ---
75
- if (osName === 'Darwin') {
76
- if (this.logDebug) this.emit('debug', 'Running on macOS — using Puppeteer bundled Chromium');
77
- chromiumPath = require('puppeteer-core').executablePath();
78
- if (this.logDebug) this.emit('debug', `Chromium path: ${chromiumPath}`);
79
- return chromiumPath;
80
- }
78
+ // --- macOS fallback ---
79
+ if (osName === 'Darwin') {
80
+ console.log('debug', 'Running on macOS — using Puppeteer bundled Chromium');
81
+ chromiumPath = puppeteer.executablePath();
82
+ console.log('debug', `Chromium path: ${chromiumPath}`);
83
+ return chromiumPath;
84
+ }
81
85
 
82
- // --- Linux distro detection ---
83
- let linuxDistro = 'unknown';
84
- try {
85
- linuxDistro = (await new Promise((res, rej) =>
86
- require('child_process').exec('cat /etc/os-release', (e, stdout) => e ? rej(e) : res(stdout))
87
- )).split('\n')[0] || 'unknown';
88
- } catch {
89
- if (this.logWarn) this.emit('warn', '/etc/os-release not found, skipping OS detection.');
90
- }
91
- if (this.logDebug) this.emit('debug', `Linux distro: ${linuxDistro}`);
92
-
93
- // --- Check if Chromium exists ---
94
- const chromiumCheck = (await new Promise((res) =>
95
- require('child_process').exec('which chromium || which chromium-browser || true', (e, stdout) => res(stdout))
96
- )).trim();
97
- if (chromiumCheck) {
98
- chromiumPath = chromiumCheck;
99
- if (this.logDebug) this.emit('debug', `Found system Chromium: ${chromiumPath}`);
100
- return chromiumPath;
101
- }
86
+ // --- Linux distro detection ---
87
+ let linuxDistro = 'unknown';
88
+ try {
89
+ const { stdout } = await new Promise((res, rej) =>
90
+ exec('cat /etc/os-release', (e, out) => e ? rej(e) : res({ stdout: out }))
91
+ );
92
+ linuxDistro = stdout.split('\n')[0] || 'unknown';
93
+ } catch {
94
+ if (this.logWarn) this.emit('warn', '/etc/os-release not found, skipping OS detection.');
95
+ }
96
+ console.log('debug', `Linux distro: ${linuxDistro}`);
97
+
98
+ // --- Check if Chromium exists ---
99
+ let chromiumCheck = '';
100
+ try {
101
+ const { stdout } = await new Promise(res =>
102
+ exec('which chromium || which chromium-browser || true', (e, out) => res({ stdout: out }))
103
+ );
104
+ chromiumCheck = stdout.trim();
105
+ } catch { }
106
+ if (chromiumCheck) {
107
+ chromiumPath = chromiumCheck;
108
+ console.log('debug', `Found system Chromium: ${chromiumPath}`);
109
+ return chromiumPath;
110
+ }
111
+
112
+ if (this.logWarn) this.emit('warn', 'Chromium not found. Attempting installation...');
113
+
114
+ // --- apt-get ---
115
+ try {
116
+ await new Promise((res, rej) =>
117
+ exec('sudo apt-get update -y && sudo apt-get install -y chromium-browser chromium-codecs-ffmpeg', e => e ? rej(e) : res())
118
+ );
119
+ chromiumPath = '/usr/bin/chromium-browser';
120
+ console.log('debug', 'Chromium installed successfully via apt-get.');
121
+ return chromiumPath;
122
+ } catch {
123
+ if (this.logWarn) this.emit('warn', 'apt-get install failed. Trying apk or yum...');
124
+ }
102
125
 
103
- if (this.logWarn) this.emit('warn', 'Chromium not found. Attempting installation...');
126
+ // --- apk (Alpine) ---
127
+ try {
128
+ await new Promise((res, rej) =>
129
+ exec('sudo apk add --no-cache chromium ffmpeg', e => e ? rej(e) : res())
130
+ );
131
+ chromiumPath = '/usr/bin/chromium-browser';
132
+ console.log('debug', 'Chromium installed successfully via apk.');
133
+ return chromiumPath;
134
+ } catch {
135
+ if (this.logWarn) this.emit('warn', 'apk install failed. Trying yum...');
136
+ }
104
137
 
105
- // --- apt-get ---
106
- try {
107
- await new Promise((res, rej) =>
108
- require('child_process').exec('sudo apt-get update -y && sudo apt-get install -y chromium-browser chromium-codecs-ffmpeg', (e) => e ? rej(e) : res())
109
- );
110
- chromiumPath = '/usr/bin/chromium-browser';
111
- if (this.logDebug) this.emit('debug', 'Chromium installed successfully via apt-get.');
112
- return chromiumPath;
113
- } catch {
114
- if (this.logWarn) this.emit('warn', 'apt-get install failed. Trying apk or yum...');
115
- }
138
+ // --- yum (RHEL/CentOS) ---
139
+ try {
140
+ await new Promise((res, rej) =>
141
+ exec('sudo yum install -y chromium chromium-codecs-ffmpeg', e => e ? rej(e) : res())
142
+ );
143
+ chromiumPath = '/usr/bin/chromium-browser';
144
+ console.log('debug', 'Chromium installed successfully via yum.');
145
+ return chromiumPath;
146
+ } catch {
147
+ if (this.logWarn) this.emit('warn', 'yum install failed. Falling back to Puppeteer bundled Chromium.');
148
+ }
116
149
 
117
- // --- apk (Alpine) ---
118
- try {
119
- await new Promise((res, rej) =>
120
- require('child_process').exec('sudo apk add --no-cache chromium ffmpeg', (e) => e ? rej(e) : res())
121
- );
122
- chromiumPath = '/usr/bin/chromium-browser';
123
- if (this.logDebug) this.emit('debug', 'Chromium installed successfully via apk.');
150
+ // --- Fallback Puppeteer Chromium ---
151
+ chromiumPath = puppeteer.executablePath();
152
+ if (this.logWarn) this.emit('warn', `Using bundled Puppeteer Chromium at ${chromiumPath}`);
124
153
  return chromiumPath;
125
- } catch {
126
- if (this.logWarn) this.emit('warn', 'apk install failed. Trying yum...');
127
- }
128
154
 
129
- // --- yum (RHEL/CentOS) ---
130
- try {
131
- await new Promise((res, rej) =>
132
- require('child_process').exec('sudo yum install -y chromium chromium-codecs-ffmpeg', (e) => e ? rej(e) : res())
133
- );
134
- chromiumPath = '/usr/bin/chromium-browser';
135
- if (this.logDebug) this.emit('debug', 'Chromium installed successfully via yum.');
136
- return chromiumPath;
137
- } catch {
138
- if (this.logWarn) this.emit('warn', 'yum install failed. Falling back to Puppeteer bundled Chromium.');
155
+ } catch (err) {
156
+ if (this.logError) this.emit('error', `Chromium detection/install error: ${err.message}`);
157
+ throw err;
139
158
  }
140
-
141
- // --- Fallback ---
142
- chromiumPath = require('puppeteer-core').executablePath();
143
- if (this.logWarn) this.emit('warn', `Using bundled Puppeteer Chromium at ${chromiumPath}`);
144
- return chromiumPath;
145
-
146
- } catch (err) {
147
- if (this.logError) this.emit('error', `Chromium detection/install error: ${err.message}`);
148
- throw err;
149
159
  }
150
- }
151
-
152
160
 
153
161
 
154
162
  async isRunningInDocker() {
package/src/melcloud.js CHANGED
@@ -330,8 +330,8 @@ class MelCloud extends EventEmitter {
330
330
  try {
331
331
  const chromiumPath = await this.functions.ensureChromiumInstalled();
332
332
 
333
- // dynamiczny require dopiero przy uruchomieniu
334
- const puppeteer = require('puppeteer-core');
333
+ // --- dynamiczny import Puppeteer w ESM ---
334
+ const puppeteer = await import('puppeteer-core');
335
335
 
336
336
  browser = await puppeteer.launch({
337
337
  headless: true,
@@ -441,7 +441,6 @@ class MelCloud extends EventEmitter {
441
441
  }
442
442
  }
443
443
 
444
-
445
444
  async checkDevicesList() {
446
445
  let devices = [];
447
446
  switch (this.accountType) {