Closed jamieburchell closed 8 years ago
Great find! If you need this soon, pull requests are very welcome. If not, I'll try to find some time in the next few weeks to look into it.
No problem. To be honest I'm not sure how to fix this one. You kind of can't rely on the XML processor to automagically convert values to guessed types using xml2js.processors.parseNumbers.
Looks like the solution is to create a custom parser based off of the xml2js.processors.parseNumbers
parser
I think the difficulty will be knowing if you should parse the value given as a MAC adddress or convert it in to a int/float. For the same reason it's not able to automagically know if a value beginning 00626E should be a string.
I can fix this, but not till next week. Which API call is this response from? It looks like the issue only occurs for specific mac addresses (contains an 'E' - but no other letters).
So the XML (which has the correct MAC address in) is from /cgi-bin/CGIProxy.fcgi?cmd=getDevInfo&usr=xxx&pwd=xxx
. Once the XML has been parsed the value of "mac" in the JSON is Infinity.
Yeah, it looks like I was just unlucky that my MAC address only has one letter ("E") in it. I know of only one other person that's run in to this.
This is my stab at a revised function, but I do not know if you approve or how to factor that in as a custom function.
exports.parseNumbers = function(str) {
if (!isNaN(str) && str.toUpperCase().indexOf('E') < 0) {
str = str % 1 === 0 ? parseInt(str, 10) : parseFloat(str);
}
return str;
};
If you agree in principal I could have a look at getting that in Foscam.js
Closed by #15
The XML contains the MAC address but the parsed response contains "Infinity"
I suspect the MAC address is being parsed as a number or converted in some way...
https://github.com/luisiam/homebridge-foscam2/issues/3
https://github.com/luisiam/homebridge-foscamcamera/issues/5