-
Notifications
You must be signed in to change notification settings - Fork 471
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Harman Luxury Change from REST HTTP API to WebSckets #1433
Harman Luxury Change from REST HTTP API to WebSckets #1433
Conversation
Invitation URL: |
Test Results 60 files 377 suites 0s ⏱️ Results for commit a3dc9a6. ♻️ This comment has been updated with latest results. |
Minimum allowed coverage is Generated by 🐒 cobertura-action against a3dc9a6 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The usage of websockets is really good for this driver, and I think it is worthwhile to pursue it. Unfortunately the lustre library used here is out of date; I assume you copied from bose which is also out of date and we intend to update some day. You should instead use the version that is made available in the lua libraries so that you are using the most recent version which has several bug fixes, and so you dont have to include any of the lustre files in the driver package. If you want an example of using the newer api, which isn't callback based, sonos is really the only example (sonos packages its own lustre but it is almost identical to what is in the lua libs with only a small change to the constructor api iirc).
Sonos has a Router
which is a single cosock task that manages all sending and receiving for all the websockets used in the driver. You could follow that approach or another option is to have a single task for managing each websocket individually.
I would also advocate for using the
As Carter mentioned, the patch to If that's too large of a refactor for your timelines on this PR, it's not a blocker. But it is something I would recommend you keep on your radar, in the interest of keeping the code size and memory usage for the driver at a minimum by using as much shared code as possible. It also makes sure that you don't have to back port bug fixes yourself if we improve the code in the lua libs. |
@@ -41,20 +32,12 @@ function Discovery.set_device_field(driver, device) | |||
local device_cache_value = driver.datastore.discovery_cache[device.device_network_id] | |||
|
|||
-- persistent fields | |||
device:set_field(const.STATUS, true, { | |||
persist = true, | |||
}) | |||
device:set_field(const.IP, device_cache_value.ip, { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this ever get updated if the IP address of the speaker changes due to DHCP?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. I forgot taking this into account when changing to WebSockets. I'll add some logic to handle this scenario as I switch to the lua library's lustre library
local HLWebsocket = {} | ||
HLWebsocket.__index = HLWebsocket | ||
|
||
--- hendles capabilities and sends the commands to the device |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo: hendles
-> handles
I have indeed copied the Lutsre library from Bose, as I wrote in the respective commit message. But I'll take your advice and use the version from the latest library (lib v9_52x)
Thanks for the directions |
Hi @dljsjr and @cjswedes ,
I don't understand what I'm missing that causes it to try to access a PS, I will clean up the commit messages when the changes are accepted |
77d1b36
to
058320e
Compare
if self:_handle_select_err(loop_state, err) then | ||
return | ||
end | ||
elseif self:_handle_recvs(loop_state, recv, 1) then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm the person that was helping you out on the forums :)
You can fix this issue by only including this file while preserving the directory structure. You don't need to include the entire library.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay. I'll modify it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approved pending the change that @alon-tchelet is already making 🎉
4b9bcdd
to
afcf23a
Compare
Cleaned the commits. I will update when the self verification is complete |
@alon-tchelet we'd like to get this merged by 11am CST 7/2. Can you squash your commits down to remove the fixup commits? edit: we will squash and merge then if you haven't. |
afcf23a
to
805e83a
Compare
Harman decision applied on device and now propagated to SmartThings Signed-off-by: alon-tchelet <[email protected]>
Harman don't want it and don't plan to use it in the future Signed-off-by: alon-tchelet <[email protected]>
We are moving the device communications between the hub and the device to WebSockets. Until the ST lustre library WebSocket keep_alive ping bug is resolved, this lustre/ws.lua will be used instead. Signed-off-by: alon-tchelet <[email protected]>
Signed-off-by: alon-tchelet <[email protected]>
the removed APIs are no longer used after moving to WebSockets Signed-off-by: alon-tchelet <[email protected]>
this is done to further match the discovery behaviour to the example code and to return the handshake process control to the device. Signed-off-by: alon-tchelet <[email protected]>
The REST HTTP API polling was creating too much conjunction and was unreliable at time (especially in weaker networks). Hence, we changed the whole communication set up between the hub and the device to WebSockets. With the exception of fetching the device information at discovery, the rest of the communication is done through a WebSocket. We implemented a JSON protocol that tries to replicate the native SmartThings capabilities' table structures and the offline/online logic is now handled fully by the WebSocket connection status. Moreover, a lot of old and no longer used functions and namings have been modified or deleted altogether. Signed-off-by: alon-tchelet <[email protected]>
Signed-off-by: alon-tchelet <[email protected]>
805e83a
to
ad42c0d
Compare
Sorry, I did it locally and forgot pushing to remote. All good now. |
ad42c0d
to
a3dc9a6
Compare
If all goes well with the release. Itll go to the beta channel today, and the production channel next week Monday. |
This PR is fixing pretty much all the issues previously experienced with the driver as the vast majority of issues came from random timeouts and the lack of lua sockets usage.
By moving all the communication between the device and the hub to websockets we now have a stable bidirectional connection based on lua sockets. The old inefficient and blocking REST API polling was removed and the device is now able to give live updates without being polled by the hub. This results in a much more relaxed and quieter network activity by the device and hub and a smoother user experience.
Note: This PR is replacing previous improvement attempt in now closed PR #1360