-
-
Notifications
You must be signed in to change notification settings - Fork 243
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
Saving thing channel configuration results in Thing reinitialisation #2882
Comments
This seems related to #2704 - at least it seems similar so maybe the same issue exists for the channel configuration. |
@ghys I'm wondering if you might be able to provide a couple of pointers here... I'm trying to work through this issue as it completely prevents channel config being saved. I can probably change the logic in the thing save code to detect if the channel is updated, and just update that (similar to the change that was done recently for #2704). However, I'm not completely sure why the PUT is being sent when clicking the DONE button when editing the channel - as I understand the code (and my understanding is not great here so maybe I'm wrong!) the concept is that the user can edit the channel configuration, they click DONE to go back to the Thing config page, and nothing is actually saved until you click the SAVE button on the Thing Edit page? If that's the concept, then I'm trying to work out why there is a PUT sent to save the whole Thing when clicking DONE on the channel edit page. If I've followed the code correctly, the channel edit is in
This doesn't seem to explicitly send the PUT, so I guess some other code elsewhere is picking this up - do you have any pointers as to where to look? If we can prevent the PUT being called here, then I'll take a look at the SAVE logic which I think should be (relatively!) straight forward. Thanks |
@cdjackson it's been a while so I had to wrap my head around this again, but I do remember it was indeed quite the can of worms... I had to search As you see it's pretty similar in With that mind, when you change the channel list itself and not merely their configuration, then it was indeed better/simpler to just save the Thing when you're done making changes in order to:
When you click on the "Configure Channel" link in the list it runs this code: openhab-webui/bundles/org.openhab.ui/web/src/components/thing/channel-link.vue Lines 145 to 170 in ed54bf6
As you see it registers a callback on "pageAfterOut" which checks whether there is a "finalChannel", and then performs both the in-place editing of the channels (not immediately sure why though because we're saving & reloading the Thing anyways) but also emits an event "channel-updated" which should be caught here: openhab-webui/bundles/org.openhab.ui/web/src/pages/settings/things/thing-details.vue Lines 729 to 732 in ed54bf6
So that boolean parameter is whether or not we'll save the Thing (the whole Thing, with this.save(saveThing: true) which does the PUT /rest/thing even when unnecessary).
Now to answer this issue, as said above the Hope this helps and makes sense! |
Thanks for the info @ghys - I'll take a further look at this over the coming days and see if I can come up with some improved logic that allows the config to be saved independently. |
I'll add to this - maybe one solution for this scenario is to simply mark the thing "dirty"and make sure it's saved there, just before navigating away. Some of this code is from 1999 (added here with the first commit in January 2000) and this "dirty" flag didn't exist then. |
@ghys I wanted to clarify a point or two before I create a PR...
Currently, the UI appears to allow the label and description to be edited - are you saying that either the core, or elsewhere in the UI this data is ultimately not saved? If so, I guess the UI should make these read-only?
I'm not sure I understand this point... Why mark the thing "dirty"? We don't want to save the thing - only the channel config. If we mark the thing dirty, then I guess we save the whole thing later. I've spent a bit of time tonight making sure I understand how this works. What I think is an easy solution is in I think this achieves is correct - the channel config is saved independently of the thing and I think it shouldn't mess with saving the thing itself. The only concern I think I have is around the saving of the channel label and description which as above is currently editable. If these don't need to be saved, then I think this works and I'm happy to provide a PR tomorrow. |
🤦 you're right. I won't lose any sleep if we decide we can't edit those after the channel is created, if it helps. You can always remove the channel and create it again.
What I meant is something like: Create a thing > Create a channel > Configure the channel & add it > Thing is actually saved > Link item(s) would become: Create a thing > Create a channel > Configure the channel & add it > Thing is NOT actually saved but is marked "dirty" > Try to link item(s) > You are offered the option to save the Thing to continue or cancel and stay on the Thing page |
Ok, I think we're talking about slightly different use cases...
In this case, we start with This configuration is on the channel, so the user goes to the existing channel and clicks on the config channel link, then makes the change, and clicks For me this makes sense in my use case - I guess the question is what happens in your use case. I think it still works as I think the use case you mention where everything is done at once. One other point - it's also possible (and useful) to configure channels that are not linked to an item. In your cases above you talk about "Create a channel" and "Configure the channel and add it" - in my understanding, the user can't add a channel can they? They can only link an item to a channel? Or is there another mechanism used by bindings for dynamic channel creation that I'm not familiar with? I can't see any way to add a channel in the UI so maybe you mean "create a link to an item"? As per the start of this paragraph, we can configure channels that are not linked to items, since the channel is what is being configured, and that is not dependant on the item... (I hope that all makes sense!). |
Yes they can, for these "editable" thing types - the ones I know of are from the MQTT and HTTP bindings, maybe there's more. The issue is that when you add, edit, or remove channels from those things, you modify the Thing itself - hence the HTTP request to save it - not only the channel configuration. And What I proposed was:
|
We could (presumably) save the channel and it's configuration, mark it dirty, and then in the "Save Thing" logic, detect that only the channel configuration had changed, and just make the call to save this. I think this is what you're suggesting? I did have a look at that, and I'm sure it's possible, but it's more complicated. As you've already pointed out elsewhere I think, this is a bit messy as there are so many different calls for saving different parts of the thing - the big problem with saving the whole thing is that it causes the thing handler to be reinitialised which actually means that the config callbacks never get called when the config is updated. IIRC when I looked at that option, the problem was that the code that saves the thing doesn't have access to the original channel config - that's only available in the channel edit code which is why I proposed to save the channel config there. Otherwise, in the "Save Thing" handler, we somehow need to differentiate between saving the channel (and hence the thing) or saving the channel config and at the moment we are returning the
I think this is in line with what I suggested - ie to make the name/description fields non-editable, and to save the configuration in |
The problem
Bottom line: Thing channel configuration doesn't work and can't be used to get config channel updated to bindings.
If a Thing channel has configuration, when the config is saved, it does a PUT to save the complete thing rather than just updating the channel config. The channel config is updated as part of this, but now the thing is reinitialised rather than just updating the channel configuration.
It also seems that the PUT request to save the Thing is sent even when no configuration update to the channel is made - ie go to the Channel Details for a channel with config, then clock Done and we get the same PUT request that causes the thing to reinitialise. In this case (ie with no actual config change) when moving away from the Thing page, we don't get the error that the thing has changed.
One issue with this is because the thing is reinitialised, this can make it difficult to manage battery devices in zigbee since they need to be woken up when the channel config is updated. If the thing gets reinitialised, then firstly this configuration may not be transferred to the device, or if the binding does try and transfer it, the device may have gone to sleep since the user has no real way to know when this is happening as it's delayed from the point at which they save the UI data.
Expected behavior
The config for the channel should be updated separately, and at the time the user clicks Save/Done, and should only be updated if the channel configuration is changed. The thing shouldn't reinitialise.
Steps to reproduce
Your environment
Browser console
Browser network traffic
Additional information
The text was updated successfully, but these errors were encountered: