aboutsummaryrefslogtreecommitdiff
path: root/lamp.ts
diff options
context:
space:
mode:
Diffstat (limited to 'lamp.ts')
-rw-r--r--lamp.ts44
1 files changed, 0 insertions, 44 deletions
diff --git a/lamp.ts b/lamp.ts
deleted file mode 100644
index b9a16a8..0000000
--- a/lamp.ts
+++ /dev/null
@@ -1,44 +0,0 @@
-import { ChildProcess, spawn } from 'child_process';
-import { Logger } from 'homebridge';
-import { join } from 'path';
-
-export type LampColor = [number, number, number, number];
-
-export default class Lamp {
- #color: LampColor;
- private subpr: ChildProcess;
- private last: string;
-
- 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) {
- this.#color = newColor.map(c => Math.floor(c)) as LampColor;
- var message = this.colorToString();
- if (this.last == message) return; // prevent duplicate messages
- this.subpr.stdin.write(message + '\n');
- this.last = message;
- }
-
- get color() {
- return this.#color;
- }
-
- private colorToString() {
- return this.color.map(i => i.toString(16).padStart(2, '0')).join('');
- }
-}
-
-// ! 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);
-// }