Skip to content

Commit

Permalink
Texture Fixture, Added more debug output, refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
mwittig committed May 13, 2016
1 parent a31e14c commit e71356a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 24 deletions.
3 changes: 3 additions & 0 deletions src/discover.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ module.exports = function (options) {
return new Promise(function (resolve, reject) {
var discoverer = dgram.createSocket('udp4');
discoverer.bind(function () {
debug("Milight: Discovery socket openend");
discoverer.setBroadcast(true);
});

Expand All @@ -41,6 +42,7 @@ module.exports = function (options) {
timeoutId = setTimeout(function() {
try {
discoverer.close();
debug("Milight: Discovery socket closed");
} catch (ex) {/*ignore*/}
resolve(discoResults);
}, timeout)
Expand Down Expand Up @@ -71,6 +73,7 @@ module.exports = function (options) {
debug(error);
try {
discoverer.close();
debug("Milight: Discovery socket closed");
} catch (ex) {/*ignore*/}
reject(error);
});
Expand Down
23 changes: 11 additions & 12 deletions src/milight.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,22 +78,20 @@ MilightController.prototype._createSocket = function () {
return resolve();
}
else {
debug("Initializing Socket");
debug("Milight: Initializing Socket");
var socket = dgram.createSocket('udp4');

if (self._broadcastMode) {
socket.bind(function () {
socket.setBroadcast(true);
self.clientSocket = socket;
debug("Milight: Initializing Socket (broadcast mode) completed");
return resolve();
});
}
else {
socket.bind(function () {
self.clientSocket = socket;
debug("Milight: Initializing Socket done");
if (self._broadcastMode) {
socket.setBroadcast(true);
debug("Milight: Initializing Socket (broadcast mode) done");
}
else {
debug("Milight: Initializing Socket done");
}
return resolve();
}
})
}
});
});
Expand Down Expand Up @@ -203,6 +201,7 @@ MilightController.prototype.close = function () {
if (self.clientSocket) {
self.clientSocket.close();
delete self.clientSocket;
debug("Milight: Socket closed");
}
return Promise.resolve();
})
Expand Down
23 changes: 11 additions & 12 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ describe("Testing transmission of control sequences", function () {
});

it("shall receive the command rgbw on in broadcast mode", function (done) {
myLight = new Milight({
var myLight = new Milight({
commandRepeat: 1
});
var calls = [
Expand Down Expand Up @@ -150,7 +150,7 @@ describe("Testing transmission of control sequences", function () {
commands2.rgbw.brightness2(100)
];
var test = function(total, command) {
return myLight.sendCommands(command)
return light.sendCommands(command)
.then(function () {
expect(bytesReceived.length).toBe(command.length);
expect(JSON.stringify(bytesReceived)).toEqual(JSON.stringify(command));
Expand All @@ -176,7 +176,7 @@ describe("Testing transmission of control sequences", function () {
commands2.rgbw.hue.apply(commands2.rgbw, args)
];
var innerTest = function(total, command) {
return myLight.sendCommands(command)
return light.sendCommands(command)
.then(function () {
expect(bytesReceived.length).toBe(command.length);
expect(JSON.stringify(bytesReceived)).toEqual(JSON.stringify(command));
Expand All @@ -201,7 +201,7 @@ describe("Testing transmission of control sequences", function () {
commands2.rgbw.rgb255(255, 255, 255)
];
var test = function(total, command) {
return myLight.sendCommands(command)
return light.sendCommands(command)
.then(function () {
expect(bytesReceived.length).toBe(flattenDeep(command).length);
expect(JSON.stringify(bytesReceived)).toEqual(JSON.stringify(flattenDeep(command)));
Expand All @@ -212,7 +212,6 @@ describe("Testing transmission of control sequences", function () {
Promise.reduce(
calls, test, 0
).finally(function () {
myLight.close();
done();
})
});
Expand All @@ -232,7 +231,7 @@ describe("Testing transmission of control sequences", function () {
flattenDeep(commands2.rgbw.rgb255.apply(commands2.rgbw, args))
];
var innerTest = function(total, command) {
return myLight.sendCommands(command)
return light.sendCommands(command)
.then(function () {
expect(bytesReceived.length).toBe(command.length);
expect(JSON.stringify(bytesReceived)).toEqual(JSON.stringify(command));
Expand All @@ -258,7 +257,7 @@ describe("Testing transmission of control sequences", function () {
commands2.rgbw[commandName](1)
];
var innerTest = function(total, command) {
return myLight.sendCommands(command)
return light.sendCommands(command)
.then(function () {
expect(bytesReceived.length).toBe(command.length);
expect(JSON.stringify(bytesReceived)).toEqual(JSON.stringify(command));
Expand All @@ -284,7 +283,7 @@ describe("Testing transmission of control sequences", function () {
commands2.rgbw[commandName]()
];
var innerTest = function(total, command) {
return myLight.sendCommands(command)
return light.sendCommands(command)
.then(function () {
expect(bytesReceived.length).toBe(command.length);
expect(JSON.stringify(bytesReceived)).toEqual(JSON.stringify(command));
Expand All @@ -310,7 +309,7 @@ describe("Testing transmission of control sequences", function () {
commands2.white[commandName](1)
];
var innerTest = function(total, command) {
return myLight.sendCommands(command)
return light.sendCommands(command)
.then(function () {
expect(bytesReceived.length).toBe(command.length);
expect(JSON.stringify(bytesReceived)).toEqual(JSON.stringify(command));
Expand All @@ -336,7 +335,7 @@ describe("Testing transmission of control sequences", function () {
commands2.white[commandName]()
];
var innerTest = function(total, command) {
return myLight.sendCommands(command)
return light.sendCommands(command)
.then(function () {
expect(bytesReceived.length).toBe(command.length);
expect(JSON.stringify(bytesReceived)).toEqual(JSON.stringify(command));
Expand All @@ -362,7 +361,7 @@ describe("Testing transmission of control sequences", function () {
commands2.rgb[commandName]()
];
var innerTest = function(total, command) {
return myLight.sendCommands(command)
return light.sendCommands(command)
.then(function () {
expect(bytesReceived.length).toBe(command.length);
expect(JSON.stringify(bytesReceived)).toEqual(JSON.stringify(command));
Expand Down Expand Up @@ -393,7 +392,7 @@ describe("Testing transmission of control sequences", function () {
commands2.rgb.hue.apply(commands.rgb, args)
];
var innerTest = function(total, command) {
return myLight.sendCommands(command)
return light.sendCommands(command)
.then(function () {
expect(bytesReceived.length).toBe(command.length);
expect(JSON.stringify(bytesReceived)).toEqual(JSON.stringify(command));
Expand Down

0 comments on commit e71356a

Please sign in to comment.