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

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