redloro / smartthings

SmartThings home automation services, apps and devices
Apache License 2.0
116 stars 194 forks source link

Fix issue parsing zones < 10 with leading '0' character. #5

Closed chrismoos closed 6 years ago

chrismoos commented 7 years ago

I noticed an issue with zones < 10 not generating open/closed events properly. This is because parseInt parses a zone like 08 as zero.

redloro commented 7 years ago

Thanks for the contrib... but not sure what it's meant to resolve... parseInt will auto remove all leading zeros... http://jsbin.com/varamekiwu/edit?js,console

What led you to believe that the zone wasn't being set right?

peaches commented 7 years ago

In some version of javascript, parseInt(08) will be attempted to parse as an octal number as opposed to a decimal number.

@chrismoos, can you test if the following fixes your problem?

msg.userOrZone = parseInt(map[2], 10);

I highly recommend to always pass in the radix to prevent confusion. I think the jsbin behaves correctly because it's being run in a modern browser.

chrismoos commented 7 years ago

@peaches yeah, it seems that was the issue, simpler than the fix I added. I've updated the change to pass the radix.

@redloro On older versions of node like 0.6.x, it doesn't parse the zone number correctly, see the following:

$ node
> parseInt('08')
0
> parseInt('08', 10)
8
>                                                                                                                                                                                      $ node -v
v0.6.12