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

[lcn] Add LCN binding #7509

Merged
merged 16 commits into from
Jun 17, 2020
Merged

[lcn] Add LCN binding #7509

merged 16 commits into from
Jun 17, 2020

Conversation

fwolter
Copy link
Member

@fwolter fwolter commented Apr 30, 2020

Migrates the Local Control Network Binding from OH1 to OH2.

Closes #108

Signed-off-by: Fabian Wolter [email protected]

@fwolter fwolter requested a review from a team as a code owner April 30, 2020 17:35
@cpmeister cpmeister added new binding If someone has started to work on a binding. For a new binding PR. oh1 migration Relates to migrating an openHAB 1 addon to openHAB 2 labels Apr 30, 2020
@TravisBuddy
Copy link

Travis tests were successful

Hey @fwolter,
we found no major flaws with your code. Still you might want to look at this logfile, as we usually suggest some optional improvements.

fwolter added 3 commits May 31, 2020 23:34
Migrates the Local Control Network Binding from OH1 to OH2.

Closes #108

Signed-off-by: Fabian Wolter <[email protected]>
Signed-off-by: Fabian Wolter <[email protected]>
Signed-off-by: Fabian Wolter <[email protected]>
@TravisBuddy
Copy link

Travis tests were successful

Hey @fwolter,
we found no major flaws with your code. Still you might want to look at this logfile, as we usually suggest some optional improvements.

1 similar comment
@TravisBuddy
Copy link

Travis tests were successful

Hey @fwolter,
we found no major flaws with your code. Still you might want to look at this logfile, as we usually suggest some optional improvements.

@kaikreuzer
Copy link
Member

Wow, a huge work @fwolter, thanks!
Before going into a review, can you give some hints on whether you have written everything from scratch or if you have ported code over from the 1.x version?

@fwolter
Copy link
Member Author

fwolter commented Jun 2, 2020

Thanks, the following classes are based on the OH1 implementation. Most of them are DTOs and constant definitions. The rest is written from scratch.

  • SendDataPlainText
  • SendData
  • SendDataPck
  • RequestStatus
  • ModInfo
  • ConnectionSettings
  • ConnectionCallback
  • Variable
  • VariableValue
  • ReverseNumber
  • PckGenerator

@TravisBuddy
Copy link

Travis tests were successful

Hey @fwolter,
we found no major flaws with your code. Still you might want to look at this logfile, as we usually suggest some optional improvements.

Signed-off-by: Fabian Wolter <[email protected]>
@TravisBuddy
Copy link

Travis tests have failed

Hey @fwolter,
please read the following log in order to understand the failure reason. There might also be some helpful tips along the way.
It will be awesome if you fix what is wrong and commit the changes.

@fwolter fwolter closed this Jun 6, 2020
@fwolter fwolter reopened this Jun 6, 2020
@TravisBuddy
Copy link

Travis tests have failed

Hey @fwolter,
please read the following log in order to understand the failure reason. There might also be some helpful tips along the way.
It will be awesome if you fix what is wrong and commit the changes.

Signed-off-by: Fabian Wolter <[email protected]>
@TravisBuddy
Copy link

Travis tests were successful

Hey @fwolter,
we found no major flaws with your code. Still you might want to look at this logfile, as we usually suggest some optional improvements.

Copy link
Member

@kaikreuzer kaikreuzer left a comment

Choose a reason for hiding this comment

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

Awesome work, @fwolter!
Really very clean and professional code and I see that you dived deep into the openHAB concepts already by using advanced stuff like profiles, vetos, etc.
My review comments should all be fairly simple, there's nothing that should mean any huge effort. Please see below and let me know, if you have any questions!

bundles/org.openhab.binding.lcn/README.md Outdated Show resolved Hide resolved
bundles/org.openhab.binding.lcn/README.md Outdated Show resolved Hide resolved
bundles/org.openhab.binding.lcn/README.md Show resolved Hide resolved
bundles/org.openhab.binding.lcn/README.md Outdated Show resolved Hide resolved
bundles/org.openhab.binding.lcn/README.md Show resolved Hide resolved
<channel-type id="output" advanced="true">
<item-type>Dimmer</item-type>
<label>Output</label>
<autoUpdatePolicy>veto</autoUpdatePolicy>
Copy link
Member

Choose a reason for hiding this comment

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

Please note that your binding is expected to quickly provide state updates after receiving commands, if you go for a veto here.
Is that really the case for all the channels where you have put "veto"?

Copy link
Member Author

Choose a reason for hiding this comment

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

I removed the vetos for these states which must be polled after changing and left the veto for those, which are updated event-based (~100ms after the change).

Copy link
Contributor

@cpmeister cpmeister left a comment

Choose a reason for hiding this comment

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

This is amazing work you have done here. Nice job!

Comment on lines 102 to 103
AbstractLcnModuleSubHandler newHandler = type.getSubHandlerClass()
.getDeclaredConstructor(LcnModuleHandler.class, ModInfo.class).newInstance(this, info);
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not have each LcnChannelGroup enum instance include a AbstractLcnModuleSubHandler factory lambda method for creating class instances? That way you wouldn't need to use reflection here.

Copy link
Member Author

Choose a reason for hiding this comment

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

I really like this idea! Refactored.

fwolter added 4 commits June 10, 2020 15:09
Signed-off-by: Fabian Wolter <[email protected]>
Signed-off-by: Fabian Wolter <[email protected]>
Signed-off-by: Fabian Wolter <[email protected]>
Signed-off-by: Fabian Wolter <[email protected]>
@fwolter
Copy link
Member Author

fwolter commented Jun 10, 2020

Thank you very much for your positive feedback and your time spent! Really appreciate it! I implemented your remarks and commented on your questions. During testing, I found two bugs, I fixed.

@TravisBuddy
Copy link

Travis tests were successful

Hey @fwolter,
we found no major flaws with your code. Still you might want to look at this logfile, as we usually suggest some optional improvements.

Signed-off-by: Fabian Wolter <[email protected]>
Copy link
Contributor

@cpmeister cpmeister left a comment

Choose a reason for hiding this comment

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

I think these are my final changes. Thanks for keeping up 😄

@TravisBuddy
Copy link

Travis tests were successful

Hey @fwolter,
we found no major flaws with your code. Still you might want to look at this logfile, as we usually suggest some optional improvements.

@TravisBuddy
Copy link

Travis tests were successful

Hey @fwolter,
we found no major flaws with your code. Still you might want to look at this logfile, as we usually suggest some optional improvements.

@fwolter fwolter requested a review from cpmeister June 13, 2020 19:19
*
* @author Fabian Wolter - Initial Contribution
*/
@NonNullByDefault
public abstract class AbstractState {
public abstract class AbstractState<T extends AbstractStateMachine<T, U>, U extends AbstractState<T, U>> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it necessary to add all these generics? Shouldn't the new state factory function just be a simple Function< AbstractStateMachine, AbstractState>?

Copy link
Member Author

Choose a reason for hiding this comment

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

I tried several approaches, but couldn't get rid of the generics. Any suggestions?

Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure what to say. As an example, this code compiles just fine:


    public interface State {

    }

    public interface StateMachine {
        public void nextState(Function<StateMachine, State> stateFactory);
    }

    public class StateImpl implements State {

        private StateMachine context;

        public StateImpl(StateMachine context) {
            this.context = context;
        }

        public void changeState() {
            context.nextState(StateImpl::new);
        }
    }

Copy link
Member Author

Choose a reason for hiding this comment

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

The problems arise when storing data in the context like the connection object. These data cannot be accessed from within StateImpl, because the reference to the context is of the interface's type. I used generics to be able to access the concrete type.

The state machine and state abstraction layer could be removed (and so the generics), but then the code wouldn't be reusable.

Another approach is to replace the generics by casts. If I see correctly only a single cast would be necessary.

As always, there are several solutions with their pros and cons. Maybe I hadn't the bright idea, yet.

Copy link
Contributor

@cpmeister cpmeister left a comment

Choose a reason for hiding this comment

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

Well, I took that as a challenge and spent way too much time trying to find a better solution, but I can't say I really found one. I think the generics are irreducibly complex, so they have to stay.
With that resolved I don't really have anything else to suggest. Nice work.

@fwolter
Copy link
Member Author

fwolter commented Jun 16, 2020

Well, I took that as a challenge and spent way too much time trying to find a better solution, but I can't say I really found one.

Me too :) Thanks!

