aboutsummaryrefslogtreecommitdiff
path: root/lamp.ts
diff options
context:
space:
mode:
Diffstat (limited to 'lamp.ts')
-rw-r--r--lamp.ts18
1 files changed, 16 insertions, 2 deletions
diff --git a/lamp.ts b/lamp.ts
index 83e6d8c..2584192 100644
--- a/lamp.ts
+++ b/lamp.ts
@@ -1,4 +1,6 @@
import { ChildProcess, spawn } from 'child_process';
+import { Logger } from 'homebridge';
+import { join } from 'path';
export type LampColor = [number, number, number, number];
@@ -6,8 +8,12 @@ export default class Lamp {
#color: LampColor;
private subpr: ChildProcess;
- constructor(public addr: string) {
- this.subpr = spawn('./venv/bin/python3', ['./main.py', addr]);
+ constructor(public addr: string, public log: Logger) {
+ this.subpr = spawn(join(__dirname, '/venv/bin/python3'), [join(__dirname, './main.py'), addr]);
+
+ // debug
+ this.subpr.stderr.on('data', this.log.error);
+ this.subpr.stdout.on('data', this.log.log);
}
set color(newColor: LampColor) {
@@ -24,3 +30,11 @@ export default class Lamp {
}
}
+// ! DEBUG
+// if (typeof require !== 'undefined' && require.main === module) {
+// var lamp = new Lamp("FC:58:FA:A1:CF:F1");
+//
+// setInterval(() => {
+// lamp.color = [0, 0, 0, Math.floor(Math.random() * 255)];
+// }, 100);
+// }