homey-api 1.10.17 → 3.0.0-rc.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/README.md +1 -1
- package/assets/types/homey-api.d.ts +47 -588
- package/assets/types/homey-api.private.d.ts +47 -648
- package/index.js +1 -1
- package/lib/APIErrorNotFound.js +20 -0
- package/lib/AthomCloudAPI/Homey.js +3 -1
- package/lib/EventEmitter.js +0 -6
- package/lib/HomeyAPI/HomeyAPI.js +49 -5
- package/lib/HomeyAPI/HomeyAPIErrorNotFound.js +21 -0
- package/lib/HomeyAPI/HomeyAPIV2/Manager.js +2 -575
- package/lib/HomeyAPI/HomeyAPIV2/ManagerDevices/Capability.js +20 -0
- package/lib/HomeyAPI/HomeyAPIV2/ManagerDevices/Device.js +18 -0
- package/lib/HomeyAPI/HomeyAPIV2/ManagerDevices.js +20 -3
- package/lib/HomeyAPI/HomeyAPIV2/ManagerDrivers/Driver.js +25 -0
- package/lib/HomeyAPI/HomeyAPIV2/ManagerDrivers.js +29 -0
- package/lib/HomeyAPI/HomeyAPIV2/ManagerFlow/AdvancedFlow.js +17 -0
- package/lib/HomeyAPI/HomeyAPIV2/ManagerFlow/Flow.js +34 -0
- package/lib/HomeyAPI/HomeyAPIV2/ManagerFlow/FlowCardAction.js +25 -0
- package/lib/HomeyAPI/HomeyAPIV2/ManagerFlow/FlowCardCondition.js +25 -0
- package/lib/HomeyAPI/HomeyAPIV2/ManagerFlow/FlowCardTrigger.js +25 -0
- package/lib/HomeyAPI/HomeyAPIV2/ManagerFlow.js +104 -0
- package/lib/HomeyAPI/HomeyAPIV2/ManagerFlowToken/FlowToken.js +24 -0
- package/lib/HomeyAPI/HomeyAPIV2/ManagerFlowToken.js +29 -0
- package/lib/HomeyAPI/HomeyAPIV2/ManagerInsights/Log.js +23 -0
- package/lib/HomeyAPI/HomeyAPIV2/ManagerInsights.js +29 -0
- package/lib/HomeyAPI/HomeyAPIV2.js +12 -716
- package/lib/HomeyAPI/HomeyAPIV3/Item.js +173 -2
- package/lib/HomeyAPI/HomeyAPIV3/Manager.js +531 -3
- package/lib/HomeyAPI/{HomeyAPIV2 → HomeyAPIV3/ManagerApps}/App.js +1 -1
- package/lib/HomeyAPI/{HomeyAPIV2 → HomeyAPIV3}/ManagerApps.js +4 -3
- package/lib/HomeyAPI/HomeyAPIV3/ManagerDevices/Capability.js +9 -0
- package/lib/HomeyAPI/{HomeyAPIV2 → HomeyAPIV3/ManagerDevices}/Device.js +78 -3
- package/lib/HomeyAPI/{HomeyAPIV2 → HomeyAPIV3/ManagerDevices}/DeviceCapability.js +3 -3
- package/lib/HomeyAPI/HomeyAPIV3/ManagerDevices.js +17 -0
- package/lib/HomeyAPI/HomeyAPIV3/ManagerDrivers/Driver.js +9 -0
- package/lib/HomeyAPI/HomeyAPIV3/ManagerDrivers.js +15 -0
- package/lib/HomeyAPI/HomeyAPIV3/ManagerFlow/AdvancedFlow.js +9 -0
- package/lib/HomeyAPI/HomeyAPIV3/ManagerFlow/Flow.js +9 -0
- package/lib/HomeyAPI/HomeyAPIV3/ManagerFlow/FlowCard.js +9 -0
- package/lib/HomeyAPI/HomeyAPIV3/ManagerFlow/FlowCardAction.js +9 -0
- package/lib/HomeyAPI/HomeyAPIV3/ManagerFlow/FlowCardCondition.js +9 -0
- package/lib/HomeyAPI/HomeyAPIV3/ManagerFlow/FlowCardTrigger.js +9 -0
- package/lib/HomeyAPI/HomeyAPIV3/ManagerFlow.js +12 -23
- package/lib/HomeyAPI/HomeyAPIV3/ManagerFlowToken/FlowToken.js +16 -0
- package/lib/HomeyAPI/HomeyAPIV3/ManagerFlowToken.js +15 -0
- package/lib/HomeyAPI/HomeyAPIV3/ManagerInsights/Log.js +9 -0
- package/lib/HomeyAPI/HomeyAPIV3/ManagerInsights.js +15 -0
- package/lib/HomeyAPI/HomeyAPIV3.js +728 -4
- package/lib/HomeyAPI/HomeyAPIV3Cloud.js +1 -1
- package/lib/HomeyAPI/HomeyAPIV3Local.js +1 -1
- package/package.json +1 -1
- package/lib/HomeyAPI/HomeyAPIApp.js +0 -127
- package/lib/HomeyAPI/HomeyAPIV2/Item.js +0 -177
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
const HomeyAPIV3 = require('./HomeyAPIV3');
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
* This class is returned by {@link AthomCloudAPI.Homey#authenticate} for a cloud
|
|
6
|
+
* This class is returned by {@link AthomCloudAPI.Homey#authenticate} for a Homey with `platform: 'cloud'` and `platformVersion: 1`.
|
|
7
7
|
*
|
|
8
8
|
* @class
|
|
9
9
|
* @hideconstructor
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
const HomeyAPIV3 = require('./HomeyAPIV3');
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
* This class is returned by {@link AthomCloudAPI.Homey#authenticate} for a Homey
|
|
6
|
+
* This class is returned by {@link AthomCloudAPI.Homey#authenticate} for a Homey with `platform: 'local'` and `platformVersion: 1`.
|
|
7
7
|
*
|
|
8
8
|
* @class
|
|
9
9
|
* @hideconstructor
|
package/package.json
CHANGED
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const HomeyAPI = require('./HomeyAPI');
|
|
4
|
-
const HomeyAPIV2 = require('./HomeyAPIV2');
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Use this class to utilize Homey Pro's Web API from inside an app.
|
|
8
|
-
*
|
|
9
|
-
* > This class only works on apps using Apps SDK v3 running on Homey Pro.
|
|
10
|
-
*
|
|
11
|
-
* > Make sure your app has the `homey:manager:api` permission.
|
|
12
|
-
*
|
|
13
|
-
* @class
|
|
14
|
-
* @extends HomeyAPIV2
|
|
15
|
-
* @example
|
|
16
|
-
* // app.json
|
|
17
|
-
* {
|
|
18
|
-
* ...
|
|
19
|
-
* "platforms": [ "local" ],
|
|
20
|
-
* "permissions": [ "homey:manager:api" ],
|
|
21
|
-
* }
|
|
22
|
-
*
|
|
23
|
-
* // app.js
|
|
24
|
-
* const Homey = require('homey');
|
|
25
|
-
* const { HomeyAPIApp } = require('homey-api');
|
|
26
|
-
*
|
|
27
|
-
* class MyApp extends Homey.App {
|
|
28
|
-
*
|
|
29
|
-
* async onInit() {
|
|
30
|
-
* const api = new HomeyAPIApp({
|
|
31
|
-
* homey: this.homey,
|
|
32
|
-
* });
|
|
33
|
-
*
|
|
34
|
-
* const devices = await api.devices.getDevices();
|
|
35
|
-
* this.log('Devices:', devices);
|
|
36
|
-
* }
|
|
37
|
-
*
|
|
38
|
-
* }
|
|
39
|
-
*/
|
|
40
|
-
class HomeyAPIApp extends HomeyAPIV2 {
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Possible Discovery Strategies
|
|
44
|
-
* @static
|
|
45
|
-
* @property {object} DISCOVERY_STRATEGIES
|
|
46
|
-
* @property {string} DISCOVERY_STRATEGIES.LOCAL - Local HTTP, e.g. `http://192.168.1.100`.
|
|
47
|
-
*/
|
|
48
|
-
static DISCOVERY_STRATEGIES = {};
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* @param {Object} args
|
|
52
|
-
* @param {Homey} args.homey - The Homey instance of your app, usually `this.homey`.
|
|
53
|
-
* @param {boolean} [args.debug=false] - Enable debug logs.
|
|
54
|
-
*/
|
|
55
|
-
constructor({
|
|
56
|
-
homey,
|
|
57
|
-
debug = false,
|
|
58
|
-
...props
|
|
59
|
-
}) {
|
|
60
|
-
super({
|
|
61
|
-
...props,
|
|
62
|
-
api: null,
|
|
63
|
-
properties: {
|
|
64
|
-
id: 'local',
|
|
65
|
-
softwareVersion: null,
|
|
66
|
-
},
|
|
67
|
-
strategy: [
|
|
68
|
-
HomeyAPI.DISCOVERY_STRATEGIES.LOCAL,
|
|
69
|
-
],
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
Object.defineProperty(this, '__homeySDK', {
|
|
73
|
-
value: homey,
|
|
74
|
-
enumerable: false,
|
|
75
|
-
writable: true,
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
Object.defineProperty(this, '__debugEnabled', {
|
|
79
|
-
value: !!debug,
|
|
80
|
-
enumerable: false,
|
|
81
|
-
writable: true,
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
__debug(...props) {
|
|
86
|
-
if (!this.__debugEnabled) return;
|
|
87
|
-
this.__homeySDK.log('[homey-api]', `[${this.constructor.name}]`, ...props);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
async login() {
|
|
91
|
-
if (!this.__loginPromise) {
|
|
92
|
-
this.__loginPromise = Promise.resolve().then(async () => {
|
|
93
|
-
const token = await this.__homeySDK.api.getOwnerApiToken();
|
|
94
|
-
this.__debug(`Local Token: ${token}`);
|
|
95
|
-
return token;
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
this.__loginPromise
|
|
99
|
-
.then(token => {
|
|
100
|
-
this.__token = token;
|
|
101
|
-
})
|
|
102
|
-
.catch(err => {
|
|
103
|
-
this.__debug('Error Logging In:', err);
|
|
104
|
-
})
|
|
105
|
-
.finally(() => {
|
|
106
|
-
this.__loginPromise = null;
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
return this.__loginPromise;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
async discoverBaseUrl() {
|
|
114
|
-
this.__baseUrl = await this.__homeySDK.api.getLocalUrl();
|
|
115
|
-
this.__strategyId = 'local';
|
|
116
|
-
|
|
117
|
-
this.__debug(`Local URL: ${this.__baseUrl}`);
|
|
118
|
-
|
|
119
|
-
return {
|
|
120
|
-
baseUrl: this.__baseUrl,
|
|
121
|
-
strategyId: this.__strategyId,
|
|
122
|
-
};
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
module.exports = HomeyAPIApp;
|
|
@@ -1,177 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const EventEmitter = require('../../EventEmitter');
|
|
4
|
-
|
|
5
|
-
class Item extends EventEmitter {
|
|
6
|
-
|
|
7
|
-
constructor({
|
|
8
|
-
uri,
|
|
9
|
-
key,
|
|
10
|
-
homey,
|
|
11
|
-
manager,
|
|
12
|
-
properties,
|
|
13
|
-
}) {
|
|
14
|
-
super();
|
|
15
|
-
|
|
16
|
-
// Set Homey
|
|
17
|
-
Object.defineProperty(this, 'homey', {
|
|
18
|
-
value: homey,
|
|
19
|
-
enumerable: false,
|
|
20
|
-
writable: false,
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
// Set Manager
|
|
24
|
-
Object.defineProperty(this, 'manager', {
|
|
25
|
-
value: manager,
|
|
26
|
-
enumerable: false,
|
|
27
|
-
writable: false,
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
// Set Key
|
|
31
|
-
Object.defineProperty(this, '__key', {
|
|
32
|
-
value: key,
|
|
33
|
-
enumerable: false,
|
|
34
|
-
writable: false,
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
// Set URI
|
|
38
|
-
Object.defineProperty(this, '__uri', {
|
|
39
|
-
value: uri,
|
|
40
|
-
enumerable: false,
|
|
41
|
-
writable: true,
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
// Set Connected
|
|
45
|
-
Object.defineProperty(this, '__connected', {
|
|
46
|
-
value: false,
|
|
47
|
-
enumerable: false,
|
|
48
|
-
writable: true,
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
// Set Properties
|
|
52
|
-
for (const [key, value] of Object.entries(properties)) {
|
|
53
|
-
Object.defineProperty(this, key, {
|
|
54
|
-
value,
|
|
55
|
-
enumerable: true,
|
|
56
|
-
writable: true,
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
__debug(...props) {
|
|
62
|
-
this.manager.__debug(`[${this.constructor.name}:${this.__key}]`, ...props);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
__update(properties) {
|
|
66
|
-
for (const [key, value] of Object.entries(properties)) {
|
|
67
|
-
this[key] = value;
|
|
68
|
-
}
|
|
69
|
-
return this;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
async connect() {
|
|
73
|
-
this.__debug('connect');
|
|
74
|
-
|
|
75
|
-
// If disconnecting, await that first
|
|
76
|
-
try {
|
|
77
|
-
// Ensure all microtasks are done first. E.g. if disconnect is called in the same tick as
|
|
78
|
-
// connect. This way the disconnect is always started first so we can await the disconnect
|
|
79
|
-
// promise before we try to connect again.
|
|
80
|
-
await Promise.resolve();
|
|
81
|
-
await this.__disconnectPromise;
|
|
82
|
-
} catch (err) { }
|
|
83
|
-
|
|
84
|
-
this.__connectPromise = Promise.resolve().then(async () => {
|
|
85
|
-
if (!this.io) {
|
|
86
|
-
this.io = this.homey.subscribe(this.__uri, {
|
|
87
|
-
onConnect: () => {
|
|
88
|
-
this.__debug('onConnect');
|
|
89
|
-
this.__connected = true;
|
|
90
|
-
|
|
91
|
-
this.onConnect();
|
|
92
|
-
},
|
|
93
|
-
onDisconnect: () => {
|
|
94
|
-
this.__debug('onDisconnect');
|
|
95
|
-
this.__connected = false;
|
|
96
|
-
|
|
97
|
-
this.onDisconnect();
|
|
98
|
-
},
|
|
99
|
-
onReconnect: () => {
|
|
100
|
-
this.__debug('onDisconnect');
|
|
101
|
-
|
|
102
|
-
this.onReconnect();
|
|
103
|
-
},
|
|
104
|
-
onEvent: (event, data) => {
|
|
105
|
-
this.__debug('onEvent', event, data);
|
|
106
|
-
|
|
107
|
-
this.emit(event, data);
|
|
108
|
-
},
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
await this.io;
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
// Delete the connecting Promise
|
|
116
|
-
this.__connectPromise
|
|
117
|
-
.catch(() => { })
|
|
118
|
-
.finally(() => {
|
|
119
|
-
delete this.__connectPromise;
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
await this.__connectPromise;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
async disconnect() {
|
|
126
|
-
this.__debug('disconnect');
|
|
127
|
-
|
|
128
|
-
// If connecting, await that first
|
|
129
|
-
try {
|
|
130
|
-
await this.__connectPromise;
|
|
131
|
-
} catch (err) { }
|
|
132
|
-
|
|
133
|
-
this.__disconnectPromise = Promise.resolve().then(async () => {
|
|
134
|
-
this.__connected = false;
|
|
135
|
-
|
|
136
|
-
if (this.io) {
|
|
137
|
-
this.io
|
|
138
|
-
.then(io => io.unsubscribe())
|
|
139
|
-
.catch(err => this.__debug('Error Disconnecting:', err));
|
|
140
|
-
}
|
|
141
|
-
});
|
|
142
|
-
|
|
143
|
-
// Delete the disconnecting Promise
|
|
144
|
-
this.__disconnectPromise
|
|
145
|
-
.catch(() => { })
|
|
146
|
-
.finally(() => {
|
|
147
|
-
delete this.__disconnectPromise;
|
|
148
|
-
// Delete this.io so connect can start new connections.
|
|
149
|
-
delete this.io;
|
|
150
|
-
});
|
|
151
|
-
|
|
152
|
-
await this.__disconnectPromise;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
onConnect() {
|
|
156
|
-
// Overload Me
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
onReconnect() {
|
|
160
|
-
// Overload Me
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
onDisconnect() {
|
|
164
|
-
// Overload Me
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
destroy() {
|
|
168
|
-
// Remove all event listeners
|
|
169
|
-
this.removeAllListeners();
|
|
170
|
-
|
|
171
|
-
// Disconnect from Socket.io
|
|
172
|
-
this.disconnect().catch(() => { });
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
module.exports = Item;
|