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

[boschshc] Add bridge and device discovery #14197

Merged
merged 3 commits into from
Mar 24, 2023

Conversation

GerdZanker
Copy link
Contributor

@GerdZanker GerdZanker commented Jan 9, 2023

#14195 [boschshc] Bridge discovery is implemented via mDNS, local IP addresses are checked. If a GET returns the public SHC information,
then this shcIpAddress is reported as a discovered bridge.

Devices are always discovered after successful pairing, but a manual scan is also possible.

@jlaur jlaur changed the title #14195 [boschshc] Bridge and Device Discovery [boschshc] Bridge and Device Discovery Jan 9, 2023
@jlaur jlaur linked an issue Jan 9, 2023 that may be closed by this pull request
@jlaur jlaur added the enhancement An enhancement or new feature for an existing add-on label Jan 9, 2023
@GerdZanker GerdZanker force-pushed the feature/#14195-bosch-shc-discovery branch from 914b314 to e30b864 Compare January 23, 2023 19:36
@GerdZanker
Copy link
Contributor Author

Hello @david-pace, can you already take a look at the code and how I now write the test?
There are two TODOs regarding the list of supported things pending which I will update within the next days.

@david-pace
Copy link
Member

I'll look at it as soon as I find some time, probably at the weekend.

new AbstractMap.SimpleEntry<>("BBL", BoschSHCBindingConstants.THING_TYPE_SHUTTER_CONTROL.getId()), // Rollladenschalter
new AbstractMap.SimpleEntry<>("TWINGUARD", BoschSHCBindingConstants.THING_TYPE_TWINGUARD.getId()), // Twinguard
new AbstractMap.SimpleEntry<>("PSM", BoschSHCBindingConstants.THING_TYPE_INWALL_SWITCH.getId()), // Steckdosen Zwischenstecker
new AbstractMap.SimpleEntry<>("PLUG_COMPACT", BoschSHCBindingConstants.THING_TYPE_INWALL_SWITCH.getId()) // Steckdosen Zwischenstecker kompakt
Copy link
Member

Choose a reason for hiding this comment

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

we now have a dedicated thing type for the plugs (not in-wall switch)

Copy link
Member

@david-pace david-pace left a comment

Choose a reason for hiding this comment

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

added some comments about things I saw at first glance

@GerdZanker
Copy link
Contributor Author

added some comments about things I saw at first glance

Thanks a lot. I will improve your findings together with the updated list/map of devices.
I'm glad to see no big topics regarding my new mockito tests.

Copy link
Member

@david-pace david-pace left a comment

Choose a reason for hiding this comment

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

I found a typo in the key for the 360 camera and I also have some general questions about the keys.

@GerdZanker
Copy link
Contributor Author

I found a typo in the key for the 360 camera and I also have some general questions about the keys.

Fixed the typo, improved the tests code and tried to clarify the questions.
Of cause the available information about your questions is weak and I guess the mapping must be improved later one. But it's the best I know currently.

Soon I will squash and cleanup the commits and provide a bundle Jar for testing with last stable version 3.4.2

@GerdZanker GerdZanker force-pushed the feature/#14195-bosch-shc-discovery branch from 4cca586 to 5d181ec Compare February 21, 2023 18:54
@GerdZanker
Copy link
Contributor Author

Test failing, because of updated code. Branch will be rebased and fixed soon.

@GerdZanker GerdZanker force-pushed the feature/#14195-bosch-shc-discovery branch from 5d181ec to ea1fdb2 Compare February 22, 2023 16:56
Copy link
Member

@david-pace david-pace left a comment

Choose a reason for hiding this comment

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

See comments, plus some checkstyle warnings have been introduced that should be fixed if possible. See file target/code-analysis/report.html. On the main branch I currently see 3 warnings related to catching NullPointerExceptions, on your branch I see 19 additional minor things that could be mitigated easily (like unnecessary empty lines etc.)

@GerdZanker GerdZanker force-pushed the feature/#14195-bosch-shc-discovery branch from ea1fdb2 to 9354467 Compare March 3, 2023 18:34
@GerdZanker
Copy link
Contributor Author

See comments,

All comments should be improved, please check how I handled the InterruptException.

plus some checkstyle warnings have been introduced that should be fixed if possible. See file target/code-analysis/report.html. On the main branch I currently see 3 warnings related to catching NullPointerExceptions, on your branch I see 19 additional minor things that could be mitigated easily (like unnecessary empty lines etc.)

I did my best to get rid of all findings

Copy link
Member

@david-pace david-pace left a comment

Choose a reason for hiding this comment

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

Only a few minor things remaining 👍 I also tested your change with real hardware and everything works nicely 😎

One idea for an enhancement would be the labels for the following items. It would look nicer if they did not have the surrounding - characters and proper readable names:

grafik

@GerdZanker GerdZanker force-pushed the feature/#14195-bosch-shc-discovery branch from 9354467 to dedff34 Compare March 17, 2023 16:47
@GerdZanker
Copy link
Contributor Author

Only a few minor things remaining 👍 I also tested your change with real hardware and everything works nicely 😎

Thanks for your testfeedback

One idea for an enhancement would be the labels for the following items. It would look nicer if they did not have the surrounding - characters and proper readable names:

It took some time to find a solution for nice names, but now this enhancement is part of this PR.

@GerdZanker GerdZanker marked this pull request as ready for review March 17, 2023 16:57
@GerdZanker GerdZanker requested a review from coeing as a code owner March 17, 2023 16:57
// convert "IntrusionDetectionSystem" into "Intrusion Detection System"
String[] allParts = StringUtils.splitByCharacterTypeCamelCase(niceName);
String[] parts = Arrays.stream(allParts).filter(p -> !p.trim().isEmpty()).collect(Collectors.toList())
.toArray(new String[0]);
Copy link
Member

Choose a reason for hiding this comment

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

Array conversion is not needed. You could use String.join() providing a list of strings. But there is an even better way: use Collectors.joining(" ") instead of Collectors.toList() and you're done directly 👍

Copy link
Member

@david-pace david-pace left a comment

Choose a reason for hiding this comment

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

Awesome, this looks great! Thanks for improving the labels, I see that this was not trivial ;) I tested again with the actual hardware and it looks good 👍

I just have a minor suggestion which could save one line of code, but this is optional. Good work 😎

Copy link
Contributor

@jlaur jlaur left a comment

Choose a reason for hiding this comment

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

Thanks! In addition to the review of @david-pace (👍) only a single comment from my side.

@GerdZanker GerdZanker force-pushed the feature/#14195-bosch-shc-discovery branch from dedff34 to f0c003e Compare March 20, 2023 19:23
@GerdZanker GerdZanker force-pushed the feature/#14195-bosch-shc-discovery branch from f0c003e to da883d9 Compare March 20, 2023 19:37
@GerdZanker
Copy link
Contributor Author

Out of topic, but @jlaur, do you know how I can provide a nice binding icon for boschshc? I wasn't able to find a documentation or used the wrong words.

@jlaur
Copy link
Contributor

jlaur commented Mar 20, 2023

Out of topic, but @jlaur, do you know how I can provide a nice binding icon for boschshc? I wasn't able to find a documentation or used the wrong words.

Yes, see here: https://www.openhab.org/docs/developer/bindings/#add-your-binding-s-logo-to-the-openhab-website

Comment on lines 245 to 248
2023-03-20 20:30:48.026 [INFO ] [g.discovery.internal.PersistentInbox] - Added new thing 'boschshc:security-camera-eyes:yourBrideName:hdm_Cameras_XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX' to inbox.
2023-03-20 20:30:48.026 [INFO ] [g.discovery.internal.PersistentInbox] - Added new thing 'boschshc:smoke-detector:yourBrideName:hdm_HomeMaticIP_XXXXXXXXXXXXXXXXXXXXXXXX' to inbox.
2023-03-20 20:30:48.027 [INFO ] [g.discovery.internal.PersistentInbox] - Added new thing 'boschshc:twinguard:yourBrideName:hdm_ZigBee_XXXXXXXXXXXXXXXX' to inbox.
2023-03-20 20:30:48.028 [INFO ] [g.discovery.internal.PersistentInbox] - Added new thing 'boschshc:smart-bulb:yourBrideName:hdm_PhilipsHueBridge_HueLight_XXXXXXXXXXXXXXXX-XX_XXXXXXXXXXXX' to inbox.
Copy link
Contributor

Choose a reason for hiding this comment

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

yourBrideName intended? 👰

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Arg - last minute changes 🤦‍♂️

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Out of topic, but @jlaur, do you know how I can provide a nice binding icon for boschshc? I wasn't able to find a documentation or used the wrong words.

Yes, see here: https://www.openhab.org/docs/developer/bindings/#add-your-binding-s-logo-to-the-openhab-website

Thanks a lot for the link to this obvious location.
I wasn't able to get information when I searched for hints the last time, but its already some months ago - hopefully this answer was added just recently 🤔

Bridge discovery is implemented via mDNS, local IP addresses are checked.
If a GET returns the public SHC information,
then this shcIpAddress is reported as a discovered bridge.

Devices are always discovered after successful pairing, but a manual scan is also possible.

Added unit tests for Bridge and Device Discovery.

Signed-off-by: Gerd Zanker <gerd.zanker@web.de>
Three AvoidCatchingNPE findings are pending in the class BoschHttpClient.
Could be false positive, because NullPointer exceptions appear during tests run.

Signed-off-by: Gerd Zanker <gerd.zanker@web.de>
@GerdZanker GerdZanker force-pushed the feature/#14195-bosch-shc-discovery branch from da883d9 to 1205492 Compare March 20, 2023 19:55
Copy link
Contributor

@jlaur jlaur left a comment

Choose a reason for hiding this comment

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

Last minute finding, sorry.

Signed-off-by: Gerd Zanker <gerd.zanker@web.de>
Copy link
Contributor

@jlaur jlaur left a comment

Choose a reason for hiding this comment

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

LGTM

@jlaur jlaur merged commit 3b08217 into openhab:main Mar 24, 2023
@jlaur jlaur added this to the 4.0 milestone Mar 24, 2023
@jlaur jlaur changed the title [boschshc] Bridge and Device Discovery [boschshc] Add bridge and device discovery Mar 24, 2023
FordPrfkt pushed a commit to FordPrfkt/openhab-addons that referenced this pull request Apr 20, 2023
* openhab#14195 Bridge and Device Discovery

Bridge discovery is implemented via mDNS, local IP addresses are checked.
If a GET returns the public SHC information,
then this shcIpAddress is reported as a discovered bridge.

Devices are always discovered after successful pairing, but a manual scan is also possible.

Added unit tests for Bridge and Device Discovery.

Signed-off-by: Gerd Zanker <gerd.zanker@web.de>
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.

[boschshc] Discovery of Bridge and Things
4 participants