forked from TanguyNa/gladys-lgwebos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
47 lines (44 loc) · 1.36 KB
/
index.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
var commandsList = require('./lib/commandsList/commandsList')
var command = require('./lib/lgwebos.command.js');
var install = require('./lib/install.js');
var uninstall = require('./lib/uninstall.js');
var exec = require('./lib/exec');
var updateDeviceTypes = require('./lib/updateDeviceTypes')
gladys.on('ready', function() {
gladys.param.getValue('LGTV_MAC_ADRESS')
.then((macAdress) => {
updateDeviceTypes({'macAdress':macAdress})
gladys.param.getValue('LGWEBOS_INTERVAL_UPDATE')
.then((intervalUser) => {
return intervalUser;
})
.catch(() => {
return 30;
})
.then((interval) => {
setInterval(function () {
sails.log.info('Update LG WEBOS data !')
updateDeviceTypes({'macAdress':macAdress})
gladys.utils.sqlUnique(
'SELECT ds.value FROM devicetype dt INNER JOIN devicestate ds ON dt.id=ds.devicetype INNER JOIN device d on dt.device=d.id WHERE dt.identifier = ? and d.service= ? ORDER BY ds.createdAt DESC LIMIT 1 ;',
[ 'Power', 'lgwebos' ]
)
.then((row) => {
if(row.value === 1)
{
commandsList.getAudioStatus()
}
})
}, interval*60000)
})
})
})
module.exports = function(sails) {
return {
television: commandsList,
command: command,
install: install,
exec: exec,
uninstall: uninstall
};
};