Fix crash when WeMo devices are powered off (#794)

* Big Update

Includes:
 - New lookup node to check state of a device
 - Fix dimming control for lights
 - Fix light group control
 - Set the node label to match the device name
 - The event now includes the text description of the light capability

* Add extra check for empty results in discovery

* Attempt to catch errors from wemo-lookup

This is to catch errors when device is offline

* Put request back

Will look at making it all http.request later

* Add more error handling and reporting

* Try and not crash with subscriptions

Failed subscriptions will try agian in 1 min

* Fix some messages

* Remove most of the console.logs

* Last of console.logs
This commit is contained in:
Ben Hardill
2021-04-10 20:02:36 +01:00
committed by GitHub
parent 2c5cc5f70c
commit 874708dc0d
3 changed files with 108 additions and 42 deletions

View File

@@ -271,6 +271,11 @@ WeMoNG.prototype.start = function start() {
post_request.abort();
});
post_request.on('error', function(err){
// should log err
//console.log(err);
})
post_request.write(util.format(getenddevs.body, udn));
post_request.end();
@@ -358,12 +363,12 @@ WeMoNG.prototype.toggleSocket = function toggleSocket(socket, on) {
});
post_request.on('error', function (e) {
console.log(e);
console.log("%j", postoptions);
// console.log(e);
// console.log("%j", postoptions);
});
post_request.on('timeout', function () {
console.log("Timeout");
// console.log("Timeout");
post_request.abort();
});
@@ -408,21 +413,21 @@ WeMoNG.prototype.getSocketStatus = function getSocketStatus(socket) {
status = parseInt(status);
def.resolve(status);
} else {
def.reject();
def.reject(err);
}
});
});
});
post_request.on('error', function (e) {
console.log(e);
console.log("%j", postoptions);
def.reject();
// console.log(e);
// console.log("%j", postoptions);
def.reject(e);
});
post_request.on('timeout', function(){
post_request.abort();
def.reject();
def.reject("timeout");
});
post_request.write(getSocketState.body);
@@ -466,14 +471,14 @@ WeMoNG.prototype.getInsightParams = function getInsightParams(socket) {
});
post_request.on('error', function (e) {
console.log(e);
console.log("%j", postoptions);
def.reject();
// console.log(e);
// console.log("%j", postoptions);
def.reject(e);
});
post_request.on('timeout', function(){
post_request.abort();
def.reject();
def.reject("timeout");
});
post_request.write(getInsightParameters.body);
@@ -521,28 +526,28 @@ WeMoNG.prototype.getLightStatus = function getLightStatus(light) {
};
def.resolve(obj);
} else {
def.reject();
console.log("err");
def.reject(err);
// console.log("err");
}
});
}
} else {
console.log("err");
def.reject();
// console.log("err");
def.reject(err);
}
});
});
});
post_request.on('error', function (e) {
console.log(e);
console.log("%j", postoptions);
def.reject();
// console.log(e);
// console.log("%j", postoptions);
def.reject(e);
});
post_request.on('timeout', function () {
console.log("Timeout");
post_request.abort();
// console.log("Timeout");
post_request.abort("timeout");
def.reject();
});
@@ -578,12 +583,12 @@ WeMoNG.prototype.setStatus = function setStatus(light, capability, value) {
});
post_request.on('error', function (e) {
console.log(e);
console.log("%j", postoptions);
// console.log(e);
// console.log("%j", postoptions);
});
post_request.on('timeout', function () {
console.log("Timeout");
// console.log("Timeout");
post_request.abort();
});
@@ -612,7 +617,7 @@ WeMoNG.prototype.parseEvent = function parseEvent(evt) {
msg.value = res['StateEvent']['Value'][0];
def.resolve(msg);
} else {
def.reject();
def.reject(err);
}
});
} else if (prop.hasOwnProperty('BinaryState')) {
@@ -629,7 +634,7 @@ WeMoNG.prototype.parseEvent = function parseEvent(evt) {
}
} else {
//error
def.reject();
def.reject(err);
}
});