Open tzapu opened 5 years ago
You could change the makeHelper function adding a var timeoutID = null; and then change the setter like this: setter: function (value, callback) { if(timeoutID) clearTimeout(timeoutID); timeoutID = setTimeout(function(){setDispatch(value, callback, characteristic)}, 200); }
But I didn't test it and don't know if it satisfy your needs.
Added setterDelay parameter that is a number which defines the number of milliseconds to wait before executing a "set" action request. If more than one request is received during this interval, only the last one is executed. Defaults to 200 but you can change it to whatever suits you better..
wow, you are a superstar, i was just about to tinker with this, thank you very very much. is it worth changing the default to 0ms or 50ms as to not visibly impact people that expect the current behaviour ?
playing with it, but it looks like there might be a problem, it seems to call delayed for some getters as well, not sure how
[1/4/2019, 12:37:16 AM] [Kitchen Blinds] getTargetPosition emitter returned data: 71
[1/4/2019, 12:37:16 AM] [Kitchen Blinds] updating TargetPosition with value 71 in 10000ms
[1/4/2019, 12:37:16 AM] [Kitchen Blinds] calling callback for action getTargetPosition
[1/4/2019, 12:37:16 AM] [Kitchen Blinds] received response from action: http://10.0.1.27:3000/v1/projects/home/rooms/...
[1/4/2019, 12:37:16 AM] [Kitchen Blinds] Applying mappers on {"value":75}
[1/4/2019, 12:37:16 AM] [Kitchen Blinds] Mapper 0 mapped {"value":75} to 75
[1/4/2019, 12:37:16 AM] [Kitchen Blinds] Mapper 1 mapped 75 to 71
[1/4/2019, 12:37:16 AM] [Kitchen Blinds] Mapping result is 71
[1/4/2019, 12:37:16 AM] [Kitchen Blinds] We have a value: 71, int: 71
[1/4/2019, 12:37:16 AM] [Kitchen Blinds] getCurrentPosition emitter returned data: 71
[1/4/2019, 12:37:16 AM] [Kitchen Blinds] updating CurrentPosition with value 71 in 10000ms
some more logs, the action i did was open home app, given no command. i would not expect it to try and set anything ...
[1/4/2019, 12:52:03 AM] [Kitchen Blinds] getDispatch function called for url: http://10.0.1.27:3000/v1/projects/home/rooms/...1
[1/4/2019, 12:52:03 AM] [Kitchen Blinds] getDispatch function called for url: http://10.0.1.27:3000/v1/projects/home/rooms/...2
[1/4/2019, 12:52:03 AM] [Kitchen Blinds] received response from action: http://10.0.1.27:3000/v1/projects/home/rooms/...
[1/4/2019, 12:52:03 AM] [Kitchen Blinds] Applying mappers on {"value":91}
[1/4/2019, 12:52:03 AM] [Kitchen Blinds] Mapper 0 mapped {"value":91} to 91
[1/4/2019, 12:52:03 AM] [Kitchen Blinds] Mapper 1 mapped 91 to 90
[1/4/2019, 12:52:03 AM] [Kitchen Blinds] Mapping result is 90
[1/4/2019, 12:52:03 AM] [Kitchen Blinds] We have a value: 90, int: 90
[1/4/2019, 12:52:03 AM] [Kitchen Blinds] getTargetPosition getter function returned with data: 90
[1/4/2019, 12:52:03 AM] [Kitchen Blinds] updating TargetPosition with value 90 in 10000ms
[1/4/2019, 12:52:03 AM] [Kitchen Blinds] received response from action: http://10.0.1.27:3000/v1/projects/home/rooms/...
[1/4/2019, 12:52:03 AM] [Kitchen Blinds] Applying mappers on {"value":91}
[1/4/2019, 12:52:03 AM] [Kitchen Blinds] Mapper 0 mapped {"value":91} to 91
[1/4/2019, 12:52:03 AM] [Kitchen Blinds] Mapper 1 mapped 91 to 90
[1/4/2019, 12:52:03 AM] [Kitchen Blinds] Mapping result is 90
[1/4/2019, 12:52:03 AM] [Kitchen Blinds] We have a value: 90, int: 90
[1/4/2019, 12:52:03 AM] [Kitchen Blinds] getCurrentPosition getter function returned with data: 90
[1/4/2019, 12:52:03 AM] [Kitchen Blinds] updating CurrentPosition with value 90 in 10000ms
[1/4/2019, 12:52:13 AM] [Kitchen Blinds] setDispatch:actionName:value: setTargetPosition 90
[1/4/2019, 12:52:13 AM] [Kitchen Blinds] Applying mappers on 90
[1/4/2019, 12:52:13 AM] [Kitchen Blinds] Mapper 0 mapped 90 to 91
[1/4/2019, 12:52:13 AM] [Kitchen Blinds] Mapping result is 91
[1/4/2019, 12:52:13 AM] [Kitchen Blinds] setDispatch:actionName:value: setCurrentPosition 90
I think this is HK normal behavior. Do you have any problem with the blind?
Guido
On Thu, 3 Jan 2019 at 23:55, tzapu notifications@github.com wrote:
some more logs, the action i did was open home app, given no command. i would not expect it to try and set anything ...
[1/4/2019, 12:52:03 AM] [Kitchen Blinds] getDispatch function called for url: http://10.0.1.27:3000/v1/projects/home/rooms/...1 [1/4/2019 http://10.0.1.27:3000/v1/projects/home/rooms/...1%5B1/4/2019, 12:52:03 AM] [Kitchen Blinds] getDispatch function called for url: http://10.0.1.27:3000/v1/projects/home/rooms/...2 [1/4/2019 http://10.0.1.27:3000/v1/projects/home/rooms/...2%5B1/4/2019, 12:52:03 AM] [Kitchen Blinds] received response from action: http://10.0.1.27:3000/v1/projects/home/rooms/... [1/4/2019, 12:52:03 AM] [Kitchen Blinds] Applying mappers on {"value":91} [1/4/2019, 12:52:03 AM] [Kitchen Blinds] Mapper 0 mapped {"value":91} to 91 [1/4/2019, 12:52:03 AM] [Kitchen Blinds] Mapper 1 mapped 91 to 90 [1/4/2019, 12:52:03 AM] [Kitchen Blinds] Mapping result is 90 [1/4/2019, 12:52:03 AM] [Kitchen Blinds] We have a value: 90, int: 90 [1/4/2019, 12:52:03 AM] [Kitchen Blinds] getTargetPosition getter function returned with data: 90 [1/4/2019, 12:52:03 AM] [Kitchen Blinds] updating TargetPosition with value 90 in 10000ms [1/4/2019, 12:52:03 AM] [Kitchen Blinds] received response from action: http://10.0.1.27:3000/v1/projects/home/rooms/... [1/4/2019, 12:52:03 AM] [Kitchen Blinds] Applying mappers on {"value":91} [1/4/2019, 12:52:03 AM] [Kitchen Blinds] Mapper 0 mapped {"value":91} to 91 [1/4/2019, 12:52:03 AM] [Kitchen Blinds] Mapper 1 mapped 91 to 90 [1/4/2019, 12:52:03 AM] [Kitchen Blinds] Mapping result is 90 [1/4/2019, 12:52:03 AM] [Kitchen Blinds] We have a value: 90, int: 90 [1/4/2019, 12:52:03 AM] [Kitchen Blinds] getCurrentPosition getter function returned with data: 90 [1/4/2019, 12:52:03 AM] [Kitchen Blinds] updating CurrentPosition with value 90 in 10000ms [1/4/2019, 12:52:13 AM] [Kitchen Blinds] setDispatch:actionName:value: setTargetPosition 90 [1/4/2019, 12:52:13 AM] [Kitchen Blinds] Applying mappers on 90 [1/4/2019, 12:52:13 AM] [Kitchen Blinds] Mapper 0 mapped 90 to 91 [1/4/2019, 12:52:13 AM] [Kitchen Blinds] Mapping result is 91 [1/4/2019, 12:52:13 AM] [Kitchen Blinds] setDispatch:actionName:value: setCurrentPosition 90
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/staromeste/homebridge-http-advanced-accessory/issues/4#issuecomment-451304179, or mute the thread https://github.com/notifications/unsubscribe-auth/AEL9MVGWhvVskF7QCD5ZoWaOfcSt9Afiks5u_opagaJpZM4ZmiHB .
well, mostly it looks to be an internal set, with no corresponding http request. in my head it only makes sense to delay the http request, not the internal setters. i will play with it some more, had to revert it to 0ms delay for now.
I don’t follow you. Based on the log you sent, the setter is called by HK, and after 10 seconds the execution (http request) is done.
Maybe 10 seconds is too much, I would try a smaller interval.
Anyway, what’s the problem you’re experiencing using the accessory?
Guido
Il giorno 6 gen 2019, alle ore 11:02, tzapu notifications@github.com ha scritto:
well, mostly it looks to be an internal set, with no corresponding http request. in my head it only makes sense to delay the http request, not the internal setters. i will play with it some more, had to revert it to 0ms delay for now.
— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.
hi, updated it a bit here https://github.com/staromeste/homebridge-http-advanced-accessory/pull/6 to disable this for people not using it, so it's backwards compatible and not causing any unexpected behaviours.
the 10 seconds delay was jsut there to try and see what happens, in slow motion if you will.
my current issue is that it does not act as a debounce. it only delays requests between set calls.
in the following log, those values were set on the home app within a second. the events only come one after the other with the set delay (5s in this instance), so no debounce takes place. all you get is a delay between actions really. i suspect that another event is not sent until de callback is called, which in this case is delayed by the timeout...
i hope i managed to explain better this time , thank you for looking at this Guido, much appreciated
[1/6/2019, 12:28:44 PM] [Kitchen Blinds] getDispatch function called for url: http://10.0.1.27:3000/v1/projects/home/rooms/...
[1/6/2019, 12:28:44 PM] [Kitchen Blinds] received response from action: http://10.0.1.27:3000/v1/projects/home/rooms/...
[1/6/2019, 12:28:44 PM] [Kitchen Blinds] Applying mappers on {"value":60}
[1/6/2019, 12:28:44 PM] [Kitchen Blinds] Mapper 0 mapped {"value":60} to 60
[1/6/2019, 12:28:44 PM] [Kitchen Blinds] Mapper 1 mapped 60 to 54
[1/6/2019, 12:28:44 PM] [Kitchen Blinds] Mapping result is 54
[1/6/2019, 12:28:44 PM] [Kitchen Blinds] We have a value: 54, int: 54
[1/6/2019, 12:28:44 PM] [Kitchen Blinds] getCurrentPosition getter function returned with data: 54
[1/6/2019, 12:28:44 PM] [Kitchen Blinds] updating CurrentPosition with value 54
[1/6/2019, 12:28:48 PM] [Kitchen Blinds] updating TargetPosition with value 68 in 5000ms
[1/6/2019, 12:28:53 PM] [Kitchen Blinds] setDispatch:actionName:value: setTargetPosition 68
[1/6/2019, 12:28:53 PM] [Kitchen Blinds] Applying mappers on 68
[1/6/2019, 12:28:53 PM] [Kitchen Blinds] Mapper 0 mapped 68 to 72
[1/6/2019, 12:28:53 PM] [Kitchen Blinds] Mapping result is 72
[1/6/2019, 12:28:53 PM] [Kitchen Blinds] updating TargetPosition with value 69 in 5000ms
[1/6/2019, 12:28:58 PM] [Kitchen Blinds] setDispatch:actionName:value: setTargetPosition 69
[1/6/2019, 12:28:58 PM] [Kitchen Blinds] Applying mappers on 69
[1/6/2019, 12:28:58 PM] [Kitchen Blinds] Mapper 0 mapped 69 to 73
[1/6/2019, 12:28:58 PM] [Kitchen Blinds] Mapping result is 73
[1/6/2019, 12:28:58 PM] [Kitchen Blinds] updating TargetPosition with value 68 in 5000ms
[1/6/2019, 12:29:03 PM] [Kitchen Blinds] setDispatch:actionName:value: setTargetPosition 68
[1/6/2019, 12:29:03 PM] [Kitchen Blinds] Applying mappers on 68
[1/6/2019, 12:29:03 PM] [Kitchen Blinds] Mapper 0 mapped 68 to 72
[1/6/2019, 12:29:03 PM] [Kitchen Blinds] Mapping result is 72
[1/6/2019, 12:29:03 PM] [Kitchen Blinds] updating TargetPosition with value 75 in 5000ms
[1/6/2019, 12:29:08 PM] [Kitchen Blinds] setDispatch:actionName:value: setTargetPosition 75
[1/6/2019, 12:29:08 PM] [Kitchen Blinds] Applying mappers on 75
[1/6/2019, 12:29:08 PM] [Kitchen Blinds] Mapper 0 mapped 75 to 78
[1/6/2019, 12:29:08 PM] [Kitchen Blinds] Mapping result is 78
[1/6/2019, 12:29:08 PM] [Kitchen Blinds] updating TargetPosition with value 76 in 5000ms
[1/6/2019, 12:29:13 PM] [Kitchen Blinds] setDispatch:actionName:value: setTargetPosition 76
[1/6/2019, 12:29:13 PM] [Kitchen Blinds] Applying mappers on 76
[1/6/2019, 12:29:13 PM] [Kitchen Blinds] Mapper 0 mapped 76 to 79
[1/6/2019, 12:29:13 PM] [Kitchen Blinds] Mapping result is 79
[1/6/2019, 12:29:13 PM] [Kitchen Blinds] updating TargetPosition with value 92 in 5000ms
[1/6/2019, 12:29:18 PM] [Kitchen Blinds] setDispatch:actionName:value: setTargetPosition 92
[1/6/2019, 12:29:18 PM] [Kitchen Blinds] Applying mappers on 92
[1/6/2019, 12:29:18 PM] [Kitchen Blinds] Mapper 0 mapped 92 to 92
[1/6/2019, 12:29:18 PM] [Kitchen Blinds] Mapping result is 92
[1/6/2019, 12:29:18 PM] [Kitchen Blinds] updating TargetPosition with value 95 in 5000ms
[1/6/2019, 12:29:23 PM] [Kitchen Blinds] setDispatch:actionName:value: setTargetPosition 95
[1/6/2019, 12:29:23 PM] [Kitchen Blinds] Applying mappers on 95
[1/6/2019, 12:29:23 PM] [Kitchen Blinds] Mapper 0 mapped 95 to 95
[1/6/2019, 12:29:23 PM] [Kitchen Blinds] Mapping result is 95
so i've updated the pull request with some other changes. that version works perfectly for me, it debounces as it should and it does not affect in any way people that don't use a delayed setter. could you take a look and asses if it maybe breaks anything else of if you can think of another way of doing it?
https://github.com/staromeste/homebridge-http-advanced-accessory/pull/6
cheers alex
Thanks guys for a wonderful plugin, I was able to integrate some fibaro blinds controllers with it, it was so much help.
For stuff like lights, having instant reaction on dimming sliders is great, but for something like window covering what is happening is that homekit sends an update every few hundred milliseconds, when you are sliding your finger around, which in turn causes the blinds to go to a position, stop, go to another position, stop again, etc.
Something like an optional delay flag (don't call any set http handlers until 200ms have passed since the last homekit event for example) or a debounce of all the events would be great.
I did look at the code a bit, but am at a loss as to how to add it, if anyone else feels inclined and has some ideas, it would be very appreciated, thank you