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

Items: Fix createItem does not set metadata & further improvement #109

Merged
merged 6 commits into from
Apr 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 53 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ This will be used instead of the binding provided version.

### Breaking Changes
- item.history.lastUpdate() returns `ZonedDateTime` instead of `Date`
- `addItem(...)` and `updateItem(...)` use [`itemConfig`](#itemconfig) as parameter

## UI Based Rules

Expand Down Expand Up @@ -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.&lt;Item&gt;</code>
* .getItemsByTag(...tagNames) ⇒ <code>Array.&lt;Item&gt;</code>
* .createItem(itemName, [itemType], [category], [groups], [label], [tags], [giBaseType], [groupFunction], [itemMetadata])
Copy link

Choose a reason for hiding this comment

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

Why removing it?

Copy link
Contributor Author

@florian-h05 florian-h05 Apr 17, 2022

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.

* .addItem(itemName, [itemType], [category], [groups], [label], [tags], [giBaseType], [groupFunction])
* .addItem([itemConfig](#itemconfig))
* .removeItem(itemOrItemName) ⇒ <code>Boolean</code>
* .replaceItem(itemName, [itemType], [category], [groups], [label], [tags], [giBaseType], [groupFunction])
* .replaceItem([itemConfig](#itemconfig))
* .safeItemName(s) ⇒ <code>String</code>

```javascript
Expand Down Expand Up @@ -289,7 +289,56 @@ item.postUpdate("OFF");
console.log("KitchenLight state", item.state)
```

calling `item.history...` returns a ItemHistory object with the following functions:
#### `itemConfig`
Calling `addItem(itemConfig)` or `replaceItem(itemConfig)` requires the `itemConfig` object with the following properties:

* itemConfig : <code>object</code>
* .type ⇒ <code>String</code>
* .name ⇒ <code>String</code>
* .label ⇒ <code>String</code>
* .category (icon) ⇒ <code>String</code>
* .groups ⇒ <code>Array.&lt;String&gt;</code>
* .tags ⇒ <code>Array.&lt;String&gt;</code>
* .channels ⇒ <code>String|Object { channeluid: { config } }</code>
* .metadata ⇒ <code>Object { namespace: value }|Object { namespace: { value: value , config: { config } } }</code>
* .giBaseType ⇒ <code>String</code>
* .groupFunction ⇒ <code>String</code>

Note: `.type` and `.name` are required.

Example:
```javascript
items.replaceItem({
type: 'Switch',
name: 'Hallway_Light',
label: 'Hallway Light',
category: 'light',
groups: ['Hallway', 'Light'],
tags: ['Lightbulb'],
channels: {
'binding:thing:device:hallway#light': {},
'binding:thing:device:livingroom#light': {
profile: 'system:follow'
}
},
metadata: {
expire: '10m,command=OFF',
stateDescription: {
config: {
pattern: '%d%%',
min: 0,
max: 100,
step: 1,
options: '1=Red, 2=Green, 3=Blue'
}
}
}
});
```

See [openhab-js : items](https://openhab.github.io/openhab-js/items.html) for full API documentation.
#### `item.history`
Calling `item.history` returns a ItemHistory object with the following functions:

Note `serviceId` is optional, if omitted, the default persistance service will be used.

Expand Down
20 changes: 0 additions & 20 deletions itemchannellink.js

This file was deleted.

Loading