-
Notifications
You must be signed in to change notification settings - Fork 0
/
myMuell.iob
112 lines (100 loc) · 4.27 KB
/
myMuell.iob
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
111
112
const city_id = 66005;
const area_id = 2800;
const logging = false;
const name = 'Müllabfuhr [Stadt]';
const numberOfEntries = 9;
const request = require('request');
const instanz = '0_userdata.' + instance + '.muell';
if (logging) log('starting muell.' + instanz);
extendObject(instanz, {
type: "device",
common: {
name: name
}
}, function (err) {
if (err) {
log('could not create device: ', 'warn');
return;
}
}
);
let baseData = {};
// query names first
request({
url: 'https://mymuell.jumomind.com/mmapp/api.php?r=trash&city_id=' + city_id + '&area_id=' + area_id,
method: 'GET',
headers: { 'Accept': 'application/json' }
}, function(error, response, body) {
if (!error && response.statusCode == 200) {
var data = JSON.parse(body); // info ist ein Objekt
data.forEach((v, i) => {
baseData[v._name] = v;
})
updateMuell();
}
}
);
schedule('{"time":{"exactTime":true,"start":"12:17"},"period":{"days":1}}', updateMuell);
function updateMuell() {
var options = {url: 'https://mymuell.jumomind.com/webservice.php?idx=termins&city_id=' + city_id + '&area_id=' + area_id + '&ws=3', method: 'GET', headers: { 'Accept': 'application/json' }};
request(options, function(error, response, body) {
if (!error && response.statusCode == 200) {
var info = JSON.parse(body); // info ist ein Objekt
if (info[0].Ack === 'Success') {
var data = info[0]._data; // xy ist eine Eigenschaft des Objektes info
let counter = 0;
const date = (new Date())
const todayStr = date.getFullYear() + "-" + ('00' + (date.getMonth() + 1 )).slice(-2) + "-" + ('00' + date.getDate()).slice(-2)
log(todayStr);
data.forEach((v, i) => {
if (todayStr < v.cal_date && counter <= numberOfEntries) {
const basePath = instanz + '.' + ('000' + counter).slice(-3);
log(v.cal_date + ' -> ' + basePath, 'debug');
// States erstellen
extendObject(basePath, {
type: "channel",
common: {
name: v.cal_date_normal
}
}, function (err) {
if (err) {
log('could not create device: ', 'warn');
return;
}
}
);
createState(basePath + '.date', v.cal_date_normal, {
name: 'Datum',
desc: 'Datum der Abholung',
type: 'string',
read: true,
write: false
}, () => {
setState(basePath + '.date', v.cal_date_normal, true);
});
createState(basePath + '.desc', baseData[v.cal_garbage_type].title, {
name: 'Beschreibung',
desc: 'Beschreibung der Abholung',
type: 'string',
read: true,
write: false
}, () => {
setState(basePath + '.desc', baseData[v.cal_garbage_type].title, true);
});
createState(basePath + '.color', {
name: 'Farbe',
desc: 'Farbe',
type: 'string',
role: 'level.color',
read: true,
write: false
}, () => {
setState(basePath + '.color', baseData[v.cal_garbage_type].color, true);
});
counter++;
}
});
}
}
});
};