i am trying to make a function in my app that is supposed to update the status of my hue lamps when the states of one of them changed.
For now, i have done this :
async.waterfall([
function getLightsId(callback) {
args = {
path: {
"username": "webjeremie"
}
};
client.registerMethod("getLightState", "http://hue.jeremieledieu.fr/api/${username}/lights/", "GET");
client.methods.getLightState(args, function (data, response) {
var ids = [];
for (key in data) {
ids.push(key);
}
callback(null, ids);
});
},
function getLightsState(ids, callback) {
var lightsState = new Object();
async.reduce(ids, {}, function(lightsState, id, rcallback) {
getLightState(id, function(state) {
lightsState[id] = state;
rcallback(null, lightsState);
});
}, callback);
},
], function (err, currentState) {
io.sockets.on('connection', function (socket) {
socket.emit('updateLightsState', currentState);
previousState = currentState;
});
});
This get me the states of all the lamps in the currenState
but im stuck at how should i constantly compare the previous state with the current state, and only emit when the currentState != previousState
Any ideas ?