From 7ba38d6acf306cb72dfca77e07ddca12e3afd376 Mon Sep 17 00:00:00 2001 From: faanskit Date: Fri, 7 May 2021 08:52:57 +0200 Subject: [PATCH] Lights and switches, including roomsAsLighs, is now proposing an area for Home Assistant based on the room name from Plejd. This by using suggested_area in MQTT config. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In many installations, Plejd units have the same name and are separated by the room they belong to. Eg. Badrum -> Spottar, Kök->Spottar, Sovrum->Taklampa, Kök->Taklampa With 8.0.0 devices can have the same name, and therefore it makes sense to now also support areas. --- plejd/MqttClient.js | 1 + plejd/PlejdApi.js | 5 +++++ plejd/types/DeviceRegistry.d.ts | 1 + 3 files changed, 7 insertions(+) diff --git a/plejd/MqttClient.js b/plejd/MqttClient.js index 64586bd..d10840b 100644 --- a/plejd/MqttClient.js +++ b/plejd/MqttClient.js @@ -69,6 +69,7 @@ const getOutputDeviceDiscoveryPayload = ( manufacturer: 'Plejd', model: device.typeName, name: device.name, + ...(device.roomName !== undefined ? { suggested_area: device.roomName } : {}), sw_version: device.version, }, ...(device.type === MQTT_TYPES.LIGHT ? { brightness: device.dimmable, schema: 'json' } : {}), diff --git a/plejd/PlejdApi.js b/plejd/PlejdApi.js index ab5cbf4..a338cba 100644 --- a/plejd/PlejdApi.js +++ b/plejd/PlejdApi.js @@ -436,6 +436,8 @@ class PlejdApi { loadType = 'light'; } + const room = this.siteDetails.rooms.find((x) => x.roomId === device.roomId); + /** @type {import('types/DeviceRegistry').OutputDevice} */ const outputDevice = { bleOutputAddress, @@ -446,6 +448,7 @@ class PlejdApi { name: device.title, output: deviceOutput, roomId: device.roomId, + roomName: room.title, state: undefined, type: loadType, typeName, @@ -519,6 +522,7 @@ class PlejdApi { name: room.title, output: undefined, roomId, + roomName: room.title, state: undefined, type: 'light', typeName: 'Room', @@ -548,6 +552,7 @@ class PlejdApi { name: scene.title, output: undefined, roomId: undefined, + roomName: undefined, state: false, type: 'scene', typeName: 'Scene', diff --git a/plejd/types/DeviceRegistry.d.ts b/plejd/types/DeviceRegistry.d.ts index 5ee68ae..9e4d6ba 100644 --- a/plejd/types/DeviceRegistry.d.ts +++ b/plejd/types/DeviceRegistry.d.ts @@ -13,6 +13,7 @@ export interface OutputDevice { name: string; output: number; roomId: string; + roomName: string; state: boolean | undefined; type: string; typeName: string;