-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathapi.js
More file actions
142 lines (139 loc) · 2.93 KB
/
Copy pathapi.js
File metadata and controls
142 lines (139 loc) · 2.93 KB
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/* jslint node: true */
'use strict';
module.exports = {
async getLog({ homey, query })
{
return homey.app.diagLog;
},
async getLogFilterOptions({ homey, query })
{
return homey.app.getLogFilterOptions();
},
async getDetect({ homey, query })
{
try
{
homey.app.detectedDevices = homey.app.varToString(await homey.app.getHUBDevices());
}
catch (err)
{
if (!homey.app.detectedDevices)
{
homey.app.detectedDevices = err.message;
}
}
return homey.app.detectedDevices;
},
async getBLEStatistics({ homey, query })
{
return homey.app.getBLEStatistics();
},
async clearBLEStatistics({ homey, query })
{
homey.app.clearBLEStatistics(true);
return 'OK';
},
async getDetectedBLEDevices({ homey, query })
{
if (homey.app.isBLEInitialising())
{
return { initialising: true, devices: [] };
}
return { initialising: false, devices: await homey.app.getDetectedBLEDevices() };
},
async getAllDetectedBLEDevices({ homey, query })
{
return homey.app.getAllDetectedBLEDevices();
},
async getBLEAdvertisementSettings({ homey, query })
{
return homey.app.getBLEAdvertisementSettings();
},
async clearAllDetectedBLEDevices({ homey, query })
{
homey.app.clearAllDetectedBLEDevices();
return 'OK';
},
async GetDriverSupportMatrix({ homey, body })
{
return homey.app.getDriverSupportMatrix((body && body.mode) || 'hub');
},
async SendUnsupportedDevices({ homey, body })
{
return homey.app.sendUnsupportedDevices(body && body.unsupportedDevices);
},
async clearLog({ homey, query })
{
homey.app.diagLog = '';
return 'OK';
},
async SendDeviceLog({ homey, query })
{
return homey.app.sendLog('deviceLog');
},
async SendInfoLog({ homey, query })
{
return homey.app.sendLog('infoLog');
},
async SendStatusLog({ homey, query })
{
return homey.app.sendLog('statusLog');
},
async clearStatusLog({ homey, query })
{
homey.app.deviceStatusLog = '';
return 'OK';
},
async newData({ homey, body })
{
if (homey.app.BLEHub)
{
homey.app.BLEHub.newBLEHubData(body);
}
return 'OK';
},
async requestDeviceStatus({ homey, query })
{
const retval = await homey.app.getDeviceStatus(query.deviceId);
const data = JSON.stringify(retval, null, 2);
homey.app.deviceStatusLog += data;
return homey.app.deviceStatusLog;
},
async checkOAuthStatus({ homey, query })
{
try
{
const savedSessions = homey.app.getSavedOAuth2Sessions();
// getSavedOAuth2Sessions returns an object of sessions by sessionId
const hasSession = savedSessions && Object.keys(savedSessions).length > 0;
return {
hasOAuthSession: hasSession,
};
}
catch (err)
{
return {
hasOAuthSession: false,
};
}
},
async startOAuth2Flow({ homey, query })
{
try
{
const { authUrl, flowId } = await homey.app.startSettingsOAuthLogin();
return {
authUrl,
flowId,
success: true,
};
}
catch (err)
{
return {
success: false,
error: err.message,
};
}
},
};