diff --git a/Dockerfile b/plejd/Dockerfile similarity index 100% rename from Dockerfile rename to plejd/Dockerfile diff --git a/api.js b/plejd/api.js similarity index 83% rename from api.js rename to plejd/api.js index f668db3..4ea64eb 100644 --- a/api.js +++ b/plejd/api.js @@ -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; } diff --git a/build.json b/plejd/build.json similarity index 100% rename from build.json rename to plejd/build.json diff --git a/config.json b/plejd/config.json similarity index 72% rename from config.json rename to plejd/config.json index 4c4cf98..60a5780 100644 --- a/config.json +++ b/plejd/config.json @@ -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" } } \ No newline at end of file diff --git a/main.js b/plejd/main.js similarity index 100% rename from main.js rename to plejd/main.js diff --git a/mqtt.js b/plejd/mqtt.js similarity index 100% rename from mqtt.js rename to plejd/mqtt.js diff --git a/package.json b/plejd/package.json similarity index 100% rename from package.json rename to plejd/package.json diff --git a/plejd.js b/plejd/plejd.js similarity index 100% rename from plejd.js rename to plejd/plejd.js diff --git a/rootfs/etc/services.d/plejd/finish b/plejd/rootfs/etc/services.d/plejd/finish similarity index 100% rename from rootfs/etc/services.d/plejd/finish rename to plejd/rootfs/etc/services.d/plejd/finish diff --git a/rootfs/etc/services.d/plejd/run b/plejd/rootfs/etc/services.d/plejd/run similarity index 100% rename from rootfs/etc/services.d/plejd/run rename to plejd/rootfs/etc/services.d/plejd/run diff --git a/rootfs/usr/bin/plejd.sh b/plejd/rootfs/usr/bin/plejd.sh similarity index 79% rename from rootfs/usr/bin/plejd.sh rename to plejd/rootfs/usr/bin/plejd.sh index 1e9eb43..56b9372 100644 --- a/rootfs/usr/bin/plejd.sh +++ b/plejd/rootfs/usr/bin/plejd.sh @@ -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\" } " diff --git a/repository.json b/repository.json new file mode 100644 index 0000000..a6e65a3 --- /dev/null +++ b/repository.json @@ -0,0 +1,6 @@ +{ + "name": "Unofficial Plejd Add-on", + "url": "https://github.com/icanos/hassio-plejd", + "maintainer": "Marcus Westin " + } + \ No newline at end of file