homebridge-melcloud-control 4.0.0-beta.443 → 4.0.0-beta.444

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.443",
4
+ "version": "4.0.0-beta.444",
5
5
  "description": "Homebridge plugin to control Mitsubishi Air Conditioner, Heat Pump and Energy Recovery Ventilation.",
6
6
  "license": "MIT",
7
7
  "author": "grzegorz914",
@@ -39,7 +39,7 @@
39
39
  "async-mqtt": "^2.6.3",
40
40
  "axios": "^1.13.0",
41
41
  "express": "^5.1.0",
42
- "puppeteer-core": "^24.26.1",
42
+ "puppeteer": "^24.26.1",
43
43
  "axios-cookiejar-support": "^6.0.4",
44
44
  "tough-cookie": "^6.0.0",
45
45
  "jsdom": "^27.0.1"
package/src/functions.js CHANGED
@@ -1,7 +1,10 @@
1
1
  import fs from 'fs';
2
+ import util from 'util';
2
3
  import { promises as fsPromises } from 'fs';
3
4
  import { exec } from 'child_process';
4
- import puppeteer from 'puppeteer-core';
5
+ import puppeteer from 'puppeteer';
6
+ const access = util.promisify(fs.access);
7
+ const execPromise = util.promisify(exec);
5
8
 
6
9
  class Functions {
7
10
  constructor() {
@@ -52,44 +55,35 @@ class Functions {
52
55
 
53
56
  try {
54
57
  // --- 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(`Detected architecture: ${arch}`);
62
- } catch (err) {
63
- console.log(`Failed to detect architecture: ${err.message}`);
64
- }
58
+ const { stdout: archOut } = await execPromise('uname -m');
59
+ const arch = archOut.trim();
60
+ console.log(`Detected architecture: ${arch}`);
65
61
 
66
62
  // --- 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(`Detected OS: ${osName}`);
74
- } catch (err) {
75
- console.log(`Failed to detect OS: ${err.message}`);
76
- }
63
+ const { stdout: osOut } = await execPromise('uname -s');
64
+ const osName = osOut.trim();
65
+ console.log(`Detected OS: ${osName}`);
77
66
 
78
67
  // --- macOS fallback ---
79
68
  if (osName === 'Darwin') {
80
- console.log('Running on macOS — using system Chromium/Chrome');
81
69
  chromiumPath = '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome';
82
- console.log(`Chromium path: ${chromiumPath}`);
70
+
71
+ try {
72
+ await access(chromiumPath, fs.constants.X_OK);
73
+ console.log(`Using system Chrome at ${chromiumPath}`);
74
+ } catch {
75
+ console.log('System Chrome not found. Falling back to Puppeteer bundled Chromium.');
76
+ chromiumPath = puppeteer.executablePath();
77
+ }
78
+
83
79
  return chromiumPath;
84
80
  }
85
81
 
86
82
  // --- Linux distro detection ---
87
83
  let linuxDistro = 'unknown';
88
84
  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';
85
+ const { stdout: distroOut } = await execPromise('cat /etc/os-release');
86
+ linuxDistro = distroOut.split('\n')[0] || 'unknown';
93
87
  } catch {
94
88
  console.log('/etc/os-release not found, skipping OS detection.');
95
89
  }
@@ -98,10 +92,8 @@ class Functions {
98
92
  // --- Check if Chromium exists ---
99
93
  let chromiumCheck = '';
100
94
  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();
95
+ const { stdout: checkOut } = await execPromise('which chromium || which chromium-browser || true');
96
+ chromiumCheck = checkOut.trim();
105
97
  } catch { }
106
98
  if (chromiumCheck) {
107
99
  chromiumPath = chromiumCheck;
@@ -113,57 +105,36 @@ class Functions {
113
105
 
114
106
  // --- apt-get ---
115
107
  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';
108
+ await execPromise('sudo apt-get update -y && sudo apt-get install -y chromium-browser chromium-codecs-ffmpeg');
120
109
  console.log('Chromium installed successfully via apt-get.');
121
110
  return chromiumPath;
122
- } catch {
123
- console.log('apt-get install failed. Trying apk or yum...');
124
- }
111
+ } catch { console.log('apt-get install failed. Trying apk or yum...'); }
125
112
 
126
113
  // --- apk (Alpine) ---
127
114
  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';
115
+ await execPromise('sudo apk add --no-cache chromium ffmpeg');
132
116
  console.log('Chromium installed successfully via apk.');
133
117
  return chromiumPath;
134
- } catch {
135
- console.log('apk install failed. Trying yum...');
136
- }
118
+ } catch { console.log('apk install failed. Trying yum...'); }
137
119
 
138
120
  // --- yum (RHEL/CentOS) ---
139
121
  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';
122
+ await execPromise('sudo yum install -y chromium chromium-codecs-ffmpeg');
144
123
  console.log('Chromium installed successfully via yum.');
145
124
  return chromiumPath;
146
- } catch {
147
- console.log('yum install failed. Falling back to Puppeteer bundled Chromium.');
148
- }
125
+ } catch { console.log('yum install failed. Falling back to Puppeteer bundled Chromium.'); }
149
126
 
150
- // --- Fallback Puppeteer Chromium ---
127
+ // --- Fallback Puppeteer ---
151
128
  chromiumPath = puppeteer.executablePath();
152
- if (!chromiumPath) {
153
- console.log('Puppeteer bundled Chromium not found');
154
- throw new Error('Puppeteer bundled Chromium not found');
155
- }
156
- console.log(`Using bundled Puppeteer Chromium at ${chromiumPath}`);
129
+ console.log(`Using bundled Puppeteer Chromium at ${chromiumPath || 'not found'}`);
157
130
  return chromiumPath;
158
131
 
159
- } catch (err) {
160
- console.log(`Chromium detection/install error: ${err.message}`);
161
- throw err;
132
+ } catch (error) {
133
+ throw new Error(`Chromium detection/install error: ${error.message}`);
162
134
  }
163
135
  }
164
136
 
165
137
 
166
-
167
138
  async isRunningInDocker() {
168
139
  try {
169
140
  if (fs.existsSync('/.dockerenv')) return true;
package/src/melcloud.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import axios from 'axios';
2
2
  import EventEmitter from 'events';
3
- import puppeteer from 'puppeteer-core';
3
+ import puppeteer from 'puppeteer';
4
4
  import MelCloudHomeToken from './melcloudhometoken.js';
5
5
  import ImpulseGenerator from './impulsegenerator.js';
6
6
  import Functions from './functions.js';
@@ -342,7 +342,6 @@ class MelCloud extends EventEmitter {
342
342
  });
343
343
 
344
344
  const page = await browser.newPage();
345
-
346
345
  page.on('error', err => { if (this.logError) this.emit('error', `Page crashed: ${err.message}`); });
347
346
  page.on('pageerror', err => { if (this.logError) this.emit('error', `Browser error: ${err.message}`); });
348
347
  page.on('close', () => { if (this.logDebug) this.emit('debug', 'Page was closed unexpectedly'); });