aboutsummaryrefslogtreecommitdiff
path: root/lamp.ts
diff options
context:
space:
mode:
authorLoek Le Blansch <32883851+lonkaars@users.noreply.github.com>2021-08-13 14:03:33 +0200
committerGitHub <noreply@github.com>2021-08-13 14:03:33 +0200
commitf1872e3b036e679d8e6b5f8e08c31da18caaa37a (patch)
treed5ff7c3656868780a4f29461eb3bbec535ec3cfa /lamp.ts
parentb8c9fc19e6e35679a1b9125396448987d7a6e8d0 (diff)
parent886630c94bd76b5bec9aa5b2eeb8a6da7d6a0cc2 (diff)
Merge pull request #1 from lonkaars/homeassistant
homebridge to homeassistant
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);
-// }