Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
emilohman committed Oct 1, 2019
0 parents commit 97fac49
Show file tree
Hide file tree
Showing 24 changed files with 1,695 additions and 0 deletions.
57 changes: 57 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Plejd

This App brings support for the Plejd devices.

## Q&A

> **Q1** Why can’t Homey connect to Plejd?
* _Check if the Plejd mesh is not connected to another bluetooth device. The `Plejd` app for example_

> **Q2** Why is the Plejd devices displaying wrong states in Homey?
* _It’s because Homey can’t get the state from the Plejd device due to limitation in Homeys Bluetooth support. See https://github.com/athombv/homey-apps-sdk-issues/issues/81._

## Usage

Obtaining the crypto key and the device ids is a crucial step to get this
running, for this it is required to get the .site json file from the plejd app on android or iOS. Then enter them while adding devices to Homey.

### Steps for android:

1. Turn on USB debugging and connect the phone to a computer.
2. Extract a backup from the phone:
```
$ adb backup com.plejd.plejdapp
```
3. Unpack the backup:
```
$ dd if=backup.ab bs=1 skip=24 | python -c "import zlib,sys;sys.stdout.write(zlib.decompress(sys.stdin.read()))" | tar -xv
```
4. Recover the .site file:
```
$ cp apps/com.plejd.plejdapp/f/*/*.site site.json
```

### Steps for iOS:

1. Open a backup in iBackup viewer.
2. Select raw files, look for AppDomainGroup-group.com.plejd.consumer.light.
3. In AppDomainGroup-group.com.plejd.consumer.light/Documents there should be two folders.
4. The folder that isn't named ".config" contains the .site file.

### Gather cryto key and ids for devices

When the site.json file has been recovered the cryptokey and the output
addresses can be extracted:

1. Extract the cryptoKey:
```
$ cat site.json | jq '.PlejdMesh.CryptoKey' | sed 's/-//g'
```
2. Extract the outputAddresses:
```
$ cat site.json | jq '.PlejdMesh.outputAdresses' | grep -v '\$type' | jq '.[][]'
```

Or just open site.json in your favorite editor and extract the crypto key and output addresses (IDs).
12 changes: 12 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
'use strict';

const Homey = require('homey');

class PlejdApp extends Homey.App {

async onInit() {
this.log('PlejdApp is running...');
}
}

module.exports = PlejdApp;
65 changes: 65 additions & 0 deletions app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
{
"id": "se.emilohman.plejd",
"version": "0.0.1",
"compatibility": ">=2.1.2",
"sdk": 2,
"name": {
"en": "Plejd"
},
"description": {
"en": "Adds support for Plejd devices."
},
"tags": {
"en": [ "plejd, light, bluetooth, BLE, dimmer" ]
},
"category": [
"lights"
],
"permissions": [
"homey:wireless:ble"
],
"images": {
"large": "/assets/images/large.png",
"small": "/assets/images/small.png"
},
"author": {
"name": "Emil Öhman",
"email": "emilohman@gmail.com"
},
"contributors": {
"developers": [
{
"name": "Emil Öhman",
"email": "emilohman@gmail.com"
}
]
},
"drivers": [
{
"id": "plejd",
"name": {
"en": "Plejd"
},
"class": "light",
"capabilities": [
"dim",
"onoff"
],
"images": {
"large": "/drivers/plejd/assets/images/large.png",
"small": "/drivers/plejd/assets/images/small.png"
},
"pair": [
{
"id": "settings",
"navigation": {
"next": "done"
}
},
{
"id": "done"
}
]
}
]
}
16 changes: 16 additions & 0 deletions assets/icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/large.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/small.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added drivers/plejd/assets/images/large.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added drivers/plejd/assets/images/small.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
59 changes: 59 additions & 0 deletions drivers/plejd/device.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
'use strict';

const Homey = require('homey');

class PlejdDevice extends Homey.Device {

onInit() {
const driver = this.getDriver();
this.log('Plejd Device (' + this.getName() + ') initialized');
this.log('id: ', this.getData().id);
this.log('plejdId: ', this.getData().plejdId);
this.log('count ', driver.getDevices().length);

this.registerCapabilityListener("onoff", async value => {
this.log(`Power is set to: ${value} for id ${this.getData().plejdId}`);
if (value) {
return await driver.turnOn(parseInt(this.getData().plejdId));
} else {
return await driver.turnOff(parseInt(this.getData().plejdId));
}
});

this.registerCapabilityListener("dim", async value => {
this.log(`Brightness is set to ${value}`);

const brightness = parseInt(255 * value);
if (brightness == 0) {
return await driver.turnOff(this.getData().plejdId);
} else {
return await driver.turnOn(this.getData().plejdId, brightness);
}
});
}

async onAdded() {
const driver = this.getDriver();

this.log('Adding device: ' + this.getName() + ' (' + this.getData().id + ')');
this.log('count ', driver.getDevices().length);

if (driver.getDevices().length === 1) {
await driver.connect();
}
}

async onDeleted() {
const driver = this.getDriver();

this.log('device deleted: ' + this.getName());
this.log('count ', driver.getDevices().length);

if (driver.getDevices().length === 0) {
await driver.disconnect();
}
}

}

module.exports = PlejdDevice;
Loading

0 comments on commit 97fac49

Please sign in to comment.