-
Notifications
You must be signed in to change notification settings - Fork 10
/
discover_get.js
96 lines (92 loc) · 3.55 KB
/
discover_get.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
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
import { YamahaYXC } from './index.js';
// import { YamahaYXC } from 'yamaha-yxc-nodejs';
async function discover() {
var yamaha = new YamahaYXC();
try {
const result = await yamaha.discover();
console.table(result);
return Promise.resolve(result);
} catch (error) {
return Promise.reject(error);
}
}
async function discoverAndGet() {
let found = [];
try {
const devicearray = await discover();
if (devicearray) {
await Promise.all(
devicearray.map(async (device) => {
let data = {};
data[device.name] = {};
const yamaha = new YamahaYXC(device.ip);
data[device.name]['system'] = {};
const getDeviceInfo = await yamaha['getDeviceInfo']();
data[device.name]['system']['getDeviceInfo'] = getDeviceInfo;
const getNetworkStatus = await yamaha.getNetworkStatus();
data[device.name]['system']['getNetworkStatus'] = getNetworkStatus;
const getFuncStatus = await yamaha.getFuncStatus();
data[device.name]['system']['getFuncStatus'] = getFuncStatus;
const getLocationInfo = await yamaha.getLocationInfo();
data[device.name]['system']['getLocationInfo'] = getLocationInfo;
const getFeatures = await yamaha.getFeatures();
data[device.name]['system']['getFeatures'] = getFeatures;
data[device.name]['dist'] = {};
const getDistributionInfo = await yamaha.getDistributionInfo();
data[device.name]['dist']['getFeatures'] = getDistributionInfo;
if (getFeatures['netusb']) {
data[device.name]['netusb'] = {};
const getNetPlayInfo = await yamaha.getPlayInfo();
data[device.name]['netusb']['getPlayInfo'] = getNetPlayInfo;
const getPresetInfo = await yamaha.getPresetInfo();
data[device.name]['netusb']['getPresetInfo'] = getPresetInfo;
const getSettings = await yamaha.getSettings();
data[device.name]['netusb']['getSettings'] = getSettings;
const getRecentInfo = await yamaha.getRecentInfo();
data[device.name]['netusb']['getRecentInfo'] = getRecentInfo;
}
if (getFeatures['tuner']) {
data[device.name]['tuner'] = {};
const getTunerPlayInfo = await yamaha.getTunerPlayInfo();
data[device.name]['tuner']['getPlayInfo'] = getTunerPlayInfo;
const getTunerPresetInfo = await yamaha.getTunerPresetInfo();
data[device.name]['tuner']['getPresetInfo'] = getTunerPresetInfo;
}
if (getFeatures['cd']) {
data[device.name]['cd'] = {};
const getCdPlayInfo = await yamaha.getPlayInfo('cd');
data[device.name]['cd']['getPlayInfo'] = getCdPlayInfo;
}
if (getFeatures['clock']) {
data[device.name]['clock'] = {};
const getClockSettings = await yamaha.getClockSettings();
data[device.name]['clock']['getSettings'] = getClockSettings;
}
if (getFeatures['zone']) {
await Promise.all(
getFeatures['zone'].map(async (zone) => {
data[device.name][zone.id] = {};
const getStatus = await yamaha.getStatus();
data[device.name][zone.id]['getStatus'] = getStatus;
const getSoundProgramList = await yamaha.getSoundProgramList();
data[device.name][zone.id]['getSoundProgramList'] = getSoundProgramList;
const getSignalInfo = await yamaha.getSoundProgramList();
data[device.name][zone.id]['getSignalInfo'] = getSignalInfo;
})
);
}
found.push(data);
})
);
return Promise.resolve(found);
}
} catch (error) {
return Promise.reject(error);
}
}
discoverAndGet().then((res) => {
console.table(res);
console.log(res[0]);
console.log(JSON.stringify(res[0]));
console.log(JSON.stringify(res[1]));
});