getMeasurement method
Gets a Calendar measurement for all events in all calendars.
The period starts at the last time this probe collected data or, the
first time, at HistoricSamplingConfiguration.past before now. The
period ends now.
Implementation
@override
Future<Measurement> getMeasurement() async {
if (_calendars == null) await _retrieveCalendars();
// Fast out if calendars could not be retrieved, e.g. due to missing permissions.
if (_calendars == null) {
return Measurement.fromData(Error(message: 'The list of calendars could not be retrieved.'));
}
DateTime startDate = samplingConfiguration.lastTime ?? DateTime.now().subtract(samplingConfiguration.past);
DateTime endDate = DateTime.now();
// Get all events from all calendars.
var events = await _deviceCalendar.listEvents(startDate, endDate);
return Measurement(
sensorStartTime: startDate.microsecondsSinceEpoch,
sensorEndTime: endDate.microsecondsSinceEpoch,
data: Calendar(startDate, endDate)
..calendarEvents = events.map((event) => CalendarEvent.fromEvent(event)).toList(),
);
}