-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathlistAllRecipes.js
48 lines (44 loc) · 1.61 KB
/
listAllRecipes.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
'use strict';
const neeoapi = require('neeo-sdk');
console.log('NEEO SDK Example "getAllRecipes"');
console.log('--------------------------------');
function startSdkExample(brain) {
console.log('- Fetch all recipes...');
neeoapi.getRecipes(brain)
.then((recipes) => {
console.log('- Recipes fetched, number of recipes found:', recipes.length);
recipes.forEach((recipe) => {
// HINT: you can call recipe.action.powerOn() / recipe.action.powerOff() to change the state of the Recipe.
console.log(' RECIPE:', JSON.stringify({
name: decodeURIComponent(recipe.detail.devicename),
model: decodeURIComponent(recipe.detail.model),
manufacturer: decodeURIComponent(recipe.detail.manufacturer),
roomname: decodeURIComponent(recipe.detail.roomname),
isPoweredOn: recipe.isPoweredOn,
powerKey: recipe.powerKey
}));
});
console.log('- Fetch power state of recipes');
return neeoapi.getRecipesPowerState(brain);
})
.then((poweredOnKeys) => {
console.log('- Power state fetched, powered on recipes:', poweredOnKeys);
process.exit(0);
})
.catch((err) => {
//if there was any error, print message out to console
console.error('ERROR!', err);
});
}
const brainIp = process.env.BRAINIP;
if (brainIp) {
console.log('- use NEEO Brain IP from env variable', brainIp);
startSdkExample(brainIp);
} else {
console.log('- discover one NEEO Brain...');
neeoapi.discoverOneBrain()
.then((brain) => {
console.log('- Brain discovered:', brain.name);
startSdkExample(brain);
});
}