-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
[hue] Changed discovery to mDNS; added HTTPS handling; refactor HTTPClient to use jetty shared client #11842
Conversation
.../main/java/org/openhab/binding/hue/internal/discovery/HueBridgeUPnPDiscoveryParticipant.java
Outdated
Show resolved
Hide resolved
.../main/java/org/openhab/binding/hue/internal/discovery/HueBridgeMDNSDiscoveryParticipant.java
Outdated
Show resolved
Hide resolved
...ue/src/main/java/org/openhab/binding/hue/internal/connection/HueTlsTrustManagerProvider.java
Show resolved
Hide resolved
// register trustmanager service | ||
HueTlsTrustManagerProvider tlsTrustManagerProvider = new HueTlsTrustManagerProvider( | ||
ip + ":" + hueBridgeConfig.getPort(), hueBridgeConfig.useSelfSignedCertificate()); | ||
serviceRegistration = FrameworkUtil.getBundle(getClass()).getBundleContext() | ||
.registerService(TlsTrustManagerProvider.class.getName(), tlsTrustManagerProvider, null); |
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.
This is a really ugly implementation and we do not want it. But unfortunately I did not yet found a better solution.
Implementing the HueTlsTrustManagerProvider
to be a ThingHandlerService
would be my favorite one but when doing so there will be a race condition between activation of the HueTlsTrustManagerProvider
and initialization of the HueBridgeHandler
.
Registering the HueTlsTrustManagerProvider
in the HueThingHandlerFactory
does not work because I need access to the configuration of the Thing
to retrieve IP address, port and protocol.
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.
Is there a way for HueTlsTrustManagerProvider to return a status in the case that getting the external cert fails (i.e. the server is momentarily unreachable)? It seems like the current code has no provision to retry the cert retrieval process since it attempted only once during initialize().
Wow, that's awesome, thank you - I already hoped that you would look into the new hue APIs! 😄 |
I am planning to separate the implementation into three steps. This is the first one.
|
...ue/src/main/java/org/openhab/binding/hue/internal/connection/HueTlsTrustManagerProvider.java
Outdated
Show resolved
Hide resolved
...hab.binding.hue/src/main/java/org/openhab/binding/hue/internal/handler/HueBridgeHandler.java
Outdated
Show resolved
Hide resolved
bundles/org.openhab.binding.hue/src/main/java/org/openhab/binding/hue/internal/HueBridge.java
Outdated
Show resolved
Hide resolved
95220ce
to
f4e3567
Compare
.../main/java/org/openhab/binding/hue/internal/discovery/HueBridgeMDNSDiscoveryParticipant.java
Show resolved
Hide resolved
Continuing discussion with @lolodomo from this #11834 (comment)
You could still do that by means of an entry in the '.cfg' file (rather than via the UI).
@lolodomo the main reason to remove the parameter was the brilliant idea of @kaikreuzer quoted below. Which would enable new systems to pre-discover potential Things on the network without any bindings having been installed. However if you insist that it must be a binding parameter (instead of an entry in a
|
My concern was to have a parameter, whatever the file in which to define it. By the way, now that we move from UPnP to mDNS, is this grace period still useful for mDNS discovery? |
@cweitkamp : do you know if mDMD discovery is available for old v1 bridge? |
I will install the JAR from this PR and test it on my Hue bridge to see if the mDNS disco suffers from the same problem as the UPNP disco. BTW this time of year is a perfect time to test it. In my case the problem (on UPNP disco) only occurs when the Hue bridge is running "heavy" automations, and presumably the automation causes delays in sending the NOTIFY messages. This time of year is when I run a Christmas light colour loop in the front window of my house. This is quite a "heavy" automation. |
@lolodomo I am afraid not.
For older bridges there still is the |
Unfortunately I could not build the binding jar because there is some dependency on PEMTrustManager in the core, which I cannot find. => So @cweitkamp could you please give me a link to the built JAR? |
Here you are: org.openhab.core.io.net-3.3.0-SNAPSHOT.zip |
f4e3567
to
da2d354
Compare
The client is configured to use at maximum 2 connections per destination. It uses 5 up to 10 threads. Those values are user specific (see https://github.com/openhab/openhab-core/blob/4096df1c6433f10e332632ced9f2e679dd8c340d/bundles/org.openhab.core.io.net/src/main/java/org/openhab/core/io/net/http/internal/WebClientFactoryImpl.java#L156-L163). |
Just to mention that |
Thanks. I will need to figure out how to add some more detailed logging when this happens, as it does happen consistently a few times per week now. It wouldn't be much of a problem if my rules were more well-written - currently I monitor all my devices and get push messages when they are offline/unreachable, but I don't consider if the reason is the bridge being offline, so that triggers a lot of messages. :-) It might be the number of threads being the limitation as some of my other bindings are quite busy all the time. |
To see the exception, DEBUG log level would need to be set. Have your checked in logs if the bridge has come OFFLINE at any moment, even just for a few seconds? I'm suspecting (for me) if may be caused by activity from other bindings using the shared http client. |
@lolodomo, @cweitkamp - although the switch to shared Jetty client has changed some behavior related to timeouts in my setup, I believe this is a general problem for which this binding is not to blame, probably it's just a symptom. So IMHO it would be okay to merge if no one else but me experienced any issues. I will still try to track this further. |
My only remaining comments were about exception handling but I believe you concluded there is in fact no problem. As a consequence, that is fine for me,. Feel free to merge @jlaur |
Can someone post the JAR link so I can test this? I have 2 HUE bridges with over 50 devices across them. I'm running OH 3.2 and the same HUE version binding, my issue is the HUE bridges go offline/online throughout the day very often (just offline for a few milliseconds). Reading this thread, is this because it's using a shared HTTP client? If this is solved, this would be great! |
This version of the binding requires core 3.3 or higher, so you would need to upgrade before being able to test it. I actually experienced the opposite problem. Shared Jetty client was introduced with this PR and I didn't have timeouts before I began testing this. |
@jlaur Which other bindings do you use in your environment based on the shared Jetty client? |
|
Interesting. And what about the polling configuration of the hue binding itself? IIRC the binding has three polling jobs. One for lights including groups - frequency is configurable by user in seconds , one for sensors - interval configurable too (in ms, disabled, if 0 or less) and one for scenes - fixed value (10 minutes). Plus one request for each command sent towards Hue Bridge. |
Polling interval is 10 seconds (default). I remember now that I lowered Sensor Polling Interval to 250 ms. I believe that was an attempt to slightly improve responsiveness of some FoH buttons (in lack of SSE). |
=> FYI I am working on SSE for Hue and HDPowerview :) => also the Gardena binding uses the shared Jetty client; although it has WebSocket call backs (similar to SSE) so the load is low; but one user has complained that when the WebSocket drops, it breaks other bindings; which may or may not be related ?? |
@cweitkamp - thanks again! |
…lient to use jetty shared client (openhab#11842) * Changed discovery to MDNS; added HTTPS handling; refactor HTTPClient to use jetty shared client Signed-off-by: Christoph Weitkamp <github@christophweitkamp.de>
…lient to use jetty shared client (openhab#11842) * Changed discovery to MDNS; added HTTPS handling; refactor HTTPClient to use jetty shared client Signed-off-by: Christoph Weitkamp <github@christophweitkamp.de> Signed-off-by: Andras Uhrin <andras.uhrin@gmail.com>
…lient to use jetty shared client (openhab#11842) * Changed discovery to MDNS; added HTTPS handling; refactor HTTPClient to use jetty shared client Signed-off-by: Christoph Weitkamp <github@christophweitkamp.de>
…lient to use jetty shared client (openhab#11842) * Changed discovery to MDNS; added HTTPS handling; refactor HTTPClient to use jetty shared client Signed-off-by: Christoph Weitkamp <github@christophweitkamp.de>
…lient to use jetty shared client (openhab#11842) * Changed discovery to MDNS; added HTTPS handling; refactor HTTPClient to use jetty shared client Signed-off-by: Christoph Weitkamp <github@christophweitkamp.de>
Depends on openhab/openhab-core#2622 and openhab/openhab-core#2635
Philips announced a brand new HUE API v2 being available. These are the first steps to add support for it.
The new API supports some really interesting new features like streaming SSEs. It uses HTTPS only. Additional, they will
deprecatedisable UPnP in Q2 2022 in favor of mDNS.See their Migration Guide to new API.
Signed-off-by: Christoph Weitkamp github@christophweitkamp.de