-
-
Notifications
You must be signed in to change notification settings - Fork 31
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
Items: Fix createItem does not set metadata & further improvement #109
Conversation
Fixes openhab#108. Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
And `addItem` & `replaceItem` as they use `createItem` under the hood. Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
Use them in `items/managed.js` for `addItem`. Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
Adapt to breaking changes from 2a2b18c. Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
REMINDER: After this PR gets merged, update https://github.com/openhab/openhab-webui/blob/main/bundles/org.openhab.ui/web/src/assets/openhab-js-tern-defs.json#L156 for the breaking changes. |
Looks good :) Is it also possible to set configurations in metadata like the following use case?
|
Currently this is not possible, but I am working on a solution for this now |
Got it working now, you should try the following code snippet: var stateDescription = new Map()
.set('pattern', '%d%%')
.set('min', '0')
.set('max', '100')
.set('step', '1')
.set('options', '1=Red, 2=Green, 3=Blue');
var metadata = new Map();
metadata.set('stateDescription', ['', stateDescription]);
items.replaceItem({
type: 'Number',
name: 'nTest',
label: 'Test Number Item',
metadata: metadata
}); @janwo |
@florian-h05 is it possible to use object notion too, such as: items.replaceItem({
type: 'Number',
name: 'nTest',
label: 'Test Number Item',
metadata: {
stateDescription: {
pattern: '%d%%',
min: 0,
max: 100,
step: 1,
options: '1=Red, 2=Green, 3=Blue' //even this could be an object
}
}
}); I would think this to be more idiomatic JS. |
@jpg0 Currently not, I was also thinking about that way. Should I change it to use that way? |
Personally I prefer the object notation style, and that is already how the primary config object is created, so I'd say yes, change it. (You can most likely code it so that both work, if you want to.) |
Okay, then I will change it to the object notation style. |
211ce05
to
e39ef52
Compare
@jpg0 Finished it, ready for review and merging. You have to modify your code snippet a little bit: items.replaceItem({
type: 'Number',
name: 'nTest',
label: 'Test Number Item',
metadata: {
stateDescription: {
config: { // need to wrap configuration in extra object, because e.g. for expire you may use value & config
// those key:value pairs are translated to Map because Java Metadata() requires Map
pattern: '%d%%',
min: 0,
max: 100,
step: 1,
options: '1=Red, 2=Green, 3=Blue' // I have not tested if this could be an object, but I do not see any reason why it should not
}
}
}
}); |
Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
e39ef52
to
d418b53
Compare
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.
Looks good to me :)
@@ -242,10 +243,9 @@ See [openhab-js : items](https://openhab.github.io/openhab-js/items.html) for fu | |||
* .getItem(name, nullIfMissing) ⇒ <code>Item</code> | |||
* .getItems() ⇒ <code>Array.<Item></code> | |||
* .getItemsByTag(...tagNames) ⇒ <code>Array.<Item></code> | |||
* .createItem(itemName, [itemType], [category], [groups], [label], [tags], [giBaseType], [groupFunction], [itemMetadata]) |
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 removing it?
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 function only creates an Item object but does not create a new Item in openHAB.
I think there is no case where normal scripters should have a use for that and like in the linked issue, createItem
only confuses.
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
@florian-h05 FYI the Saying this, I have no problem with you removing the |
@jpg0 Thank you for that explanation.
Okay, in fact I do not remove it (it is used by addItem), I just removed it from the docs. |
@jpg0 |
This looks great! How long until it gets into the officially released jsscripting binding? I'm trying to decide whether I should just wait for that or install it manually from the main branch. |
I think that the next version of JS Scripting and this library will be released together with openHAB 3.3.0 Stable this summer, so I would recommend installing from GitHub with: |
I think its probably worthwhile to push a openhab-JS release to NPM, and update the binding with the new version so milestone and nightlies get our updated changes |
This adds two warnings for two breaking changes from the openhab-js library included in the JS Scripting Automation Add-On: * openhab/openhab-js#67 * openhab/openhab-js#109 Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
This adds two warnings for two breaking changes from the openhab-js library included in the JS Scripting Automation Add-On: * openhab/openhab-js#67 * openhab/openhab-js#109 Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
This updates `addItem(...)` and `updateItem(...)` for the breaking changes from openhab/openhab-js#109. Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
This updates `addItem(...)` and `updateItem(...)` for the breaking changes from openhab/openhab-js#109. Signed-off-by: Florian Hotze <florianh_dev@icloud.com> Also-by: Yannick Schaus <github@schaus.net>
Items: Fix
createItem
does not set metadata & improvements with Item configuration & feature additionDescription
addItem
&replaceItem
as this provides more flexibiliy and clarity.addItem
&replaceItem
.Breaking Changes
addItem
&replaceItem
now use theitemConfig
object.Add a note to https://github.com/openhab/openhab-distro/blob/main/distributions/openhab/src/main/resources/bin/update.lst.
Update https://github.com/openhab/openhab-webui/blob/main/bundles/org.openhab.ui/web/src/assets/openhab-js-tern-defs.json for code-completion in WebUI.
Testing
From the README: