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

[nuki] Fixed configuration reload on initialization #12276

Merged
merged 1 commit into from
Feb 27, 2022
Merged

Conversation

janvyb
Copy link
Contributor

@janvyb janvyb commented Feb 12, 2022

Fixed bug mentionend in https://community.openhab.org/t/new-openhab2-binding-for-nuki-smart-locks/25940/186.

When user changes configuration property (unlatch in this case), openhab calls initialize() on Thing, but since configuration was only loaded in constructor, any changes user made will not take effect until openhab restart or reinstallation of binding.

I've also added logging of request received from bridge when handling callback, since I noticed some weird NullpointerExceptions in my logfile which were probably caused by invalid request, but without seeing the data sent it's hard to debug.

@lolodomo lolodomo added the bug An unexpected problem or unintended behavior of an add-on label Feb 13, 2022
responseEntity = doHandle(bridgeApiLockStateRequestDto, request.getParameter("bridgeId"));
try {
responseEntity = doHandle(bridgeApiLockStateRequestDto);
} catch (Exception e) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Probably more something only for you as developer to find a potential bug.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I mean, yes, that's exactly why I added it. If someone reports problem with callback I won't be able to debug it if I don't know what was sent.

Copy link
Contributor

Choose a reason for hiding this comment

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

But do you have an example of exception by a user?
Why not rather analyzing the current code and only catch more specific exceptions?
In case this change makes sense, logging at warn level would be more appropriate.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As I've said I've added it because I found some Nullpointers in logfile which I can't replicate (which means it could happen to someone else) and knowing what data were sent would really help. I agree that warn would be better.

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 fixing the NPE in this case, rather than catching the exception?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've fixed the one place it throws NPE but it still would be helpful to see the data sent since that boolean flag should not be null

@janvyb
Copy link
Contributor Author

janvyb commented Feb 24, 2022

How about this? I renamed the method, I didn't like the loadConfiguration() name since it did too much and you would not expect that method to have any side effects (like also changing thing configuration).

@lolodomo
Copy link
Contributor

That looks even better now.
But please reload the configuration at first in initialize because I am not sure the load in the constructor is a guarantee to have the proper configuration. Normally, the loading is done in initialize.

@lolodomo
Copy link
Contributor

lolodomo commented Feb 26, 2022

Just to be clear, here is what I was suggesting:

    public void initialize() {
        this.configuration = getConfigAs(getConfigurationClass());
        if (migrateConfiguration()) {
            this.configuration = getConfigAs(getConfigurationClass());
        }
        scheduler.execute(this::initializeHandler);
    }

Note that when the thing configuration is updated, I believe the core framework will dispose/initialize again the thing handler. So I believe the proper code should be:

    public void initialize() {
        this.configuration = getConfigAs(getConfigurationClass());
        if (migrateConfiguration()) {
            return;
        }
        scheduler.execute(this::initializeHandler);
    }

but that would be better if you can test it (migration) because I am not 100% sure.

* Fixed bug where thing configuration was not reloaded after reinitialization
* Added better logging when processing bridge callback

Signed-off-by: Jan Vybíral <jan.vybiral1@gmail.com>
@janvyb
Copy link
Contributor Author

janvyb commented Feb 26, 2022

I think the first one is correct, the handler needs to be initialized again every time config is updated, initializeHandler is not a framework method, it's a private method of nuki handler which reloads it's state.

@wborn wborn added rebuild Triggers Jenkins PR build and removed rebuild Triggers Jenkins PR build labels Feb 26, 2022
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 923f720 into openhab:main Feb 27, 2022
@lolodomo lolodomo added this to the 3.3 milestone Feb 27, 2022
NickWaterton pushed a commit to NickWaterton/openhab-addons that referenced this pull request Apr 27, 2022
* Fixed bug where thing configuration was not reloaded after reinitialization
* Added better logging when processing bridge callback

Signed-off-by: Jan Vybíral <jan.vybiral1@gmail.com>
Signed-off-by: Nick Waterton <n.waterton@outlook.com>
andan67 pushed a commit to andan67/openhab-addons that referenced this pull request Nov 6, 2022
* Fixed bug where thing configuration was not reloaded after reinitialization
* Added better logging when processing bridge callback

Signed-off-by: Jan Vybíral <jan.vybiral1@gmail.com>
andrasU pushed a commit to andrasU/openhab-addons that referenced this pull request Nov 12, 2022
* Fixed bug where thing configuration was not reloaded after reinitialization
* Added better logging when processing bridge callback

Signed-off-by: Jan Vybíral <jan.vybiral1@gmail.com>
Signed-off-by: Andras Uhrin <andras.uhrin@gmail.com>
psmedley pushed a commit to psmedley/openhab-addons that referenced this pull request Feb 23, 2023
* Fixed bug where thing configuration was not reloaded after reinitialization
* Added better logging when processing bridge callback

Signed-off-by: Jan Vybíral <jan.vybiral1@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug An unexpected problem or unintended behavior of an add-on
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants