Supereg / homebridge-http-lightbulb

Powerful http lightbulb for Homebridge: https://github.com/homebridge/homebridge
ISC License
23 stars 7 forks source link

Issue parsing 'On' status response body #3

Closed mabiste closed 4 years ago

mabiste commented 4 years ago

Hey Andi,

first of all, thank you very much for your great plugins! I'm using them together with the http-notification-server which is very nice!

Currently, I have an issue with parsing the 'On' status of the light bulb from statusUrl response body.

When I request the On status I get a JSON body like this one:

{"LL": { "control": "dev/sps/io/LK207001/state", "value": "1", "Code": "200"}}

-> "value" is "1" when the light is on and "0" when the light is off

I've set the statusPattern to \"value\":\s\"(-?[0-9]):

"statusPattern": "\\"value\\":\s\\"(-?[0-9])"

...and tested it on https://regex101.com with my response body:

image image

But when I open my Home app on my iPhone, I always get the light 'On' status is 'on'. On the debug log I can see the right status on the response body (value = "0"), but it was parsed as 'ON'':

getPowerState() request returned successfully (200). Body: '{"LL": { "control": "dev/sps/io/LK207001/state", "value": "0", "Code": "200"}} getPowerState() power is currently ON

Can you tell me what's wrong? Thank you!

Kind regards! Marco

mabiste commented 4 years ago

Must I have as result of the regex compilation just a 'Full match' like the example referenzed on the readme.md of homebridge-http-switch? grafik Or as the exmaple on your comment to issue #35 (Cannot read stare from status url) of the homebridge-http-switch plugin? grafik

mabiste commented 4 years ago

Yes, I've solved the problem by using this statusPattern:

\"value\":\s\"1\"

With this pattern, I just get a 'Full match' when value is "1":

image

When the value is "0", I get no match:

image

And also on the debug log I can see correct parsing:

getPowerState() request returned successfully (200). Body: '{"LL": { "control": "dev/sps/io/LK207001/state", "value": "0", "Code": "200"}} getPowerState() power is currently OFF

Supereg commented 4 years ago

Great, you already figured it out by yourself 👏

Regarding your original pattern ("value":\s"(-?[0-9]):). The problem here was that you would math any one digit number ([0-9]) ad event any negative number (-?). The plugin considers anything which matches as ON an and anything that doesn't match as off. This is special for the on characteristic as it only as two states on and off. So the thing you figured out yourself is the perfect regex for your problem 😃