Skip to content

Commit

Permalink
Merge pull request #109 from florian-h05/fix-createitem-metadata
Browse files Browse the repository at this point in the history
Items: Fix createItem does not set metadata & further improvement
  • Loading branch information
jpg0 authored Apr 23, 2022
2 parents 0c719fb + d418b53 commit 394fb99
Show file tree
Hide file tree
Showing 6 changed files with 380 additions and 194 deletions.
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])
* .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

0 comments on commit 394fb99

Please sign in to comment.