Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use light names for objects #11

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 20 additions & 12 deletions interfaces/philipsHue/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -383,23 +383,31 @@ if (exports.enabled) {
exports.settings.status.lights = lightInfo;

// Set up server-side frames, nodes, and listeners for all known lights
for (var lightId in lights) {
console.log('add lightId', lightId);
const frameId = lightId + 'frame';
server.addNode(lightId, frameId, 'switch', 'node');
server.addNode(lightId, frameId, 'brightness', 'node');
for (let lightId in lights) {
let lightName = lightId;

if(lights[lightId].hasOwnProperty("name")){
if(lights[lightId].name) {
lightName = lightId+"_"+lights[lightId].name;
}
}

console.log('add lightId', lightName);
const frameId = lightName + '_tool';
server.addNode(lightName, frameId, 'switch', 'node');
server.addNode(lightName, frameId, 'brightness', 'node');
if (lights[lightId].colorful) {
server.addNode(lightId, frameId, 'hue', 'node');
server.addNode(lightId, frameId, 'saturation', 'node');
server.addNode(lightName, frameId, 'hue', 'node');
server.addNode(lightName, frameId, 'saturation', 'node');
}
server.activate(lightId);
server.activate(lightName);

server.addReadListener(lightId, frameId, 'switch', onRead(lightId, writeSwitchState));
server.addReadListener(lightId, frameId, 'brightness', onRead(lightId, writeBrightness));
server.addReadListener(lightName, frameId, 'switch', onRead(lightId, writeSwitchState));
server.addReadListener(lightName, frameId, 'brightness', onRead(lightId, writeBrightness));

if (lights[lightId].colorful) {
server.addReadListener(lightId, frameId, 'hue', onRead(lightId, writeHue));
server.addReadListener(lightId, frameId, 'saturation', onRead(lightId, writeSaturation));
server.addReadListener(lightName, frameId, 'hue', onRead(lightId, writeHue));
server.addReadListener(lightName, frameId, 'saturation', onRead(lightId, writeSaturation));
}
}
}
Expand Down