Skip to content
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

[danfossairunit] Use serial number as valid Thing ID in discovery #18414

Merged
merged 1 commit into from
Mar 22, 2025

Conversation

jlaur
Copy link
Contributor

@jlaur jlaur commented Mar 18, 2025

This eliminates inbox results for already configured Things.

Additionally, the suggested Thing ID is now compliant with .things file configuration by avoiding "-" as first character in ID. See openhab/openhab-core#4652.

A downside is that discovery now need to be able to connect to the unit to get the serial number. This is not possible while another connection to the unit is already established. However, the disovered Thing would not be able to come online anyway while such other connection exists.

@jlaur jlaur added the enhancement An enhancement or new feature for an existing add-on label Mar 18, 2025
@jlaur jlaur force-pushed the danfossairunit-discovery branch 2 times, most recently from 2c9f1e6 to d4e0d61 Compare March 19, 2025 21:47
Signed-off-by: Jacob Laursen <[email protected]>
@jlaur jlaur force-pushed the danfossairunit-discovery branch from d4e0d61 to ec752ba Compare March 19, 2025 21:53
@jlaur jlaur marked this pull request as ready for review March 19, 2025 21:54
@jlaur jlaur requested a review from pravussum as a code owner March 19, 2025 21:54
@jlaur jlaur changed the title [danfossairunit] Improve discovery [danfossairunit] Use serial number as valid Thing ID in discovery Mar 19, 2025
Copy link
Contributor

@lsiepel lsiepel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, LGTM

Would be nice if @pravussum could comment.

@pravussum
Copy link
Contributor

pravussum commented Mar 22, 2025

Hej, the code changes LGTM so far.
I'm just wondering about two things:

  • what happens to existing things? Will a second, autodiscovered thing appear in the Inbox beside an already configured air unit thing created using the "old way"?
  • will der autodiscovery broadcast try to request the serial number from the air unit over and over again (only to find that its the same and probably failing in the process once the thing holds a connection to the air unit)

@lsiepel
Copy link
Contributor

lsiepel commented Mar 22, 2025

Hej, the code changes LGTM so far. I'm just wondering about two things:

  • what happens to existing things? Will a second, autodiscovered thing appear in the Inbox beside an already configured air unit thing created using the "old way"?

No, they are from now on matched by the new representation-property for both old and new.

  • will der autodiscovery broadcast try to request the serial number from the air unit over and over again (only to find that its the same and probably failing in the process once the thing holds a connection to the air unit)

Only when manually discovering items. There does not seem to be a backgroudn discovery proces for this binding.

@lsiepel lsiepel merged commit 8ef6b6a into openhab:main Mar 22, 2025
2 checks passed
@lsiepel lsiepel added this to the 5.0 milestone Mar 22, 2025
@jlaur
Copy link
Contributor Author

jlaur commented Mar 22, 2025

Hej, the code changes LGTM so far.

Thanks for the review, and the others as well. 👍

  • what happens to existing things? Will a second, autodiscovered thing appear in the Inbox beside an already configured air unit thing created using the "old way"?

This is handled, since the Thing handler already sets the seriaNumber property. So no, when already having a unit configured with the same serial number as a discovered once, it will not be added to the inbox.

  • will der autodiscovery broadcast try to request the serial number from the air unit over and over again (only to find that its the same and probably failing in the process once the thing holds a connection to the air unit)

That's a really good question! I will test this some more. I did test it for manually triggered discovery while already having a connection from another openHAB instance, and here it will obviously fail when trying to connect. I'm afraid the same might happen for manually triggered discovery when already having the Thing online. In this case the discovery will be delayed by the 5 second500 ms timeout, and the CCM will not be discovered. I will verify to be sure. I guess the only use-case for manual discovery after already having a configured Thing would be having multiple Air units, which is probably rare.

For auto-discovery I need to check how often this might happen.

I will get back after testing and thinking about how this might be improved.

lsiepel

This comment was marked as outdated.

@jlaur jlaur deleted the danfossairunit-discovery branch March 22, 2025 23:32
@jlaur
Copy link
Contributor Author

jlaur commented Mar 22, 2025

will der autodiscovery broadcast try to request the serial number from the air unit over and over again (only to find that its the same and probably failing in the process once the thing holds a connection to the air unit)

For auto-discovery I need to check how often this might happen.

Auto-discovery is triggered only on component activation and when configuration for the discovery service is changed. So during openHAB startup I observed the discovery to be performed successfully quite some time before thing Thing came online (different start levels). Also it will be triggered when adding/replacing a JAR for the binding.

So yes, it will request the serial number over and over again, but not very often. And no, it doesn't seem to be the case that it will fail the process under normal circumstances because OSGi component activation happens long before reaching the start level that will initialize handlers.

@jlaur
Copy link
Contributor Author

jlaur commented Mar 23, 2025

So during openHAB startup I observed the discovery to be performed successfully quite some time before thing Thing came online (different start levels). Also it will be triggered when adding/replacing a JAR for the binding.

I think actually that's a result of a lacking background discovery implementation:
https://www.openhab.org/docs/concepts/discovery.html#background-discovery

The binding does a one-shot discovery rather than continuously performing discovery until asked to stop:

@Override
protected void startBackgroundDiscovery() {
logger.debug("Start Danfoss Air CCM background discovery");
scheduler.execute(this::discover);
}

Usually bindings create a ScheduledFuture to continuously check for new devices.

I'm not sure if background discovery makes much sense for this binding. I don't think it needs to same convenience as for example a Zigbee binding, where it could happen more frequently that new devices shows up after a trip to IKEA etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement An enhancement or new feature for an existing add-on
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants