Skip to content

Commit

Permalink
Added Signaling property for UpdateLight / issue #311
Browse files Browse the repository at this point in the history
  • Loading branch information
michielpost committed Nov 23, 2023
1 parent cd9c98a commit 4898613
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 13 deletions.
16 changes: 14 additions & 2 deletions src/HueApi.Tests/LightTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Microsoft.Extensions.Configuration;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

Expand Down Expand Up @@ -36,7 +37,7 @@ public async Task Get()
public async Task GetById()
{
var all = await localHueClient.GetLightsAsync();
var id = all.Data.First().Id;
var id = all.Data.Last().Id;

var result = await localHueClient.GetLightAsync(id);

Expand All @@ -56,13 +57,24 @@ public async Task PutById()

UpdateLight req = new UpdateLight()
{
Alert = new UpdateAlert()
Signaling = new SignalingUpdate
{
Signal = Signal.alternating,
Duration = 60000,
Colors = new List<Color>
{
new Color { Xy = new XyPosition { X = 0.456, Y = 0.123, }},
new Color { Xy = new XyPosition { X = 0.333, Y = 0.712, }}
}
}
};
var result = await localHueClient.UpdateLightAsync(id, req);

Assert.IsNotNull(result);
Assert.IsFalse(result.HasErrors);

var resultRead = await localHueClient.GetLightAsync(id);

Assert.IsTrue(result.Data.Count == 1);
Assert.AreEqual(id, result.Data.First().Rid);

Expand Down
2 changes: 1 addition & 1 deletion src/HueApi/HueApi.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<WarningsAsErrors>nullable</WarningsAsErrors>
<Version>1.5.0</Version>
<Version>1.5.1</Version>
<Authors>Michiel Post</Authors>
<Description>For Clip v2 API. Open source library for interaction with the Philips Hue Bridge. Allows you to control your lights from C#.</Description>
<PackageProjectUrl>https://github.com/michielpost/Q42.HueApi</PackageProjectUrl>
Expand Down
17 changes: 10 additions & 7 deletions src/HueApi/Models/Device.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,28 @@ namespace HueApi.Models
public class ProductData
{
[JsonPropertyName("certified")]
public bool Certified { get; set; }
public bool? Certified { get; set; }

[JsonPropertyName("manufacturer_name")]
public string ManufacturerName { get; set; } = default!;
public string? ManufacturerName { get; set; }

[JsonPropertyName("model_id")]
public string ModelId { get; set; } = default!;
public string? ModelId { get; set; }

[JsonPropertyName("product_archetype")]
public string ProductArchetype { get; set; } = default!;
public string? ProductArchetype { get; set; }

[JsonPropertyName("product_name")]
public string ProductName { get; set; } = default!;
public string? ProductName { get; set; }

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

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

[JsonPropertyName("function")]
public string? Function { get; set; }
}

public class Device : HueResource
Expand Down
10 changes: 8 additions & 2 deletions src/HueApi/Models/GroupedLight.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,16 @@ namespace HueApi.Models
{
public class GroupedLight : HueResource
{
[JsonPropertyName("on")]
public On On { get; set; } = default!;

[JsonPropertyName("dimming")]
public Dimming? Dimming { get; set; }

[JsonPropertyName("alert")]
public Alert? Alert { get; set; }

[JsonPropertyName("on")]
public On? On { get; set; }
[JsonPropertyName("signaling")]
public Signaling? Signaling { get; set; }
}
}
27 changes: 26 additions & 1 deletion src/HueApi/Models/Light.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ public class Light : HueResource
[JsonPropertyName("alert")]
public Alert? Alert { get; set; }

[JsonPropertyName("product_data")]
public ProductData? ProductData { get; set; }

[JsonPropertyName("signaling")]
public Signaling? Signaling { get; set; }

Expand Down Expand Up @@ -61,6 +64,9 @@ public class Alert

public class Signaling
{
[JsonPropertyName("signal_values")]
public List<Signal>? SignalValues { get; set; }

[JsonPropertyName("status")]
public SignalingStatus? Status { get; set; }
}
Expand All @@ -78,6 +84,25 @@ public class SignalingStatus
/// </summary>
[JsonPropertyName("estimated_end")]
public DateTimeOffset? EstimatedEnd { get; set; }

[JsonPropertyName("colors")]
public List<XyPosition>? Colors { get; set; }
}

public class SignalingUpdate
{
[JsonPropertyName("signal")]
public Signal Signal { get; set; }

[JsonPropertyName("duration")]
public int Duration { get; set; }

/// <summary>
/// List of colors to apply to the signal (not supported by all signals)
/// </summary>
[JsonPropertyName("colors")]
public List<Color>? Colors { get; set; }

}

public class Dynamics
Expand Down Expand Up @@ -297,6 +322,6 @@ public enum PowerUpOnMode
[JsonConverter(typeof(JsonStringEnumConverter))]
public enum Signal
{
no_signal, on_off
no_signal, on_off, on_off_color, alternating
}
}
3 changes: 3 additions & 0 deletions src/HueApi/Models/Requests/UpdateGroupedLight.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ public class UpdateGroupedLight : BaseResourceRequest, IUpdateColor, IUpdateColo
[JsonPropertyName("alert")]
public UpdateAlert? Alert { get; set; }

[JsonPropertyName("signaling")]
public SignalingUpdate? Signaling { get; set; }

[JsonPropertyName("dynamics")]
public Dynamics? Dynamics { get; set; }

Expand Down
3 changes: 3 additions & 0 deletions src/HueApi/Models/Requests/UpdateLight.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ public class UpdateLight : BaseResourceRequest, IUpdateColor, IUpdateColorTemper
[JsonPropertyName("alert")]
public UpdateAlert? Alert { get; set; }

[JsonPropertyName("signaling")]
public SignalingUpdate? Signaling { get; set; }

[JsonPropertyName("gradient")]
public Gradient? Gradient { get; set; }

Expand Down

0 comments on commit 4898613

Please sign in to comment.