-
-
Notifications
You must be signed in to change notification settings - Fork 429
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
getThing('someThing').setLabel('aLabel') does not persist after a restart #3648
Comments
This is not a bug. Changing things requires updating the thing in the registry, not modifying the thing instance itself. |
If it's not a bug how do I make it persist? What would be the point of it not sticking? The docs don't describe this. |
You need to get the thing registry and call "update" with the updated thing as parameter. |
Like this??? |
You're by passing common usage - reaching dev side |
What would be the common usage of renaming a label that doesn't persist? Could you just tell me how to do this? |
Changing the name of a Thing from a rule is not something that would be common to do from a Rule. The names of Things tend to be static and manually set to something meaningful. There really is no need to change it dynamically from a rule. That's what @clinique means. It's an odd request and smells greatly of an XY Problem. And the how is outlined above by @J-N-K. You don't mention which JavaScript you are using which could change the answer some. In both cases For Nashorn JS see https://www.openhab.org/javadoc/latest/org/openhab/core/thing/thingregistry or the actual code at openhab-core/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/ThingRegistry.java Line 35 in be74889
For GraalVM JS Scripting it doesn't look like direct access to the ThingRegistry's
Note this will overwrite the helper library |
Let say it differently: you're diving -at the surface - of OH Core guts. Don't expect this to be fully user documented as it is not the intended audience. |
There are other ways to handle that use case including the karaf console, REST API, text based .things files, etc. Rules in general are not really intended to be
I suspect that they are there for completeness. You can open an issue on openhab-js to change the implementation of those methods so that the changes get preserved in the registry or remove the methods. I'm surprised to even see they exist in the helper library in the first place. It was probably a case of "while I'm here I may as well be complete" and ultimately it wasn't implemented correctly.
Sure, but that doesn't mean we are obligated to document each and every possible thing that could be done in rules, especially for things that are considered outside the scope of what rules are intended to do. And there isn't a complete lack of documentation. It's there in the javadocs and the code, which is where the intended audience for these methods would find them. But over all, it's not resistance to what you are doing. It's resistance to the expectation that we would necessarily cover it in the end user docs. |
Feel free to open an issue so I have a reminder to fix this once I have the time.
I added this in openhab/openhab-js#132, and IIRC it was like you described: If I’m here … |
Expected Behavior
When a rule or script runs the command
getThing('someThing').setLabel('aLabel')
The label of the Thing should change as expected, and when openhab restarts the Thing should still have this new label
Current Behavior
When openhab is restarted, the label returns to whatever it was set to previously.
Possible Solution
Steps to Reproduce (for Bugs)
getThing('UIDOfThing').setLabel('newLabel')
Context
Your Environment
The text was updated successfully, but these errors were encountered: