|
1 |
| -using HADotNet.Core.Models; |
2 |
| -using System; |
3 |
| -using System.Collections.Generic; |
4 |
| -using System.Threading.Tasks; |
5 |
| - |
6 |
| -namespace HADotNet.Core.Clients |
7 |
| -{ |
8 |
| - /// <summary> |
9 |
| - /// Provides access to the calendar API for retrieving information about calendar entries. |
10 |
| - /// </summary> |
11 |
| - public sealed class CalendarClient : BaseClient |
12 |
| - { |
13 |
| - /// <summary> |
14 |
| - /// Initializes a new instance of the <see cref="CalendarClient" />. |
15 |
| - /// </summary> |
16 |
| - /// <param name="instance">The Home Assistant base instance URL.</param> |
17 |
| - /// <param name="apiKey">The Home Assistant long-lived access token.</param> |
18 |
| - public CalendarClient(Uri instance, string apiKey) : base(instance, apiKey) { } |
19 |
| - |
20 |
| - /// <summary> |
21 |
| - /// Retrieves a list of current and future calendar items, from now until the specified <paramref name="daysFromNow" />. The maximum number of results is driven by the "max_results" configuration option in the calendar config. |
22 |
| - /// </summary> |
23 |
| - /// <param name="calendarEntityName">The full name of the calendar entity. If this paramter does not start with "calendar.", it will be prepended automatically.</param> |
24 |
| - /// <param name="daysFromNow">Optional, defaults to 30. The number of days from the current point in time to retrieve calendar items for.</param> |
25 |
| - /// <returns>A <see cref="List{CalendarObject}" /> representing the calendar items found.</returns> |
26 |
| - public async Task<List<CalendarObject>> GetEvents(string calendarEntityName, int daysFromNow = 30) => await GetEvents(calendarEntityName, DateTimeOffset.Now, DateTimeOffset.Now.AddDays(daysFromNow)); |
27 |
| - |
28 |
| - /// <summary> |
29 |
| - /// Retrieves a list of current and future calendar items, between the <paramref name="start" /> and <paramref name="end" /> parameters. The maximum number of results is driven by the "max_results" configuration option in the calendar config. |
30 |
| - /// </summary> |
31 |
| - /// <param name="calendarEntityName">The full name of the calendar entity. If this paramter does not start with "calendar.", it will be prepended automatically.</param> |
32 |
| - /// <param name="start">The start date/time to search.</param> |
33 |
| - /// <param name="end">The end date/time to search.</param> |
34 |
| - /// <returns>A <see cref="List{CalendarObject}" /> representing the calendar items found.</returns> |
35 |
| - public async Task<List<CalendarObject>> GetEvents(string calendarEntityName, DateTimeOffset start, DateTimeOffset end) => await Get<List<CalendarObject>>($"/api/calendars/{(calendarEntityName.StartsWith("calendar.") ? calendarEntityName : "calendar." + calendarEntityName)}?start={start:yyyy-MM-dd\\THH:mm:sszzz}&end={end:yyyy-MM-dd\\THH:mm:sszzz}"); |
36 |
| - } |
37 |
| -} |
| 1 | +using HADotNet.Core.Models; |
| 2 | +using System; |
| 3 | +using System.Collections.Generic; |
| 4 | +using System.Threading.Tasks; |
| 5 | + |
| 6 | +namespace HADotNet.Core.Clients |
| 7 | +{ |
| 8 | + /// <summary> |
| 9 | + /// Provides access to the calendar API for retrieving information about calendar entries. |
| 10 | + /// </summary> |
| 11 | + public sealed class CalendarClient : BaseClient |
| 12 | + { |
| 13 | + /// <summary> |
| 14 | + /// Initializes a new instance of the <see cref="CalendarClient" />. |
| 15 | + /// </summary> |
| 16 | + /// <param name="instance">The Home Assistant base instance URL.</param> |
| 17 | + /// <param name="apiKey">The Home Assistant long-lived access token.</param> |
| 18 | + public CalendarClient(Uri instance, string apiKey) : base(instance, apiKey) { } |
| 19 | + |
| 20 | + /// <summary> |
| 21 | + /// Retrieves a list of current and future calendar items, from now until the specified <paramref name="daysFromNow" />. The maximum number of results is driven by the "max_results" configuration option in the calendar config. |
| 22 | + /// </summary> |
| 23 | + /// <param name="calendarEntityName">The full name of the calendar entity. If this paramter does not start with "calendar.", it will be prepended automatically.</param> |
| 24 | + /// <param name="daysFromNow">Optional, defaults to 30. The number of days from the current point in time to retrieve calendar items for.</param> |
| 25 | + /// <returns>A <see cref="List{CalendarObject}" /> representing the calendar items found.</returns> |
| 26 | + public async Task<List<CalendarObject>> GetEvents(string calendarEntityName, int daysFromNow = 30) => await GetEvents(calendarEntityName, DateTimeOffset.Now, DateTimeOffset.Now.AddDays(daysFromNow)); |
| 27 | + |
| 28 | + /// <summary> |
| 29 | + /// Retrieves a list of current and future calendar items, between the <paramref name="start" /> and <paramref name="end" /> parameters. The maximum number of results is driven by the "max_results" configuration option in the calendar config. |
| 30 | + /// </summary> |
| 31 | + /// <param name="calendarEntityName">The full name of the calendar entity. If this paramter does not start with "calendar.", it will be prepended automatically.</param> |
| 32 | + /// <param name="start">The start date/time to search.</param> |
| 33 | + /// <param name="end">The end date/time to search.</param> |
| 34 | + /// <returns>A <see cref="List{CalendarObject}" /> representing the calendar items found.</returns> |
| 35 | + public async Task<List<CalendarObject>> GetEvents(string calendarEntityName, DateTimeOffset start, DateTimeOffset end) => await Get<List<CalendarObject>>($"/api/calendars/{(calendarEntityName.StartsWith("calendar.") ? calendarEntityName : "calendar." + calendarEntityName)}?start={start:yyyy-MM-dd\\THH:mm:ss}Z&end={end:yyyy-MM-dd\\THH:mm:ss}Z"); |
| 36 | + } |
| 37 | +} |
0 commit comments