-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
71f0912
commit f2144a8
Showing
3 changed files
with
80 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
name: Test | ||
|
||
on: [push, pull_request] | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
|
||
strategy: | ||
matrix: | ||
# the Node.js versions to build on | ||
node-version: [18.x, 20.x, 22.x] | ||
homebridge-version: ['^1.8.0', '^2.0.0-beta.0'] | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Use Node.js ${{ matrix.node-version }} | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
|
||
- name: Install dependencies | ||
run: npm install | ||
|
||
- name: Use homebridge ${{ matrix.homebridge-version }} | ||
run: npm install homebridge@${{ matrix.homebridge-version }} | ||
|
||
- name: Build the project | ||
run: npm run build | ||
|
||
- name: Tune the tests | ||
run: npm run test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Homebridge plugin for AEG RX 9 / Electrolux Pure i9 robot vacuum | ||
// Copyright © 2024 Alexander Thoukydides | ||
|
||
import { spawn } from 'child_process'; | ||
import assert from 'node:assert'; | ||
|
||
// Command to use to launch Homebridge | ||
const SPAWN_COMMAND = 'homebridge'; | ||
const SPAWN_ARGS = '-D -I -P .. --strict-plugin-resolution'.split(' '); | ||
|
||
// Log messages indicating success | ||
const SUCCESS_OUTPUT_REGEX = /\[Homebridge AEG Robot Vacuum\] (Starting new authorisation|Using saved access token)/; | ||
|
||
// Length of time to wait for the message | ||
const TIMEOUT_MS = 15 * 1000; // (15 seconds) | ||
|
||
// Run the test | ||
void (async (): Promise<void> => { | ||
// Attempt to launch Homebridge | ||
const homebridge = spawn(SPAWN_COMMAND, SPAWN_ARGS, { stdio: 'pipe', timeout: TIMEOUT_MS }); | ||
|
||
// Log any error output | ||
//homebridge.stderr.on('data', (data) => { console.error(`stderr: ${data.trim()}`); }); | ||
|
||
// Collect stdout and check for success message(s) | ||
let output = ''; | ||
homebridge.stdout.setEncoding('utf8'); | ||
for await (const chunk of homebridge.stdout) { | ||
assert(typeof chunk === 'string'); | ||
output += chunk.toString(); | ||
if (SUCCESS_OUTPUT_REGEX.test(output)) { | ||
// Test completed successfully | ||
homebridge.kill('SIGTERM'); | ||
console.log('Success'); | ||
return; | ||
} | ||
} | ||
|
||
// Homebridge did not start successfully | ||
switch (homebridge.exitCode) { | ||
case null: throw new Error('Unexpected stdout termination'); | ||
case 0: throw new Error('Unexpected successful process termination'); | ||
default: throw new Error(`Homebridge exited with code ${homebridge.exitCode}`); | ||
} | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters