Skip to content

Commit

Permalink
Support for Capabilities API
Browse files Browse the repository at this point in the history
  • Loading branch information
michielpost committed Sep 15, 2016
1 parent e40c5fa commit c7100f7
Show file tree
Hide file tree
Showing 6 changed files with 197 additions and 2 deletions.
34 changes: 34 additions & 0 deletions src/Q42.HueApi.Tests/CapabilitiesTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Configuration;
using System.Collections.Generic;
using System.Threading.Tasks;
using Q42.HueApi.Interfaces;

namespace Q42.HueApi.Tests
{
[TestClass]
public class CapabilitiesTest
{
private IHueClient _client;

[TestInitialize]
public void Initialize()
{
string ip = ConfigurationManager.AppSettings["ip"].ToString();
string key = ConfigurationManager.AppSettings["key"].ToString();

_client = new LocalHueClient(ip, key);
}

[TestMethod]
public async Task GetCapabilitiesTest()
{
var result = await _client.GetCapabilitiesAsync();

Assert.IsNotNull(result);
}

}
}
1 change: 1 addition & 0 deletions src/Q42.HueApi.Tests/Q42.HueApi.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
</Otherwise>
</Choose>
<ItemGroup>
<Compile Include="CapabilitiesTest.cs" />
<Compile Include="HueApiTests.cs" />
<Compile Include="Remote\RemoteLightsTests.cs" />
<Compile Include="RuleTests.cs" />
Expand Down
37 changes: 37 additions & 0 deletions src/Q42.HueApi/HueClient-Capabilities.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Q42.HueApi.Models;
using Q42.HueApi.Models.Groups;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;

namespace Q42.HueApi
{
/// <summary>
/// Partial HueClient, contains requests to the /config/ url
/// </summary>
public partial class HueClient
{

/// <summary>
/// Get bridge capabilities
/// </summary>
/// <returns></returns>
public async Task<BridgeCapabilities> GetCapabilitiesAsync()
{
CheckInitialized();

HttpClient client = await GetHttpClient().ConfigureAwait(false);
var stringResult = await client.GetStringAsync(new Uri(ApiBase + "capabilities")).ConfigureAwait(false);

BridgeCapabilities capabilities = DeserializeResult<BridgeCapabilities>(stringResult);

return capabilities;
}

}
}
10 changes: 8 additions & 2 deletions src/Q42.HueApi/Interfaces/IHueClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,12 @@ public interface IHueClient
Task<string> CreateResourceLinkAsync(ResourceLink resourceLink);
Task<HueResults> UpdateResourceLinkAsync(string id, ResourceLink resourceLink);

#endregion
}
#endregion

#region Capabilities

Task<BridgeCapabilities> GetCapabilitiesAsync();

#endregion
}
}
115 changes: 115 additions & 0 deletions src/Q42.HueApi/Models/BridgeCapabilities.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Q42.HueApi.Models
{
public class BridgeCapabilities
{
public LightsCapability Lights { get; set; }
public SensorsCapability Sensors { get; set; }
public GroupsCapability Groups { get; set; }
public ScenesCapability Scenes { get; set; }
public SchedulesCapability Schedules { get; set; }
public RulesCapability Rules { get; set; }
public ResourceLinksCapability Resourcelinks { get; set; }
public Timezones Timezones { get; set; }

}

public class LightsCapability : Capability
{
}

public class ClipCapability : Capability
{
}

public class ZllCapability : Capability
{
}

public class ZgpCapability : Capability
{
}

public class SensorsCapability : Capability
{
/// <summary>
/// Capability information of resources which are directly created by POST
/// </summary>
public ClipCapability Clip { get; set; }

/// <summary>
/// Capability information of Zigbee resources which are discovered by POST
/// </summary>
public ZllCapability Zll { get; set; }

/// <summary>
/// Capability information of ZGP resources which are discovered by POST
/// </summary>
public ZgpCapability Zgp { get; set; }
}

public class GroupsCapability : Capability
{
}

public class LightstatesCapability : Capability
{
}

public class ScenesCapability : Capability
{
/// <summary>
/// Represents the total pool of individual lightsstates (scene setting per lamp) which can be used across all scenes in /scenes/lightstates
/// </summary>
public LightstatesCapability Lightstates { get; set; }
}

public class SchedulesCapability : Capability
{
}

public class ConditionsCapability : Capability
{
}

public class ActionsCapability : Capability
{
}

public class RulesCapability : Capability
{
public ConditionsCapability Conditions { get; set; }

/// <summary>
/// Represents the total pool of individual actions which can be used across all rules in /rules/actions
/// </summary>
public ActionsCapability Actions { get; set; }
}

public class ResourceLinksCapability : Capability
{

}

public class Timezones
{
/// <summary>
/// List of supported time zones represented as tz database strings. Each value can be set in /config/timezone. Other values are not supported.
/// </summary>
public List<string> Values { get; set; }
}

public abstract class Capability
{
/// <summary>
/// Total (maximum) number of resources which still can be created by POST on this resource path. The number of creatable resources for a specific subresource type might be lower.
/// </summary>
public int Available { get; set; }
}

}
2 changes: 2 additions & 0 deletions src/Q42.HueApi/Q42.HueApi.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
<Compile Include="Converters\HttpMethodConverter.cs" />
<Compile Include="Crypto\MD5.cs" />
<Compile Include="HttpBridgeLocator.cs" />
<Compile Include="HueClient-Capabilities.cs" />
<Compile Include="HueClient-ResourceLinks.cs" />
<Compile Include="Interfaces\IRemoteAuthenticationClient.cs" />
<Compile Include="Interfaces\IRemoteHueClient.cs" />
Expand All @@ -74,6 +75,7 @@
<Compile Include="HueClient.cs" />
<Compile Include="Models\AccessTokenResponse.cs" />
<Compile Include="Models\Bridge.cs" />
<Compile Include="Models\BridgeCapabilities.cs" />
<Compile Include="Models\BridgeConfigUpdate.cs" />
<Compile Include="Models\BridgeConfig.cs" />
<Compile Include="Models\GenericScheduleCommand.cs" />
Expand Down

0 comments on commit c7100f7

Please sign in to comment.