-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfixOutOfDateGuide.js
66 lines (56 loc) · 2.37 KB
/
fixOutOfDateGuide.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
'use strict'
import {Tivo} from './lib/tivo.js';
import {config} from './config.js';
const getTime = () => {
return (new Date()).toLocaleTimeString('en-US');
}
const doit = async () => {
let tivo = new Tivo(config.ip, config.mak);
await tivo.connect();
console.log('connected');
const systemInformation = await tivo.systemInformation();
console.log(systemInformation.programInfoTo);
//less then 10 days in ms
if ((Date.parse( systemInformation.programInfoTo) -Date.now()) < 86400000) {
console.log(`Guide data is through ${systemInformation.programInfoTo}. Rebooting.`)
await tivo.reboot();
await new Promise(resolve => setTimeout(resolve, 30000));//wait 30 seconds before we start trying to reconnect. My bolt takes about 1:30
do {
console.log(getTime() + `: waiting tivo to boot up`);
try {
await tivo.connect();//connect timeout is about 20 seconds so we don't need additonal sleeps.
} catch (e) {
//console.log('not connected?', e);
}
} while (!tivo.isConnected());
console.log(getTime() + ': Reconnected. Running first phone home');
await tivo.phoneHome();
let phoneHomeStatus = {};
do {
await new Promise(resolve => setTimeout(resolve, 4000));
try {
phoneHomeStatus = await tivo.phoneHomeStatus();
//console.log('phoneHomeStatus', phoneHomeStatus);
console.log(getTime()+ `: ${phoneHomeStatus.phase} - ${phoneHomeStatus.status}`)
} catch (e) {
console.log('sad face', e)
}
} while (phoneHomeStatus.phase !== 'succeeded');
console.log(getTime() + ': running second phone home');
await tivo.phoneHome();
do {
await new Promise(resolve => setTimeout(resolve, 4000));
try {
phoneHomeStatus = await tivo.phoneHomeStatus();
//console.log('phoneHomeStatus', phoneHomeStatus);
console.log(getTime() + `: ${phoneHomeStatus.phase} - ${phoneHomeStatus.status}`)
} catch (e) {
console.log('sad face', e)
}
} while (phoneHomeStatus.phase !== 'succeeded');
console.log('finished')
tivo.disconnect();
}
tivo.disconnect();
}
doit();