aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlonkaars <loek@pipeframe.xyz>2021-08-04 13:18:14 +0200
committerlonkaars <loek@pipeframe.xyz>2021-08-04 13:18:14 +0200
commit482e06a93f04e1544d06d0889dee49f51f9673c2 (patch)
treef52f48b91bafc8e3fd28dd276d3be9659cb70d91
parent7c93e78865698cc80dd96ccf0e7639cffc85d641 (diff)
plugin still doesn't load :(
-rw-r--r--.gitignore1
-rw-r--r--config.schema.json20
-rw-r--r--index.ts4
-rw-r--r--lamp.ts3
-rw-r--r--main.py1
-rw-r--r--package.json17
-rw-r--r--plugin.ts83
-rw-r--r--requirements.txt1
8 files changed, 65 insertions, 65 deletions
diff --git a/.gitignore b/.gitignore
index 7e325aa..b3ada5d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,4 @@
node_modules/
**/*.js
+venv/
diff --git a/config.schema.json b/config.schema.json
new file mode 100644
index 0000000..6a64a39
--- /dev/null
+++ b/config.schema.json
@@ -0,0 +1,20 @@
+{
+ "pluginAlias": "BekenBridge",
+ "pluginType": "accessory",
+ "singular": false,
+ "schema": {
+ "type": "object",
+ "properties": {
+ "name": {
+ "title": "Name",
+ "type": "string",
+ "required": true
+ },
+ "address": {
+ "title": "Bluetooth address of lamp",
+ "type": "string",
+ "required": true
+ }
+ }
+ }
+}
diff --git a/index.ts b/index.ts
index 767376c..b85e13f 100644
--- a/index.ts
+++ b/index.ts
@@ -2,6 +2,6 @@ import { API } from 'homebridge';
import BekenBridge from './plugin';
-export default function Plugin(api: API) {
- api.registerPlatform('BekenBridge', BekenBridge);
+module.exports = (api: API) => {
+ api.registerAccessory('BekenBridge', BekenBridge);
}
diff --git a/lamp.ts b/lamp.ts
index dfe12da..83e6d8c 100644
--- a/lamp.ts
+++ b/lamp.ts
@@ -7,7 +7,7 @@ export default class Lamp {
private subpr: ChildProcess;
constructor(public addr: string) {
- this.subpr = spawn('python3', ['./main.py', addr]);
+ this.subpr = spawn('./venv/bin/python3', ['./main.py', addr]);
}
set color(newColor: LampColor) {
@@ -23,3 +23,4 @@ export default class Lamp {
return this.color.map(i => i.toString(16).padStart(2, '0')).join('');
}
}
+
diff --git a/main.py b/main.py
index 88a7557..d2debb7 100644
--- a/main.py
+++ b/main.py
@@ -2,7 +2,6 @@
from bluepy.btle import Peripheral, ADDR_TYPE_PUBLIC, BTLEDisconnectError
import threading
import time
-import colorsys
import sys
mac = sys.argv[1]
diff --git a/package.json b/package.json
index 711f8f0..58ae9ef 100644
--- a/package.json
+++ b/package.json
@@ -1,24 +1,33 @@
{
+ "displayName": "Beken LED Homebridge plugin",
"name": "homebridge-beken",
"version": "0.1.0",
"description": "homebridge beken led plugin",
- "main": "index.js",
"repository": "git@pipeframe.xyz:lonkaars/beken-homebridge",
"author": "lonkaars <loek@pipeframe.xyz>",
"license": "MIT",
"private": false,
"type": "module",
+ "main": "./index.js",
+ "keywords": [
+ "homebridge-plugin"
+ ],
+ "engines": {
+ "node": ">=16.0.0",
+ "homebridge": ">=1.3.0"
+ },
"scripts": {
- "build": "tsc"
+ "build": "tsc",
+ "perms": "sudo setcap 'cap_net_raw,cap_net_admin+eip' venv/lib/python3.9/site-packages/bluepy/bluepy-helper"
},
"dependencies": {
"@abandonware/noble": "^1.9.2-14",
- "color": "^4.0.0",
- "homebridge": "^1.3.4"
+ "color": "^4.0.0"
},
"devDependencies": {
"@types/color": "^3.0.2",
"@types/node": "^16.4.10",
+ "homebridge": "^1.3.4",
"typescript": "^4.3.5"
}
}
diff --git a/plugin.ts b/plugin.ts
index 01af191..04664e1 100644
--- a/plugin.ts
+++ b/plugin.ts
@@ -1,73 +1,42 @@
import {
API,
- Characteristic,
- DynamicPlatformPlugin,
+ AccessoryPlugin,
Logger,
- PlatformAccessory,
- PlatformConfig,
- Service,
+ AccessoryConfig,
+ Service
+
} from 'homebridge';
-export default class BekenBridge implements DynamicPlatformPlugin {
- public readonly Service: typeof Service = this.api.hap.Service;
- public readonly Characteristic: typeof Characteristic = this.api.hap.Characteristic;
+import Lamp, { LampColor } from './lamp';
+
+export default class BekenBridge implements AccessoryPlugin {
+ private lamp: Lamp;
+ private bulbService: Service;
+ private infoService: Service;
- public readonly accessories: PlatformAccessory[] = [];
+ public name: string;
constructor(
public readonly log: Logger,
- public readonly config: PlatformConfig,
+ public readonly config: AccessoryConfig,
public readonly api: API,
) {
- this.log.debug('Loaded BekenBridge');
-
- this.api.on('didFinishLaunching', () => {
- log.debug('Executed didFinishLaunching callback');
- this.discoverDevices();
- });
- }
+ console.log("reached constructor"); //DEBUG
+ // this.name = config.name;
+ // this.lamp = new Lamp(config.address);
- configureAccessory(accessory: PlatformAccessory) {
- this.log.info('Loading accessory from cache:', accessory.displayName);
+ // this.infoService = new this.api.hap.Service.AccessoryInformation()
+ // .setCharacteristic(this.api.hap.Characteristic.Manufacturer, "Beken")
+ // .setCharacteristic(this.api.hap.Characteristic.Model, "Beken LED");
- this.accessories.push(accessory);
+ // this.bulbService = new this.api.hap.Service.Lightbulb(this.name);
}
-
- discoverDevices() {
- this.log.info('gert');
- // const exampleDevices = [
- // {
- // exampleUniqueId: 'ABCD',
- // exampleDisplayName: 'Bedroom',
- // },
- // {
- // exampleUniqueId: 'EFGH',
- // exampleDisplayName: 'Kitchen',
- // },
- // ];
-
- // for (const device of exampleDevices) {
-
- // const uuid = this.api.hap.uuid.generate(device.exampleUniqueId);
-
- // const existingAccessory = this.accessories.find(accessory => accessory.UUID === uuid);
-
- // if (existingAccessory) {
- // this.log.info('Restoring existing accessory from cache:', existingAccessory.displayName);
-
- // new ExamplePlatformAccessory(this, existingAccessory);
-
- // } else {
- // this.log.info('Adding new accessory:', device.exampleDisplayName);
-
- // const accessory = new this.api.platformAccessory(device.exampleDisplayName, uuid);
-
- // accessory.context.device = device;
-
- // new ExamplePlatformAccessory(this, accessory);
-
- // this.api.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [accessory]);
- // }
- // }
+
+ getServices() {
+ console.log("getting services"); //DEBUG
+ return [
+ // this.infoService,
+ // this.bulbService
+ ];
}
}
diff --git a/requirements.txt b/requirements.txt
new file mode 100644
index 0000000..356deaa
--- /dev/null
+++ b/requirements.txt
@@ -0,0 +1 @@
+bluepy==1.3.0