diff options
author | lonkaars <loek@pipeframe.xyz> | 2021-08-05 16:58:28 +0200 |
---|---|---|
committer | lonkaars <loek@pipeframe.xyz> | 2021-08-05 16:58:28 +0200 |
commit | 34144332104dbbb2c1243ccfac79a8f81516e53d (patch) | |
tree | 090344602ff2f0136c9deeb9b0bf76a6c749ca45 /lamp.ts | |
parent | 333fc4c069e7101ea7b192e2d50fc5858c5adee4 (diff) |
working homebridge plugin
Diffstat (limited to 'lamp.ts')
-rw-r--r-- | lamp.ts | 18 |
1 files changed, 16 insertions, 2 deletions
@@ -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); +// } |