changed layout to work as a repository in hassio
This commit is contained in:
parent
acb3cc1ad3
commit
471ec7023e
12 changed files with 47 additions and 14 deletions
|
|
@ -22,9 +22,10 @@ const logger = getLogger();
|
|||
// #endregion
|
||||
|
||||
class PlejdApi extends EventEmitter {
|
||||
constructor(siteName, username, password) {
|
||||
constructor(siteName, username, password, includeRoomsAsLights) {
|
||||
super();
|
||||
|
||||
this.includeRoomsAsLights = includeRoomsAsLights;
|
||||
this.siteName = siteName;
|
||||
this.username = username;
|
||||
this.password = password;
|
||||
|
|
@ -89,6 +90,8 @@ class PlejdApi extends EventEmitter {
|
|||
logger(JSON.stringify(this.site));
|
||||
}
|
||||
|
||||
const roomDevices = {};
|
||||
|
||||
for (let i = 0; i < this.site.devices.length; i++) {
|
||||
const device = this.site.devices[i];
|
||||
const deviceId = device.deviceId;
|
||||
|
|
@ -119,9 +122,37 @@ class PlejdApi extends EventEmitter {
|
|||
|
||||
logger(JSON.stringify(newDevice));
|
||||
|
||||
if (roomDevices[device.roomId]) {
|
||||
roomDevices[device.roomId].push(newDevice);
|
||||
}
|
||||
else {
|
||||
roomDevices[device.roomId] = [newDevice];
|
||||
}
|
||||
|
||||
devices.push(newDevice);
|
||||
}
|
||||
|
||||
if (this.includeRoomsAsLights) {
|
||||
logger('includeRoomsAsLights is set to true, adding rooms too.');
|
||||
for (let i = 0; i < this.site.rooms.length; i++) {
|
||||
const room = this.site.rooms[i];
|
||||
const roomId = room.roomId;
|
||||
const roomAddress = this.site.roomAddress[roomId];
|
||||
|
||||
const newDevice = {
|
||||
id: roomAddress,
|
||||
name: room.title,
|
||||
type: 'light',
|
||||
typeName: 'Room',
|
||||
dimmable: roomDevices[roomId].find(x => x.dimmable).length > 0
|
||||
};
|
||||
|
||||
logger(JSON.stringify(newDevice));
|
||||
|
||||
devices.push(newDevice);
|
||||
}
|
||||
}
|
||||
|
||||
return devices;
|
||||
}
|
||||
|
||||
|
|
@ -1,8 +1,9 @@
|
|||
{
|
||||
"name": "Plejd",
|
||||
"version": "3",
|
||||
"version": "4",
|
||||
"slug": "plejd",
|
||||
"description": "Adds support for the Swedish home automation devices from Plejd.",
|
||||
"url": "https://github.com/icanos/hassio-plejd/",
|
||||
"arch": [
|
||||
"armhf",
|
||||
"armv7",
|
||||
|
|
@ -12,15 +13,6 @@
|
|||
],
|
||||
"startup": "application",
|
||||
"boot": "auto",
|
||||
"auto_uart": true,
|
||||
"gpio": true,
|
||||
"privileged": [
|
||||
"SYS_RAWIO"
|
||||
],
|
||||
"devices": [
|
||||
"/dev/mem:/dev/mem:rwm"
|
||||
],
|
||||
"apparmor": false,
|
||||
"host_network": true,
|
||||
"options": {
|
||||
"site": "Default Site",
|
||||
|
|
@ -28,7 +20,8 @@
|
|||
"password": "",
|
||||
"mqttBroker": "mqtt://",
|
||||
"mqttUsername": "",
|
||||
"mqttPassword": ""
|
||||
"mqttPassword": "",
|
||||
"includeRoomsAsLights": false
|
||||
},
|
||||
"schema": {
|
||||
"site": "str",
|
||||
|
|
@ -36,6 +29,7 @@
|
|||
"password": "str",
|
||||
"mqttBroker": "str",
|
||||
"mqttUsername": "str",
|
||||
"mqttPassword": "str"
|
||||
"mqttPassword": "str",
|
||||
"includeRoomsAsLights": "bool"
|
||||
}
|
||||
}
|
||||
|
|
@ -8,6 +8,7 @@ PASSWORD=$(jq --raw-output ".password" $CONFIG_PATH)
|
|||
MQTTBROKER=$(jq --raw-output ".mqttBroker" $CONFIG_PATH)
|
||||
MQTTUSERNAME=$(jq --raw-output ".mqttUsername" $CONFIG_PATH)
|
||||
MQTTPASSWORD=$(jq --raw-output ".mqttPassword" $CONFIG_PATH)
|
||||
INCLUDEROOMSASLIGHTS=$(jq --raw-output ".includeRoomsAsLights" $CONFIG_PATH)
|
||||
|
||||
PLEJD_PATH=/data/plejd.json
|
||||
PLEJD_CONFIG="{
|
||||
|
|
@ -16,7 +17,8 @@ PLEJD_CONFIG="{
|
|||
\"password\": \"$PASSWORD\",
|
||||
\"mqttBroker\": \"$MQTTBROKER\",
|
||||
\"mqttUsername\": \"$MQTTUSERNAME\",
|
||||
\"mqttPassword\": \"$MQTTPASSWORD\"
|
||||
\"mqttPassword\": \"$MQTTPASSWORD\",
|
||||
\"includeRoomsAsLights\": \"$INCLUDEROOMSASLIGHTS\"
|
||||
}
|
||||
"
|
||||
|
||||
6
repository.json
Normal file
6
repository.json
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"name": "Unofficial Plejd Add-on",
|
||||
"url": "https://github.com/icanos/hassio-plejd",
|
||||
"maintainer": "Marcus Westin <marcus@sekurbit.se>"
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue