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

[hdpowerview] Refactor dynamic channels #11853

Merged

Conversation

jlaur
Copy link
Contributor

@jlaur jlaur commented Dec 24, 2021

Signed-off-by: Jacob Laursen [email protected]

Fixes #11852

Refactoring after:

Changes

  • Extracted creation of dynamic channels into separate classes.
  • Renamed methods to be consistent with channel terminology (scene collections -> scene groups, scheduled events -> automations).
  • Optimized AutomationChannelBuilder scene/scene collection lookups.
  • Reduced log level from error to warning for scheduled events with unknown scene or scene collection.
  • Added unit test coverage for SceneChannelBuilder, SceneGroupChannelBuilder and AutomationChannelBuilder.
  • Fix small problem with empty properties during startup.

Test

I have been running this version for a longer period in production without any issues. All my channels (scenes, scene groups and automations) are working exactly as before the changes. This is the intention as the PR is purely refactoring not changing any behavior.

@jlaur jlaur changed the title [hdpowerview] Refactor creation of dynamic channels [hdpowerview] Fix support for Hub v1 and refactor dynamic channels Dec 25, 2021
@jlaur jlaur marked this pull request as ready for review December 25, 2021 15:16
@jlaur
Copy link
Contributor Author

jlaur commented Dec 25, 2021

I have created #11857 with a direct bugfix after the findings documented in #11856.

@jlaur jlaur changed the title [hdpowerview] Fix support for Hub v1 and refactor dynamic channels [hdpowerview] Fix support for PowerView Hub v1 and refactor dynamic channels Dec 25, 2021
@jlaur
Copy link
Contributor Author

jlaur commented Dec 25, 2021

JAR for this PR.

@jlaur jlaur force-pushed the 11852-hdpowerview-dynamic-channel-refactoring branch from c1e1d50 to 3924ec3 Compare December 26, 2021 16:08
@jlaur jlaur changed the title [hdpowerview] Fix support for PowerView Hub v1 and refactor dynamic channels [hdpowerview] Refactor dynamic channels Dec 26, 2021
@lolodomo lolodomo added the enhancement An enhancement or new feature for an existing add-on label Dec 27, 2021
@jlaur jlaur force-pushed the 11852-hdpowerview-dynamic-channel-refactoring branch 2 times, most recently from a8472e7 to a44919e Compare January 3, 2022 12:42
@jlaur
Copy link
Contributor Author

jlaur commented Jan 3, 2022

@jlaur jlaur requested a review from a team January 4, 2022 13:18
@jlaur jlaur force-pushed the 11852-hdpowerview-dynamic-channel-refactoring branch from a44919e to 1a81b03 Compare January 4, 2022 19:46
@jlaur jlaur requested a review from andrewfg January 5, 2022 15:58
@jlaur jlaur force-pushed the 11852-hdpowerview-dynamic-channel-refactoring branch 2 times, most recently from e6def1d to fc6fb44 Compare January 7, 2022 15:29
@andrewfg
Copy link
Contributor

andrewfg commented Jan 7, 2022

As mentioned in my email, I suggest to add the Hunter Douglas API pdf and your API addendum pdf files to the binding's doc folder and also add a 'Developers' chapter at the bottom of the Readme.md with links that point to those files.

@jlaur
Copy link
Contributor Author

jlaur commented Jan 7, 2022

As mentioned in my email, I suggest to add the Hunter Douglas API pdf and your API addendum pdf files to the binding's doc folder and also add a 'Developers' chapter at the bottom of the Readme.md with links that point to those files.

Thanks for your mail, I'm currently responding. Short version here: PDF will not be included in context of this PR at least.

@jlaur jlaur marked this pull request as draft January 7, 2022 19:38
@jlaur jlaur force-pushed the 11852-hdpowerview-dynamic-channel-refactoring branch from fc6fb44 to 9c6a63a Compare January 7, 2022 22:56
@jlaur jlaur marked this pull request as ready for review January 7, 2022 23:00
@jlaur jlaur force-pushed the 11852-hdpowerview-dynamic-channel-refactoring branch 2 times, most recently from d7e0603 to 225cd29 Compare January 9, 2022 14:23
Copy link
Contributor

@andrewfg andrewfg left a comment

Choose a reason for hiding this comment

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

I could not test the functionality because I don’t have automations, or scene groups, but the code looks good to me.

@jlaur
Copy link
Contributor Author

jlaur commented Jan 9, 2022

I could not test the functionality because I don’t have automations, or scene groups, but the code looks good to me.

Thanks for having a look, @andrewfg.

@jlaur jlaur force-pushed the 11852-hdpowerview-dynamic-channel-refactoring branch from ffc6be4 to e7a70f5 Compare January 15, 2022 19:53
@jlaur jlaur requested a review from andylintner as a code owner January 15, 2022 19:53
@jlaur
Copy link
Contributor Author

jlaur commented Jan 15, 2022

There is now a conflicting file to resolve.

That was expected. It's resolved now.

I reviewed all the code except the tests and I have no remark. I will review the tests later.

Thanks a lot!

@lolodomo
Copy link
Contributor

The problem with the way you fixed the conflict is either I have to do a full review again :-(

@jlaur
Copy link
Contributor Author

jlaur commented Jan 15, 2022

The problem with the way you fixed the conflict is either I have to do a full review again :-(

I'm really sorry about that, what happened and how can I avoid it in the future? From previous PR's I had an understanding that merging back from main is not good practice, but rebase is preferred. Is that correct? So I rebased towards main and resolved the conflicts. All commits were preserved in order to keep same history.

If everything was reviewed excepts tests, why would you have to do a full review again? Conflict was resolved in first commit, which you of course cannot see. Two methods conflicted because they had new throws in other PR and were renamed in this PR. So I think that's the only change which is not transparent because of the rebase history manipulation, but that's kind of natural because it was a rebase.

@andrewfg
Copy link
Contributor

how can I avoid it in the future?

I think the normal process is to hand edit any file that has a merge conflict, to remove the conflict, and then just do a normal commit and push.

@jlaur
Copy link
Contributor Author

jlaur commented Jan 16, 2022

I think the normal process is to hand edit any file that has a merge conflict, to remove the conflict, and then just do a normal commit and push.

But you still need to merge one way or the other to resolve the conflict. So either merge from main or rebase to main.

@jlaur
Copy link
Contributor Author

jlaur commented Jan 16, 2022

I think the normal process is to hand edit any file that has a merge conflict, to remove the conflict, and then just do a normal commit and push.

But you still need to merge one way or the other to resolve the conflict. So either merge from main or rebase to main.

#8902 (comment)

This was what I recalled.

@andrewfg
Copy link
Contributor

This was what I recalled.

Aha. I think it depends on the circumstances of the conflict. I think that there are basically two cases where merge conflicts can arise -- namely..

  1. Two people have independently pushed commits to the same java file within the scope of the binding that is subject of the current pull request. In that case it is only necessary to manually edit the respective file that has the conflict (to essentially include the work of both the people concerned), and then re-commit and push that specific file.
  2. The branch your-name/openhab-addons/your-branch where the PR is hosted, has become generally out of synchronization with the branch openhab/openhab-addons/main. In this case, the rebase procedure described in kai's link is required.

@jlaur
Copy link
Contributor Author

jlaur commented Jan 16, 2022

I think neither of those cases applied here. It wasn't "generally out of synchronization", but for two specific method signatures there was a change in each PR - method name in one and thrown exceptions in another. If I had manually picked from the other, it wouldn't compile, as my PR didn't have the new exception type. So I had to actually merge, either by rebasing or by merging main back into my branch. @lolodomo - please advice. I would prefer to not obstruct any ongoing PR reviews, but I'm not sure how in this case. I'm pretty annoyed myself when someone will be doing frequent rebases + squashing everything into a single commit, since it makes it impossible to track what changed during the review process.

@lolodomo
Copy link
Contributor

lolodomo commented Jan 16, 2022

I am not at all a Git expert. The way I am doing it generally is to update my local main branch from the remote main branch and then merge my local main branch into my local work branch, and finally push my local work branch into my remote work branch. It avoids to have all the history pushed again. But in practice, I believe it does not help to identify what has changed with the merge. At least, you know that the only change since the last review was this merge.
If you tell me you have done no other changes except the merge, I believe you. I will just take 2 minutes to do a very very partial look to what I have already reviewed and then switch to the tests.

@jlaur
Copy link
Contributor Author

jlaur commented Jan 16, 2022

The way I am doing it generally is to update my local main branch from the remote main branch and then merge my local main branch into my local work branch, and finally push my local work branch into my remote work branch. It avoids to have all the history pushed again.

Correct, this gives the most detailed change tracking as history will not be manipulated and no force push is needed. However, it also makes history somewhat more complex, i.e. less clean as end result. This was my exact approach in the referenced PR when Kai requested me to rebase instead.

But in practice, I believe it does not help to identify what has changed with the merge. At least, you know that the only change since the last review was this merge.
If you tell me you have done no other changes except the merge, I believe you. I will just take 2 minutes to do a very very partial look to what I have already reviewed and then switch to the tests.

These were the only changes, i.e. conflict resolving:

Other (first exception changed, method still not renamed):

    private List<SceneCollection> updateSceneCollectionChannels()
            throws HubInvalidResponseException, HubProcessingException, HubMaintenanceException {

This (first exception still not changed, method renamed):

    private List<SceneCollection> updateSceneGroupChannels()
            throws JsonParseException, HubProcessingException, HubMaintenanceException {

The same for one other method which was renamed here and had exception changed in other.

So to sum things up, I think I did was I needed to do, even though it somehow interfered with your review?

Copy link
Contributor

@lolodomo lolodomo left a comment

Choose a reason for hiding this comment

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

LGTM

@lolodomo lolodomo merged commit e44dfe7 into openhab:main Jan 17, 2022
@lolodomo lolodomo added this to the 3.3 milestone Jan 17, 2022
moesterheld pushed a commit to moesterheld/openhab-addons that referenced this pull request Jan 18, 2022
* Extract dynamic channel creation to separate classes.
* Avoid double list allocations.
* Add test coverage for scenarios with no channels built.
* Extract common builder stuff to super class.
* Fix grammar.
* Reduce constructor access modifiers.
* Removed unneeded this keyword for protected method.
* Fix null annotation issues.

Signed-off-by: Jacob Laursen <[email protected]>
nemerdaud pushed a commit to nemerdaud/openhab-addons that referenced this pull request Jan 28, 2022
* Extract dynamic channel creation to separate classes.
* Avoid double list allocations.
* Add test coverage for scenarios with no channels built.
* Extract common builder stuff to super class.
* Fix grammar.
* Reduce constructor access modifiers.
* Removed unneeded this keyword for protected method.
* Fix null annotation issues.

Signed-off-by: Jacob Laursen <[email protected]>
NickWaterton pushed a commit to NickWaterton/openhab-addons that referenced this pull request Apr 27, 2022
* Extract dynamic channel creation to separate classes.
* Avoid double list allocations.
* Add test coverage for scenarios with no channels built.
* Extract common builder stuff to super class.
* Fix grammar.
* Reduce constructor access modifiers.
* Removed unneeded this keyword for protected method.
* Fix null annotation issues.

Signed-off-by: Jacob Laursen <[email protected]>
Signed-off-by: Nick Waterton <[email protected]>
andan67 pushed a commit to andan67/openhab-addons that referenced this pull request Nov 6, 2022
* Extract dynamic channel creation to separate classes.
* Avoid double list allocations.
* Add test coverage for scenarios with no channels built.
* Extract common builder stuff to super class.
* Fix grammar.
* Reduce constructor access modifiers.
* Removed unneeded this keyword for protected method.
* Fix null annotation issues.

Signed-off-by: Jacob Laursen <[email protected]>
andrasU pushed a commit to andrasU/openhab-addons that referenced this pull request Nov 12, 2022
* Extract dynamic channel creation to separate classes.
* Avoid double list allocations.
* Add test coverage for scenarios with no channels built.
* Extract common builder stuff to super class.
* Fix grammar.
* Reduce constructor access modifiers.
* Removed unneeded this keyword for protected method.
* Fix null annotation issues.

Signed-off-by: Jacob Laursen <[email protected]>
Signed-off-by: Andras Uhrin <[email protected]>
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.

[hdpowerview] Bridge handler dynamic channel refactoring
3 participants