Skip to content

Commit

Permalink
Added missing properties and support for Prism Effect
Browse files Browse the repository at this point in the history
  • Loading branch information
michielpost committed Aug 30, 2023
1 parent 971eee5 commit d3d42b6
Show file tree
Hide file tree
Showing 14 changed files with 87 additions and 20 deletions.
4 changes: 2 additions & 2 deletions src/HueApi.ConsoleSample/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,15 @@ void PrintChildren(HueResponse<HueResource> resources, Guid? owner, int level)
Console.ReadLine();


void EventStreamMessage(List<EventStreamResponse> events)
void EventStreamMessage(string bridgeIp, List<EventStreamResponse> events)
{
Console.WriteLine($"{DateTimeOffset.UtcNow} | {events.Count} new events");

foreach(var hueEvent in events)
{
foreach(var data in hueEvent.Data)
{
Console.WriteLine($"Data: {data.Metadata?.Name} / {data.IdV1}");
Console.WriteLine($"Bridge IP: {bridgeIp} | Data: {data.Metadata?.Name} / {data.IdV1}");
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/HueApi.Tests/HueApi.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="7.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.2" />
<PackageReference Include="MSTest.TestAdapter" Version="3.1.1" />
<PackageReference Include="MSTest.TestFramework" Version="3.1.1" />
<PackageReference Include="coverlet.collector" Version="6.0.0">
Expand Down
25 changes: 15 additions & 10 deletions src/HueApi.Tests/LightTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,17 +158,22 @@ public async Task ChangePlayStripLightColor()
//Turn red
var req = new UpdateLight()
.TurnOn();
//.SetColor(new ColorConverters.RGBColor("FF0000"));

req.Gradient = new Gradient();
req.Gradient.Mode = GradientMode.interpolated_palette;
req.Gradient.Points = new System.Collections.Generic.List<GradientPoint>()
//.SetColor(new ColorConverters.RGBColor("FF0000"));

//req.Gradient = new Gradient();
//req.Gradient.Mode = GradientMode.interpolated_palette;
//req.Gradient.Points = new System.Collections.Generic.List<GradientPoint>()
//{
// new GradientPoint().SetColor(new ColorConverters.RGBColor("FF0000")), //red
// new GradientPoint().SetColor(new ColorConverters.RGBColor("00FF00")), //green
// new GradientPoint().SetColor(new ColorConverters.RGBColor("0000FF")), //blue
// new GradientPoint().SetColor(new ColorConverters.RGBColor("FFA500")), //orange
// new GradientPoint().SetColor(new ColorConverters.RGBColor("A020F0")), //purple
//};

req.Effects = new Effects()
{
new GradientPoint().SetColor(new ColorConverters.RGBColor("FF0000")), //red
new GradientPoint().SetColor(new ColorConverters.RGBColor("00FF00")), //green
new GradientPoint().SetColor(new ColorConverters.RGBColor("0000FF")), //blue
new GradientPoint().SetColor(new ColorConverters.RGBColor("FFA500")), //orange
new GradientPoint().SetColor(new ColorConverters.RGBColor("A020F0")), //purple
Effect = Effect.prism
};

var result = await localHueClient.UpdateLightAsync(id, req);
Expand Down
2 changes: 1 addition & 1 deletion src/HueApi/BaseHueApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace HueApi
{
public delegate void EventStreamMessage(List<EventStreamResponse> events);
public delegate void EventStreamMessage(string bridgeIp, List<EventStreamResponse> events);

public abstract class BaseHueApi
{
Expand Down
2 changes: 1 addition & 1 deletion src/HueApi/LocalHueApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public async void StartEventStream(HttpClient? client = null, CancellationToken?

if (data != null && data.Any())
{
OnEventStreamMessage?.Invoke(data);
OnEventStreamMessage?.Invoke(this.ip, data);
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/HueApi/Models/Device.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ public class ProductData

[JsonPropertyName("software_version")]
public string SoftwareVersion { get; set; } = default!;

[JsonPropertyName("hardware_platform_type")]
public string HardwarePlatformType { get; set; } = default!;
}

public class Device : HueResource
Expand Down
2 changes: 1 addition & 1 deletion src/HueApi/Models/Light.cs
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ public class Effects
[JsonConverter(typeof(JsonStringEnumConverter))]
public enum Effect
{
no_effect, fire, candle, sparkle
no_effect, fire, candle, sparkle, prism, glisten, opal
}

public class TimedEffects
Expand Down
2 changes: 1 addition & 1 deletion src/HueApi/Models/LightAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace HueApi.Models
{
public class LightAction : IUpdateColor, IUpdateColorTemperature, IUpdateOn
public class LightAction : IUpdateColor, IUpdateColorTemperature, IUpdateOn, IUpdateDynamics
{
[JsonPropertyName("on")]
public On? On { get; set; }
Expand Down
7 changes: 7 additions & 0 deletions src/HueApi/Models/Metadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,12 @@ public class Metadata

[JsonPropertyName("image")]
public ResourceIdentifier? Image { get; set; }

/// <summary>
/// Used with Button
/// control identifier of the switch which is unique per device. Meaning in combination with type – dots Number of dots – number Number printed on device – other a logical order of controls in switch
/// </summary>
[JsonPropertyName("control_id")]
public int? ControlId { get; set; }
}
}
13 changes: 13 additions & 0 deletions src/HueApi/Models/Requests/Interface/IUpdateDynamics.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HueApi.Models.Requests.Interface
{
public interface IUpdateDynamics
{
public Dynamics? Dynamics { get; set; }
}
}
2 changes: 1 addition & 1 deletion src/HueApi/Models/Requests/UpdateGroupedLight.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace HueApi.Models.Requests
{
public class UpdateGroupedLight : BaseResourceRequest, IUpdateColor, IUpdateColorTemperature, IUpdateOn, IUpdateDimmingDelta, IUpdateDimming
public class UpdateGroupedLight : BaseResourceRequest, IUpdateColor, IUpdateColorTemperature, IUpdateOn, IUpdateDimmingDelta, IUpdateDimming, IUpdateDynamics
{
[JsonPropertyName("on")]
public On? On { get; set; }
Expand Down
2 changes: 1 addition & 1 deletion src/HueApi/Models/Requests/UpdateLight.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace HueApi.Models.Requests
{
public class UpdateLight : BaseResourceRequest, IUpdateColor, IUpdateColorTemperature, IUpdateOn, IUpdateDimmingDelta, IUpdateDimming
public class UpdateLight : BaseResourceRequest, IUpdateColor, IUpdateColorTemperature, IUpdateOn, IUpdateDimmingDelta, IUpdateDimming, IUpdateDynamics
{
[JsonPropertyName("on")]
public On? On { get; set; }
Expand Down
39 changes: 39 additions & 0 deletions src/HueApi/Models/Requests/UpdateLightExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,5 +127,44 @@ public static T SetBrightness<T>(this T lightCommand, double brightness) where T
};
return lightCommand;
}

public static T SetDuration<T>(this T lightCommand, TimeSpan duration) where T : IUpdateDynamics
{
if (lightCommand == null)
throw new ArgumentNullException(nameof(lightCommand));

lightCommand.Dynamics = new Dynamics
{
Duration = (int)duration.TotalMilliseconds
};
return lightCommand;
}

public static T SetDuration<T>(this T lightCommand, int durationMs) where T : IUpdateDynamics
{
if (lightCommand == null)
throw new ArgumentNullException(nameof(lightCommand));

lightCommand.Dynamics = new Dynamics
{
Duration = durationMs
};
return lightCommand;
}

public static T SetSpeed<T>(this T lightCommand, double speed) where T : IUpdateDynamics
{
if (lightCommand == null)
throw new ArgumentNullException(nameof(lightCommand));

if (!(0 <= speed && speed <= 1))
throw new ArgumentOutOfRangeException(nameof(speed), "Value must be between 0 and 1");

lightCommand.Dynamics = new Dynamics
{
Speed = speed
};
return lightCommand;
}
}
}
2 changes: 1 addition & 1 deletion src/HueDiagnostics/HueDiagnostics.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="CompareNETObjects" Version="4.79.0" />
<PackageReference Include="CompareNETObjects" Version="4.80.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="7.0.4" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="7.0.0" />
</ItemGroup>
Expand Down

0 comments on commit d3d42b6

Please sign in to comment.