homey-api 3.18.0 → 3.18.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/HomeyAPI/HomeyAPIV2/ManagerDrivers.js +2 -0
- package/lib/HomeyAPI/HomeyAPIV2/ManagerFlow.js +6 -0
- package/lib/HomeyAPI/HomeyAPIV2/ManagerFlowToken.js +2 -0
- package/lib/HomeyAPI/HomeyAPIV2/ManagerInsights.js +6 -3
- package/lib/HomeyAPI/HomeyAPIV3/Item.js +33 -29
- package/lib/HomeyAPI/HomeyAPIV3/Manager.js +57 -53
- package/lib/HomeyAPI/HomeyAPIV3/ManagerFlow.js +6 -0
- package/package.json +1 -1
|
@@ -15,12 +15,14 @@ class ManagerDrivers extends ManagerDriversV3 {
|
|
|
15
15
|
async getDriver({
|
|
16
16
|
$cache = true,
|
|
17
17
|
id,
|
|
18
|
+
...rest
|
|
18
19
|
}) {
|
|
19
20
|
if ($cache === true && this.__cache['driver'][id]) {
|
|
20
21
|
return this.__cache['driver'][id];
|
|
21
22
|
}
|
|
22
23
|
|
|
23
24
|
return this.__super__getDriver({
|
|
25
|
+
...rest,
|
|
24
26
|
id: id.split(':').reverse()[0],
|
|
25
27
|
uri: id.split(':', 3).join(':'),
|
|
26
28
|
});
|
|
@@ -61,12 +61,14 @@ class ManagerFlow extends ManagerFlowV3 {
|
|
|
61
61
|
async getFlowCardTrigger({
|
|
62
62
|
$cache = true,
|
|
63
63
|
id,
|
|
64
|
+
...rest
|
|
64
65
|
}) {
|
|
65
66
|
if ($cache === true && this.__cache['flowcardtrigger'][id]) {
|
|
66
67
|
return this.__cache['flowcardtrigger'][id];
|
|
67
68
|
}
|
|
68
69
|
|
|
69
70
|
return this.__super__getFlowCardTrigger({
|
|
71
|
+
...rest,
|
|
70
72
|
id: id.split(':').slice(3).join(':'),
|
|
71
73
|
uri: id.split(':', 3).join(':'),
|
|
72
74
|
});
|
|
@@ -75,12 +77,14 @@ class ManagerFlow extends ManagerFlowV3 {
|
|
|
75
77
|
async getFlowCardCondition({
|
|
76
78
|
$cache = true,
|
|
77
79
|
id,
|
|
80
|
+
...rest
|
|
78
81
|
}) {
|
|
79
82
|
if ($cache === true && this.__cache['flowcardcondition'][id]) {
|
|
80
83
|
return this.__cache['flowcardcondition'][id];
|
|
81
84
|
}
|
|
82
85
|
|
|
83
86
|
return this.__super__getFlowCardCondition({
|
|
87
|
+
...rest,
|
|
84
88
|
id: id.split(':').slice(3).join(':'),
|
|
85
89
|
uri: id.split(':', 3).join(':'),
|
|
86
90
|
});
|
|
@@ -100,12 +104,14 @@ class ManagerFlow extends ManagerFlowV3 {
|
|
|
100
104
|
async getFlowCardAction({
|
|
101
105
|
$cache = true,
|
|
102
106
|
id,
|
|
107
|
+
...rest
|
|
103
108
|
}) {
|
|
104
109
|
if ($cache === true && this.__cache['flowcardaction'][id]) {
|
|
105
110
|
return this.__cache['flowcardaction'][id];
|
|
106
111
|
}
|
|
107
112
|
|
|
108
113
|
return this.__super__getFlowCardAction({
|
|
114
|
+
...rest,
|
|
109
115
|
id: id.split(':').slice(3).join(':'),
|
|
110
116
|
uri: id.split(':', 3).join(':'),
|
|
111
117
|
});
|
|
@@ -13,12 +13,14 @@ class ManagerFlowToken extends ManagerFlowTokenV3 {
|
|
|
13
13
|
async getFlowToken({
|
|
14
14
|
$cache = true,
|
|
15
15
|
id,
|
|
16
|
+
...rest
|
|
16
17
|
}) {
|
|
17
18
|
if ($cache === true && this.__cache['flowtoken'][id]) {
|
|
18
19
|
return this.__cache['flowtoken'][id];
|
|
19
20
|
}
|
|
20
21
|
|
|
21
22
|
return this.__super__getFlowToken({
|
|
23
|
+
...rest,
|
|
22
24
|
id: id.split(':').reverse()[0],
|
|
23
25
|
uri: id.split(':', 3).join(':'),
|
|
24
26
|
});
|
|
@@ -9,19 +9,21 @@ class ManagerInsights extends ManagerInsightsV3 {
|
|
|
9
9
|
Log,
|
|
10
10
|
};
|
|
11
11
|
|
|
12
|
-
async getLog({ $cache = true, id }) {
|
|
12
|
+
async getLog({ $cache = true, id, ...rest }) {
|
|
13
13
|
if ($cache === true && this.__cache['log'][id]) {
|
|
14
14
|
return this.__cache['log'][id];
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
return this.__super__getLog({
|
|
18
|
+
...rest,
|
|
18
19
|
id: id.split(':').reverse()[0],
|
|
19
20
|
uri: id.split(':', 3).join(':'),
|
|
20
21
|
});
|
|
21
22
|
}
|
|
22
23
|
|
|
23
|
-
async getLogEntries({ id, resolution }) {
|
|
24
|
+
async getLogEntries({ id, resolution, ...rest }) {
|
|
24
25
|
const result = await this.__super__getLogEntries({
|
|
26
|
+
...rest,
|
|
25
27
|
id: id.split(':').reverse()[0],
|
|
26
28
|
uri: id.split(':', 3).join(':'),
|
|
27
29
|
resolution,
|
|
@@ -33,8 +35,9 @@ class ManagerInsights extends ManagerInsightsV3 {
|
|
|
33
35
|
};
|
|
34
36
|
}
|
|
35
37
|
|
|
36
|
-
async deleteLogEntries({ id }) {
|
|
38
|
+
async deleteLogEntries({ id, ...rest }) {
|
|
37
39
|
return this.__super__deleteLogEntries({
|
|
40
|
+
...rest,
|
|
38
41
|
id: id.split(':').reverse()[0],
|
|
39
42
|
uri: id.split(':', 3).join(':'),
|
|
40
43
|
});
|
|
@@ -62,35 +62,39 @@ class Item extends EventEmitter {
|
|
|
62
62
|
writable: true,
|
|
63
63
|
});
|
|
64
64
|
|
|
65
|
-
this
|
|
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
|
-
|
|
65
|
+
Object.defineProperty(this, '__realtimeConsumer', {
|
|
66
|
+
value: new RealtimeConsumer({
|
|
67
|
+
subscribe: (uri, handlers) => this.homey.subscribe(uri, handlers),
|
|
68
|
+
getUri: () => this.uri,
|
|
69
|
+
debug: (...props) => this.__debug(...props),
|
|
70
|
+
setConnected: (connected) => {
|
|
71
|
+
this.__connected = connected;
|
|
72
|
+
},
|
|
73
|
+
onConnect: () => {
|
|
74
|
+
this.onConnect();
|
|
75
|
+
},
|
|
76
|
+
onDisconnect: () => {
|
|
77
|
+
this.onDisconnect();
|
|
78
|
+
},
|
|
79
|
+
onReconnect: () => {
|
|
80
|
+
this.onReconnect();
|
|
81
|
+
},
|
|
82
|
+
onEvent: (event, data) => {
|
|
83
|
+
if (event === 'update') {
|
|
84
|
+
this.__update(this.constructor.transformGet({ ...data }));
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
if (event === 'delete') {
|
|
89
|
+
this.__delete();
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
this.emit(event, data);
|
|
94
|
+
},
|
|
95
|
+
}),
|
|
96
|
+
enumerable: false,
|
|
97
|
+
writable: false,
|
|
94
98
|
});
|
|
95
99
|
|
|
96
100
|
// Set Properties
|
|
@@ -87,69 +87,73 @@ class Manager extends EventEmitter {
|
|
|
87
87
|
writable: false,
|
|
88
88
|
});
|
|
89
89
|
|
|
90
|
-
this
|
|
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
|
-
this.emit(event, item);
|
|
117
|
-
return;
|
|
118
|
-
}
|
|
119
|
-
case 'update': {
|
|
120
|
-
const props = ItemClass.transformGet(data);
|
|
90
|
+
Object.defineProperty(this, '__realtimeConsumer', {
|
|
91
|
+
value: new RealtimeConsumer({
|
|
92
|
+
subscribe: (uri, handlers) => this.homey.subscribe(uri, handlers),
|
|
93
|
+
getUri: () => this.uri,
|
|
94
|
+
debug: (...props) => this.__debug(...props),
|
|
95
|
+
setConnected: (connected) => {
|
|
96
|
+
this.__connected = connected;
|
|
97
|
+
},
|
|
98
|
+
onEvent: (event, data) => {
|
|
99
|
+
// Transform & add to cache if this is a CRUD event
|
|
100
|
+
if (event.endsWith('.create') || event.endsWith('.update') || event.endsWith('.delete')) {
|
|
101
|
+
const [itemId, operation] = event.split('.');
|
|
102
|
+
const itemName = this.itemNames[itemId];
|
|
103
|
+
const ItemClass = this.itemClasses[itemName];
|
|
104
|
+
|
|
105
|
+
switch (operation) {
|
|
106
|
+
case 'create': {
|
|
107
|
+
const props = ItemClass.transformGet(data);
|
|
108
|
+
|
|
109
|
+
const item = new ItemClass({
|
|
110
|
+
id: props.id,
|
|
111
|
+
homey: this.homey,
|
|
112
|
+
manager: this,
|
|
113
|
+
properties: props,
|
|
114
|
+
});
|
|
115
|
+
this.__cache[ItemClass.ID][props.id] = item;
|
|
121
116
|
|
|
122
|
-
if (this.__cache[ItemClass.ID][props.id]) {
|
|
123
|
-
const item = this.__cache[ItemClass.ID][props.id];
|
|
124
|
-
item.__update(props);
|
|
125
117
|
this.emit(event, item);
|
|
126
118
|
return;
|
|
127
119
|
}
|
|
120
|
+
case 'update': {
|
|
121
|
+
const props = ItemClass.transformGet(data);
|
|
122
|
+
|
|
123
|
+
if (this.__cache[ItemClass.ID][props.id]) {
|
|
124
|
+
const item = this.__cache[ItemClass.ID][props.id];
|
|
125
|
+
item.__update(props);
|
|
126
|
+
this.emit(event, item);
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
128
129
|
|
|
129
|
-
|
|
130
|
-
}
|
|
131
|
-
case 'delete': {
|
|
132
|
-
const props = ItemClass.transformGet(data);
|
|
133
|
-
|
|
134
|
-
if (this.__cache[ItemClass.ID][props.id]) {
|
|
135
|
-
const item = this.__cache[ItemClass.ID][props.id];
|
|
136
|
-
item.__delete();
|
|
137
|
-
delete this.__cache[ItemClass.ID][item.id];
|
|
138
|
-
this.emit(event, {
|
|
139
|
-
id: item.id,
|
|
140
|
-
});
|
|
141
|
-
return;
|
|
130
|
+
break;
|
|
142
131
|
}
|
|
132
|
+
case 'delete': {
|
|
133
|
+
const props = ItemClass.transformGet(data);
|
|
134
|
+
|
|
135
|
+
if (this.__cache[ItemClass.ID][props.id]) {
|
|
136
|
+
const item = this.__cache[ItemClass.ID][props.id];
|
|
137
|
+
item.__delete();
|
|
138
|
+
delete this.__cache[ItemClass.ID][item.id];
|
|
139
|
+
this.emit(event, {
|
|
140
|
+
id: item.id,
|
|
141
|
+
});
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
143
144
|
|
|
144
|
-
|
|
145
|
+
break;
|
|
146
|
+
}
|
|
147
|
+
default:
|
|
148
|
+
break;
|
|
145
149
|
}
|
|
146
|
-
default:
|
|
147
|
-
break;
|
|
148
150
|
}
|
|
149
|
-
}
|
|
150
151
|
|
|
151
|
-
|
|
152
|
-
|
|
152
|
+
this.emit(event, data);
|
|
153
|
+
},
|
|
154
|
+
}),
|
|
155
|
+
enumerable: false,
|
|
156
|
+
writable: false,
|
|
153
157
|
});
|
|
154
158
|
|
|
155
159
|
// Create methods
|
|
@@ -21,12 +21,14 @@ class ManagerFlow extends Manager {
|
|
|
21
21
|
async getFlowCardTrigger({
|
|
22
22
|
$cache = true,
|
|
23
23
|
id,
|
|
24
|
+
...rest
|
|
24
25
|
}) {
|
|
25
26
|
if ($cache === true && this.__cache['flowcardtrigger'][id]) {
|
|
26
27
|
return this.__cache['flowcardtrigger'][id];
|
|
27
28
|
}
|
|
28
29
|
|
|
29
30
|
return this.__super__getFlowCardTrigger({
|
|
31
|
+
...rest,
|
|
30
32
|
id: id,
|
|
31
33
|
uri: id.split(':', 3).join(':'),
|
|
32
34
|
});
|
|
@@ -35,12 +37,14 @@ class ManagerFlow extends Manager {
|
|
|
35
37
|
async getFlowCardCondition({
|
|
36
38
|
$cache = true,
|
|
37
39
|
id,
|
|
40
|
+
...rest
|
|
38
41
|
}) {
|
|
39
42
|
if ($cache === true && this.__cache['flowcardcondition'][id]) {
|
|
40
43
|
return this.__cache['flowcardcondition'][id];
|
|
41
44
|
}
|
|
42
45
|
|
|
43
46
|
return this.__super__getFlowCardCondition({
|
|
47
|
+
...rest,
|
|
44
48
|
id: id,
|
|
45
49
|
uri: id.split(':', 3).join(':'),
|
|
46
50
|
});
|
|
@@ -60,12 +64,14 @@ class ManagerFlow extends Manager {
|
|
|
60
64
|
async getFlowCardAction({
|
|
61
65
|
$cache = true,
|
|
62
66
|
id,
|
|
67
|
+
...rest
|
|
63
68
|
}) {
|
|
64
69
|
if ($cache === true && this.__cache['flowcardaction'][id]) {
|
|
65
70
|
return this.__cache['flowcardaction'][id];
|
|
66
71
|
}
|
|
67
72
|
|
|
68
73
|
return this.__super__getFlowCardAction({
|
|
74
|
+
...rest,
|
|
69
75
|
id: id,
|
|
70
76
|
uri: id.split(':', 3).join(':'),
|
|
71
77
|
});
|