Skip to content

Commit

Permalink
1.5.1 Fix calendar get request
Browse files Browse the repository at this point in the history
  • Loading branch information
qJake committed Feb 1, 2021
1 parent cad2b5a commit 77a52e0
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 40 deletions.
74 changes: 37 additions & 37 deletions HADotNet.Core/Clients/CalendarClient.cs
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
using HADotNet.Core.Models;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace HADotNet.Core.Clients
{
/// <summary>
/// Provides access to the calendar API for retrieving information about calendar entries.
/// </summary>
public sealed class CalendarClient : BaseClient
{
/// <summary>
/// Initializes a new instance of the <see cref="CalendarClient" />.
/// </summary>
/// <param name="instance">The Home Assistant base instance URL.</param>
/// <param name="apiKey">The Home Assistant long-lived access token.</param>
public CalendarClient(Uri instance, string apiKey) : base(instance, apiKey) { }

/// <summary>
/// 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.
/// </summary>
/// <param name="calendarEntityName">The full name of the calendar entity. If this paramter does not start with "calendar.", it will be prepended automatically.</param>
/// <param name="daysFromNow">Optional, defaults to 30. The number of days from the current point in time to retrieve calendar items for.</param>
/// <returns>A <see cref="List{CalendarObject}" /> representing the calendar items found.</returns>
public async Task<List<CalendarObject>> GetEvents(string calendarEntityName, int daysFromNow = 30) => await GetEvents(calendarEntityName, DateTimeOffset.Now, DateTimeOffset.Now.AddDays(daysFromNow));

/// <summary>
/// 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.
/// </summary>
/// <param name="calendarEntityName">The full name of the calendar entity. If this paramter does not start with "calendar.", it will be prepended automatically.</param>
/// <param name="start">The start date/time to search.</param>
/// <param name="end">The end date/time to search.</param>
/// <returns>A <see cref="List{CalendarObject}" /> representing the calendar items found.</returns>
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}");
}
}
using HADotNet.Core.Models;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace HADotNet.Core.Clients
{
/// <summary>
/// Provides access to the calendar API for retrieving information about calendar entries.
/// </summary>
public sealed class CalendarClient : BaseClient
{
/// <summary>
/// Initializes a new instance of the <see cref="CalendarClient" />.
/// </summary>
/// <param name="instance">The Home Assistant base instance URL.</param>
/// <param name="apiKey">The Home Assistant long-lived access token.</param>
public CalendarClient(Uri instance, string apiKey) : base(instance, apiKey) { }

/// <summary>
/// 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.
/// </summary>
/// <param name="calendarEntityName">The full name of the calendar entity. If this paramter does not start with "calendar.", it will be prepended automatically.</param>
/// <param name="daysFromNow">Optional, defaults to 30. The number of days from the current point in time to retrieve calendar items for.</param>
/// <returns>A <see cref="List{CalendarObject}" /> representing the calendar items found.</returns>
public async Task<List<CalendarObject>> GetEvents(string calendarEntityName, int daysFromNow = 30) => await GetEvents(calendarEntityName, DateTimeOffset.Now, DateTimeOffset.Now.AddDays(daysFromNow));

/// <summary>
/// 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.
/// </summary>
/// <param name="calendarEntityName">The full name of the calendar entity. If this paramter does not start with "calendar.", it will be prepended automatically.</param>
/// <param name="start">The start date/time to search.</param>
/// <param name="end">The end date/time to search.</param>
/// <returns>A <see cref="List{CalendarObject}" /> representing the calendar items found.</returns>
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");
}
}
6 changes: 3 additions & 3 deletions HADotNet.Core/HADotNet.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@
<PackageTags>home-assistant external api library</PackageTags>
<Title>HADotNet Core Library</Title>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Version>1.5.0</Version>
<Version>1.5.1</Version>
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
<PackageProjectUrl>https://github.com/qJake/HADotNet</PackageProjectUrl>
<RepositoryUrl>https://github.com/qJake/HADotNet.git</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<PackageReleaseNotes></PackageReleaseNotes>
<LangVersion>7.3</LangVersion>
<AssemblyVersion>1.5.0.0</AssemblyVersion>
<FileVersion>1.5.0.0</FileVersion>
<AssemblyVersion>1.5.1.0</AssemblyVersion>
<FileVersion>1.5.1.0</FileVersion>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
Expand Down

0 comments on commit 77a52e0

Please sign in to comment.