-
-
Notifications
You must be signed in to change notification settings - Fork 86
/
Copy pathdefault.js
117 lines (107 loc) · 2.7 KB
/
default.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/* eslint-disable no-unused-vars */
const packageVersion = require('../package.json').version;
class DefaultDevice {
static get type() {
return '';
}
/**
* @param {object} item
*/
static getTraits(item) {
return [];
}
static get requiredItemTypes() {
return [];
}
/**
* @param {object} item
*/
static isCompatible(item) {
return (
item.metadata &&
item.metadata.ga &&
this.type.toLowerCase() === `action.devices.types.${item.metadata.ga.value}`.toLowerCase()
);
}
/**
* @param {object} item
*/
static matchesItemType(item) {
return (
!this.requiredItemTypes.length ||
this.requiredItemTypes.includes((item.groupType || item.type || '').split(':')[0])
);
}
/**
* @param {object} item
*/
static getAttributes(item) {
return {};
}
/**
* @param {object} item
*/
static getConfig(item) {
return (item && item.metadata && item.metadata.ga && item.metadata.ga.config) || {};
}
/**
* @param {object} item
*/
static getMetadata(item) {
const config = this.getConfig(item);
const itemType = item.groupType || item.type;
const deviceName = config.name || item.label || item.name;
const metadata = {
id: item.name,
type: this.type,
traits: this.getTraits(item),
name: {
name: deviceName,
defaultNames: [deviceName],
nicknames: [
deviceName,
...(item.metadata && item.metadata.synonyms
? item.metadata.synonyms.value.split(',').map((s) => s.trim())
: [])
]
},
willReportState: false,
roomHint: config.roomHint,
structureHint: config.structureHint,
deviceInfo: {
manufacturer: 'openHAB',
model: `${itemType}:${item.name}`,
hwVersion: '3.0.0',
swVersion: packageVersion
},
attributes: this.getAttributes(item),
customData: {
deviceType: this.name,
itemType: itemType
}
};
if (config.inverted === true) {
metadata.customData.inverted = true;
}
if (config.ackNeeded === true || config.tfaAck === true) {
metadata.customData.ackNeeded = true;
}
if (typeof config.pinNeeded === 'string' || typeof config.tfaPin === 'string') {
metadata.customData.pinNeeded = config.pinNeeded || config.tfaPin;
if (config.pinOnDisarmOnly === true) {
metadata.customData.pinOnDisarmOnly = true;
}
}
if (config.waitForStateChange) {
metadata.customData.waitForStateChange = parseInt(config.waitForStateChange);
}
return metadata;
}
/**
* @param {object} item
*/
static getState(item) {
return {};
}
}
module.exports = DefaultDevice;