-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpopulate.js
More file actions
110 lines (100 loc) · 2.27 KB
/
populate.js
File metadata and controls
110 lines (100 loc) · 2.27 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
var hue = require("node-hue-api");
var dynamo = require("dynamodb")
var Joi = require("joi");
var HueApi = hue.HueApi;
// var AWS = require('aws-sdk');
var _ = require('lodash');
var host = process.env.HOST;
var user = process.env.USER;
dynamo.AWS.config.loadFromPath('credentials.json');
dynamo.AWS.config.update({region: "us-east-1"});
console.log("This is the host ip: " + host);
console.log("This is the user: " + user);
var displayResult = function(result) {
console.log(JSON.stringify(result, null, 2));
};
var displayError = function(err) {
console.error(err);
};
var api = new HueApi(host, user);
var Device = new dynamo.define("Device", {
hashKey: "number",
timestamps: true,
schema: {
name: Joi.string(),
id: Joi.string(),
number: Joi.string(),
state: {
bri: Joi.number(),
hue: Joi.number(),
sat: Joi.number(),
effect: Joi.string(),
ct: Joi.number(),
colormode: Joi.string(),
}
}
});
var Button = new dynamo.define("Button", {
hashKey: "id",
schema: {
id: Joi.string(),
event: {
single: dynamo.types.stringSet(),
double: dynamo.types.stringSet(),
long: dynamo.types.stringSet(),
},
}
})
Device.config({tableName: "DevicesTable"});
Button.config({tableName: "ButtonsTable"});
dynamo.createTables(function(err) {
if (err) {
console.log('Error creating tables: ', err);
} else {
console.log('Tables has been created');
}
});
// gotta populate the events with something
Button.create({
id: "G030MD049054QVJN",
event: {
single: ["1"],
double: ["2"],
long: ["3"],
},
}, function(err, acc) {
console.log("insert");
if (err) {
console.log(err);
}
console.log("Created button in dynamo");
});
// maybe use uniqe id instead
api.lights(function(err, config) {
if (err) throw err;
var lights = config.lights;;
_.forEach(lights, function(value) {
console.log(value);
var state = value["state"];
console.log(state);
Device.create({
name: value["name"],
id: value["uniqueid"],
number: value["id"],
state: {
bri: state["bri"],
hue: state["hue"],
sat: state["sat"],
effect: state["effect"],
ct: state["ct"],
colormode: state["colormode"],
}
}, function(err, acc) {
console.log("HI");
if (err) {
console.log(err);
}
console.log("Created item in dynamo");
});
});
});