-
-
Notifications
You must be signed in to change notification settings - Fork 112
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
Allow thing handler to skip device initialization and execute it on config update #409
Allow thing handler to skip device initialization and execute it on config update #409
Conversation
@hsudbrock As discussed, please join this PR and do a review. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @TomTravaglino , I have added some comments inline.
org.openhab.binding.zigbee/src/main/java/org/openhab/binding/zigbee/ZigBeeBindingConstants.java
Outdated
Show resolved
Hide resolved
...nhab.binding.zigbee/src/main/java/org/openhab/binding/zigbee/handler/ZigBeeThingHandler.java
Show resolved
Hide resolved
...nhab.binding.zigbee/src/main/java/org/openhab/binding/zigbee/handler/ZigBeeThingHandler.java
Outdated
Show resolved
Hide resolved
...nhab.binding.zigbee/src/main/java/org/openhab/binding/zigbee/handler/ZigBeeThingHandler.java
Outdated
Show resolved
Hide resolved
@hsudbrock I updated the PR |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @TomTravaglino ! Two comments regarding logging...
...nhab.binding.zigbee/src/main/java/org/openhab/binding/zigbee/handler/ZigBeeThingHandler.java
Outdated
Show resolved
Hide resolved
...nhab.binding.zigbee/src/main/java/org/openhab/binding/zigbee/handler/ZigBeeThingHandler.java
Outdated
Show resolved
Hide resolved
...nhab.binding.zigbee/src/main/java/org/openhab/binding/zigbee/handler/ZigBeeThingHandler.java
Outdated
Show resolved
Hide resolved
...nhab.binding.zigbee/src/main/java/org/openhab/binding/zigbee/handler/ZigBeeThingHandler.java
Outdated
Show resolved
Hide resolved
...nhab.binding.zigbee/src/main/java/org/openhab/binding/zigbee/handler/ZigBeeThingHandler.java
Outdated
Show resolved
Hide resolved
@TomTravaglino Should the new config parameter also be added to the config description? (Probably as an advanced parameter?) |
Yes. I add it to |
What would be the reason for not adding it to the static thing types? |
Regarding this config parameter - this could get messy. I think that without this in the XML (ie ALL xmls for all things) then there might be problems. Certainly it will not be possible for users to reinitialise their devices. I wonder if it might not be better to instead use a Config Parameter Provider to provide this to all ZigBee thing types rather than require it to be added to all XML files. This might be less error prone? |
...nhab.binding.zigbee/src/main/java/org/openhab/binding/zigbee/handler/ZigBeeThingHandler.java
Show resolved
Hide resolved
@cdjackson |
Yes |
I discussed the ‘Config Parameter Provider’ idea with @triller-telekom and we came to the conclusion that such a solution needs ‘some’ work to be done. In addition, the mac address is currently also defined in the XML. My PR implements that the reportings and cluster bindings are only configured once for each device. Implementing a generic provider for various kinds of thing properties is IMHO out of scope for this PR. Our proposal is to let this PR as it is and create a new issue for the ‘Config Parameter Provider’ solution. WDYT? |
Yes, but it's not much is it? And it makes this PR usable - otherwise this PR leaves hidden dependencies.
I disagree since without this, we end up with a dependency that will probably be forgotten, and will stop devices working. What I'm worried about is if we implement these sort of changes that are only partly working, it's fine for Qivicon where Deutsche Telekom people can manage your system and your thing definitions, but it will likely be left to me to work out the problems with openHAB. I'm happy to move it to another PR if you plan to provide that in the coming couple of weeks, otherwise I would prefer to see it here so that this feature doesn't have hidden dependencies. |
I just discussed this issue with @triller-telekom. First, we see Chris' point that it might cause issues adding this to all static thing types; in particular, if there is someone out there having own static thing types that are not provided by the open source binding, then these would not get the new config parameter. We took a look at what is currently implemented in the From the code perspective, this could look like this in the
WDYT, @cdjackson and @TomTravaglino ? Would this meet both your concerns? |
I considered a very similar approach this morning. But to me it looks like it works for generic devices since you create a new config description. But it was not yet clear to me if you can handle it that way when a static thing type already provides its own config description. I think this approach would overwrite it. Maybe I missed something so I first wanted to discuss it with someone of you. |
The |
Thanks for the input. Then the approach should be fine. |
9c0f012
to
716b95c
Compare
716b95c
to
ee17d78
Compare
I updated the PR |
33dda63
to
6be0c7b
Compare
PR is updated |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have added my comments inline, @TomTravaglino .
@@ -251,6 +252,9 @@ private synchronized void doNodeInitialisation() { | |||
|
|||
List<Channel> nodeChannels; | |||
|
|||
List<ConfigDescriptionParameter> parameters = new ArrayList<ConfigDescriptionParameter>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very small comment (no need to change with this PR, unless you like to): You can use the diamond operator on the right-hand side of the assignment, i.e. new ArrayList<>()
. The compiler can figure out the generic type on its own, and this makes the code somewhat less "heavy".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will change it.
*/ | ||
public class ZigBeeConfigDescriptionParameters { | ||
|
||
private static final String PARAM_ZIGBEE_INITIALISE_DEVICE_NAME = "zigbee_initialise_device"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not use the constant from ZigBeeBindingConstants
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will replace it.
@@ -251,6 +252,9 @@ private synchronized void doNodeInitialisation() { | |||
|
|||
List<Channel> nodeChannels; | |||
|
|||
List<ConfigDescriptionParameter> parameters = new ArrayList<ConfigDescriptionParameter>(); | |||
parameters.addAll(ZigBeeConfigDescriptionParameters.getParameters()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you add those explicitly here, and not put them directly into the array list constructor?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No special reason. But I can change it.
} | ||
} else { | ||
logger.debug( | ||
"{}: Initialization of channel {} with {} will be skipped as the device is already initialized", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This log message sounds wrong, as the channel is still initialized (but only the converter part - just the device initialization part is skipped).
Correct would be something like "Device initialization for channel {} with {} is skipped as the device is already initialized".
IMHO, it would be even better to not log this for every channel, but rather use a single log message stating that device initialization is skipped for all channels (in the case that initializeDevice
is false).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can remove this statement and put this one just before the loop:
if (!initializeDevice) {
logger.debug("{}: Device initialization will be skipped as the device is already initialized",
nodeIeeeAddress);
}
@@ -423,6 +439,12 @@ private synchronized void doNodeInitialisation() { | |||
coordinatorHandler.serializeNetwork(); | |||
} | |||
|
|||
private synchronized void reinitializeDevice() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reading this now, the method name seems wrong. This method reinitializes the thing handler, and not the device. In fact, it will only reinitialize the device if the THING_PROPERTY_DEVICE_INITIALIZED
was set to false
before (which you do in handleConfigurationUpdate
).
I suggest to either rename the method, or set the thing property in here, to fix this issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK. I will move the statement
getThing().setProperty(ZigBeeBindingConstants.THING_PROPERTY_DEVICE_INITIALIZED, Boolean.FALSE.toString());
into this method. I think then it's clear what the method is made for.
@@ -597,6 +624,11 @@ public void handleConfigurationUpdate(Map<String, Object> configurationParameter | |||
|
|||
// Persist changes | |||
updateConfiguration(configuration); | |||
|
|||
if (initializeDevice) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question: What is the difference for you between initializeDevice
and reinitializeDevice
? (If there is none, you could use one of the words both for the variable and the method.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I named the variable initializeDevice
because it is related to the config param zigbee_initialise_device
. The method name is reinitializeDevice
because a re-initialization is what it does when the config param is set to true
.
Do you think it's confusing or not good to understand?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think it's confusing or not good to understand?
I think that it is ok, but not ideal.
private synchronized void reinitializeDevice() { | ||
logger.debug("{}: Reinitializing device", nodeIeeeAddress); | ||
dispose(); | ||
initialize(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems a bit strange - maybe this is also Hennings issue.
This method reinitializeDevice
doesn't reinitialise the device - it reinitialises the thing handler and the device. I would have expected that when the user wants to reinitialise the device, it just does that.
Or, do you think that because we have updated the device, that we also need to reinitialise all the converters? I'm not sure this is the case (I'd need to think it through some more - maybe you've already done that?). The clusters won't change, so I don't think reinitialising the converters and redetecting the channels and polling is really necessary?
I could be wrong though, and maybe a full reinitialisation and repoll etc is really needed, but this wasn't my expectation when I first introduced this concept.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The idea was to re-use the existing methods and so rely on the existing initialization. However, I understand your objection and so I took a closer look at the initialization part. As far as I can see we can initialize the device without the need to re-initialize anything else. I'm implementing a method that initializes only the devices. PR will follow soon.
- Introduced thing property 'zigbee_initialised'. The property will be checked before the channels are initialized and skips the device initialization when it is 'true'. On the first initialization the property will be set to 'true' after the channel initialization. - Introduced class that provides thing config description parameters. - Introduced thing config parameter 'zigbee_initialise_device' in order to allow the user to (re-)initialize the device by updating the config. The config parameter will be checked when the config is updated and executes a device initialization. Signed-off-by: Tommaso Travaglino <[email protected]>
6e3b706
to
a5f3566
Compare
I updated the PR. Now the device can be re-initialized without initializing the thing handler. |
I think Hennings comments have been addressed.
Thanks @TomTravaglino this looks good to me. I'll just let CI re-run after the branch update and then it should be good to merge. |
@cdjackson Pipeline looks successful now, I guess its ready to be merged now. Thanks for reviewing. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Resolves #403
This PR provides a solution that allows the thing handler to skip device initialization if it has been done previously. Furthermore it allows to execute a device (re-)initialization by updating the thing config.
In detail:
checked before the channels are initialized and skips the device
initialization when it is 'true'. On the first initialization the
property will be set to 'true' after the channel initialization.
to allow the user to (re-)initialize the device by updating the
config. The config parameter will be checked when the config is
updated and executes a device initialization by disposing and initializing the thing handler