Skip to content

Commit d90d27a

Browse files
authored
[items] Item: Add groupType property to get the type of group (if any) (#476)
Signed-off-by: Florian Hotze <dev@florianhotze.com>
1 parent dc974a9 commit d90d27a

14 files changed

+27
-13
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,7 @@ Calling `getItem(...)` or `...` returns an `Item` object with the following prop
417417
- .persistence ⇒ [`ItemPersistence`](#itempersistence)
418418
- .semantics ⇒ [`ItemSemantics`](https://openhab.github.io/openhab-js/items.ItemSemantics.html)
419419
- .type ⇒ `string`
420+
- .groupType ⇒ `string|null`
420421
- .name ⇒ `string`
421422
- .label ⇒ `string`
422423
- .state ⇒ `string`

src/items/items.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,16 @@ class Item {
112112
return this.rawItem.getType().toString();
113113
}
114114

115+
/**
116+
* Type of the Group, if this Item is a Group and has a type, else `null`.
117+
* @type {string|null}
118+
*/
119+
get groupType () {
120+
if (this.type !== 'Group') return null;
121+
const baseItem = this.rawItem.getBaseItem();
122+
return (baseItem !== null) ? baseItem.getType().toString() : null;
123+
}
124+
115125
/**
116126
* Name of Item
117127
* @type {string}

types/items/itemchannellink.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ export type Item = {
33
persistence: import("./item-persistence");
44
semantics: import("./item-semantics");
55
readonly type: string;
6+
readonly groupType: string;
67
readonly name: string;
78
readonly label: string;
89
readonly state: string;

types/items/itemchannellink.d.ts.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

types/items/items.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,11 @@ export class Item {
213213
* @type {string}
214214
*/
215215
get type(): string;
216+
/**
217+
* Type of the Group, if this Item is a Group and has a type, else `null`.
218+
* @type {string|null}
219+
*/
220+
get groupType(): string;
216221
/**
217222
* Name of Item
218223
* @type {string}

types/items/items.d.ts.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

types/items/metadata.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ export type Item = {
33
persistence: import("./item-persistence");
44
semantics: import("./item-semantics");
55
readonly type: string;
6+
readonly groupType: string;
67
readonly name: string;
78
readonly label: string;
89
readonly state: string;

types/items/metadata.d.ts.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

types/quantity.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ export type Item = {
33
persistence: import("./items/item-persistence");
44
semantics: import("./items/item-semantics");
55
readonly type: string;
6+
readonly groupType: string;
67
readonly name: string;
78
readonly label: string;
89
readonly state: string;

types/quantity.d.ts.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)