-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
140 lines (131 loc) · 6.32 KB
/
index.js
File metadata and controls
140 lines (131 loc) · 6.32 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
'use-strict';
import * as checkSession from './modules/checkSession.js';
import * as createSession from './modules/createSession.js';
import * as destroySession from './modules/destroySession.js';
import * as deviceInfo from './modules/deviceInfo.js';
import * as switchCommand from './modules/switchCommand.js';
/**
* Login request to Fritz!OS with use of PBKDF2 (Requires Fritz!OS 7.24) or MD5 (Requires Fritz!OS 5.50) Challenge-Response Process.
* If the Fritz!OS version does not support PBKDF2 then the function automaticly falls back to MD5.
* @param {Object} credentials - credentials details
* @param {String} credentials.user - the username for the login
* @param {String} credentials.password - the password for the login
* @param {Object} connection - connection details
* @param {String} connection.host - hostname or IP-Address
* @param {String=} [connection.mode=PBKDF2] - Challenge-Response Process; either 'PBKDF2' (default) or 'MD5'
* @param {Boolean} [connection.useSSL=false] - true if SSL connection over https should be used (default is false)
* @param {Boolean} [fullOutput=false] - Get full output as object instead of just the SessionID
* @return {Promise(String | Object)} Response SessionID as String or if fullOutput is true, the full output from rquest as Object
*/
export const doInitSession = function({user, password}, {host, mode='PBKDF2', useSSL=false}, fullOutput=false) {
return createSession.doInitSession({password,
user}, {host,
mode,
useSSL}, fullOutput);
};
/**
* Check if Session is valid
* @async
* @function
* @param {String} sessionId - current session ID
* @param {Object} connection - connection details
* @param {String} connection.host - hostname or IP-Address
* @param {String} [connection.mode='PBKDF2'] - Challenge-Response Process; either 'PBKDF2' (default) or 'MD5'
* @param {Boolean} [connection.useSSL=false] - true if SSL connection over https should be used (default is false)
* @return {Promise<Boolean>} Response if Session is valid
*/
export const isValidSession = function(sessionId, {host, mode='PBKDF2', useSSL=false}) {
return checkSession.isValidSession(sessionId, {host,
mode,
useSSL});
};
/**
* Logout user from the Fritz!OS interface
* @async
* @function
* @param {String} sessionId - current session ID
* @param {Object} connection - connection details
* @param {String} connection.host - hostname or IP-Address
* @param {String} [connection.mode='PBKDF2'] - Challenge-Response Process; either 'PBKDF2' (default) or 'MD5'
* @param {Boolean} [connection.useSSL=false] - true if SSL connection over https should be used (default is false)
* @param {Boolean} [fullOutput=false] - Get full output as object instead of just the SessionID
* @returns {Promise<String | Object>} Response SessionID as String or if fullOutput is true, the full output from rquest as Object
*/
export const doEndSession = function(sessionId, {host, mode='PBKDF2', useSSL=false}, fullOutput=false) {
return destroySession.doEndSession(sessionId, {host,
mode,
useSSL}, fullOutput);
};
/**
* Switches socket on or off
* @async
* @function setSwitchOnOff
* @param {String} sessionId - current session ID
* @param {String} actorId - Identifier of a actor, template (e.g. number) or MAC-Address of a network device
* @param {Boolean} switchOnOff - Turns actor on or off
* @param {Object} connection - connection details
* @param {String} connection.host - hostname or IP-Address
* @param {Boolean} [connection.useSSL=false] - true if SSL connection over https should be used (default is false)
* @return {Promise<Boolean>} Response either true or false, depending on the device state
*/
export const setSwitchOnOff = function(sessionId, actorId, switchOnOff, {host, useSSL=false}) {
return switchCommand.setSwitchOnOff(sessionId, actorId, switchOnOff, {host,
useSSL});
};
/**
* Provides the basics Information from all SmartHome devices
* @async
* @function getDeviceListInfos
* @param {String} sessionId - current session ID
* @param {Object} connection - connection details
* @param {String} connection.host - hostname or IP-Address
* @param {Boolean} [connection.useSSL=false] - true if SSL connection over https should be used (default is false)
* @return {Promise<Object>} Response device list data as Object
*/
export const getDeviceListInfos = function(sessionId, {host, useSSL=false}) {
return deviceInfo.getDeviceListInfos(sessionId, {host,
useSSL});
};
/**
* Returns the basic statistics (temperature, voltage, power, energy) of the actuator
* @async
* @function getBasicDeviceStats
* @param {String} sessionId - current session ID
* @param {String} actorId - Identifier of a actor, template (e.g. number) or MAC-Address of a network device
* @param {Object} connection - connection details
* @param {String} connection.host - hostname or IP-Address
* @param {Boolean} [connection.useSSL=false] - true if SSL connection over https should be used (default is false)
* @return {Promise<Object>} Response device stats data as Object
*/
export const getBasicDeviceStats = function(sessionId, actorId, {host, useSSL=false}) {
return deviceInfo.getBasicDeviceStats(sessionId, actorId, {host,
useSSL});
};
/**
* Provides the basic information of all routines/triggers
* @async
* @function getTriggerListInfos
* @param {String} sessionId - current session ID
* @param {Object} connection - connection details
* @param {String} connection.host - hostname or IP-Address
* @param {Boolean} [connection.useSSL=false] - true if SSL connection over https should be used (default is false)
* @return {Promise<Object>} Response routines/triggers data as Object
*/
export const getTriggerListInfos = function(sessionId, {host, useSSL=false}) {
return deviceInfo.getTriggerListInfos(sessionId, {host,
useSSL});
};
/**
* Provides the basic information of all templates/templates
* @async
* @function getTemplateListInfos
* @param {String} sessionId - current session ID
* @param {Object} connection - connection details
* @param {String} connection.host - hostname or IP-Address
* @param {Boolean} [connection.useSSL=false] - true if SSL connection over https should be used (default is false)
* @return {Promise<Object>} Response templates/templates data as Object
*/
export const getTemplateListInfos = function(sessionId, {host, useSSL=false}) {
return deviceInfo.getTemplateListInfos(sessionId, {host,
useSSL});
};