Add Room/Group Name to Light Name (#1303)

* Hue Node: Add Room/Group Name to Light Name

To easier identify lights in the dropdown it is useful to know to which group (room) they belong.
While lights can be added to multiple zones, they can only ever belong to one room.

*  Small improvemenets to (#1299)

Co-authored-by: Robert Kaelin <robertkaelin@users.noreply.github.com>
This commit is contained in:
Ricardo Espinoza 2021-01-07 01:58:08 -05:00 committed by GitHub
parent 9c479abc35
commit 1c615b615f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -77,9 +77,23 @@ export class PhilipsHue implements INodeType {
'GET', 'GET',
`/bridge/${user}/lights`, `/bridge/${user}/lights`,
); );
const groups = await philipsHueApiRequest.call(
this,
'GET',
`/bridge/${user}/groups`,
);
for (const light of Object.keys(lights)) { for (const light of Object.keys(lights)) {
const lightName = lights[light].name; let lightName = lights[light].name;
const lightId = light; const lightId = light;
for (const groupId of Object.keys(groups)) {
if(groups[groupId].type === 'Room' && groups[groupId].lights.includes(lightId)) {
lightName = `${groups[groupId].name}: ${lightName}`;
}
}
returnData.push({ returnData.push({
name: lightName, name: lightName,
value: lightId, value: lightId,