Copy link
Member

@kaikreuzer kaikreuzer left a comment

Choose a reason for hiding this comment

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

Many thanks again, @fwolter!
Also for your patience with the numerous reviews by @cpmeister. 🤣

Let's get that in openHAB 2.5.6!

@kaikreuzer kaikreuzer merged commit 0ae2319 into openhab:2.5.x Jun 17, 2020
@cpmeister cpmeister added this to the 2.5.6 milestone Jun 17, 2020
@fwolter
Copy link
Member Author

fwolter commented Jun 17, 2020

Thanks for merging and thank you very much for the highly professional review feedback. I integrated your proposals very gladly!

@fwolter fwolter deleted the 108-lcn branch June 17, 2020 20:14
@timbms
Copy link

timbms commented Jun 26, 2020

Thanks for this great enhancement
Sorry my mistake. I issued the wrong command. It just works great

@fwolter
Copy link
Member Author

fwolter commented Jun 26, 2020

Can you please open an issue? I will take a look into it.

@timbms
Copy link

timbms commented Jun 26, 2020

Was about to do so. No reason to do so. Sorry for the confusion.

knikhilwiz pushed a commit to knikhilwiz/openhab2-addons that referenced this pull request Jul 12, 2020
* [lcn] Add LCN binding

Migrates the Local Control Network Binding from OH1 to OH2.

Closes openhab#108

Signed-off-by: Fabian Wolter <[email protected]>
CSchlipp pushed a commit to CSchlipp/openhab-addons that referenced this pull request Jul 26, 2020
* [lcn] Add LCN binding

Migrates the Local Control Network Binding from OH1 to OH2.

Closes openhab#108

Signed-off-by: Fabian Wolter <[email protected]>
Signed-off-by: CSchlipp <[email protected]>
andrewfg pushed a commit to andrewfg/openhab-addons that referenced this pull request Aug 31, 2020
* [lcn] Add LCN binding

Migrates the Local Control Network Binding from OH1 to OH2.

Closes openhab#108

Signed-off-by: Fabian Wolter <[email protected]>
andrewfg pushed a commit to andrewfg/openhab-addons that referenced this pull request Aug 31, 2020
* [lcn] Add LCN binding

Migrates the Local Control Network Binding from OH1 to OH2.

Closes openhab#108

Signed-off-by: Fabian Wolter <[email protected]>
andrewfg pushed a commit to andrewfg/openhab-addons that referenced this pull request Aug 31, 2020
* [lcn] Add LCN binding

Migrates the Local Control Network Binding from OH1 to OH2.

Closes openhab#108

Signed-off-by: Fabian Wolter <[email protected]>
andrewfg pushed a commit to andrewfg/openhab-addons that referenced this pull request Aug 31, 2020
* [lcn] Add LCN binding

Migrates the Local Control Network Binding from OH1 to OH2.

Closes openhab#108

Signed-off-by: Fabian Wolter <[email protected]>
DaanMeijer pushed a commit to DaanMeijer/openhab-addons that referenced this pull request Sep 1, 2020
* [lcn] Add LCN binding

Migrates the Local Control Network Binding from OH1 to OH2.

Closes openhab#108

Signed-off-by: Fabian Wolter <[email protected]>
Signed-off-by: Daan Meijer <[email protected]>
markus7017 pushed a commit to markus7017/openhab-addons that referenced this pull request Sep 19, 2020
* [lcn] Add LCN binding

Migrates the Local Control Network Binding from OH1 to OH2.

Closes openhab#108

Signed-off-by: Fabian Wolter <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new binding If someone has started to work on a binding. For a new binding PR. oh1 migration Relates to migrating an openHAB 1 addon to openHAB 2
Projects
None yet
Development

Successfully merging this pull request may close these issues.

LCN binding
5 participants