-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathHP19_get-all-events.js
48 lines (41 loc) · 1.36 KB
/
HP19_get-all-events.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
// if set to undefined, all calendars will be fetched
// if set to a calendar name, for instance 'Test', only events from calendar with name 'Test' will be fetched
const calendarName = 'Test'
const metadataResult = await Homey.flow.runFlowCardAction({
uri: 'homey:app:no.runely.calendar',
id: 'get_calendars_metadata'
})
//console.log(metadataResult)
const metadata = JSON.parse(metadataResult.returnTokens.json)
if (!Array.isArray(metadata)) {
throw new Error('Metadata not found')
}
//console.log(metadata)
let eventCount = 0
for await (const calendar of metadata) {
if (calendarName && calendarName !== calendar.calendarName) {
continue
}
eventCount += calendar.events.length
console.log(`----- ${calendar.events.length} events from '${calendar.calendarName}' -----`)
for await (const eventIndex of calendar.events) {
const eventResult = await Homey.flow.runFlowCardAction({
uri: 'homey:app:no.runely.calendar',
id: 'get_calendar_event',
args: {
calendar: {
id: calendar.calendarName,
name: calendar.calendarName
},
index: eventIndex
}
})
const event = eventResult.returnTokens
console.log(`Event @ ${eventIndex}:`, event)
}
}
console.log('Total events from calendar(s):', eventCount)
if (eventCount === 0) {
throw new Error('0 events found in calendar(s)')
}
return true