Skip to content

Commit f7d6000

Browse files
authored
Using ColorTempKelvin instead of ColorTemp (which is no longer supported by Home Assistant) -> https://www.home-assistant.io/blog/2026/03/04/release-20263/#backward-incompatible-changes (#206)
* Using ColorTempKelvin instead of kelvin. * Removing unused properties.
1 parent 25abf6a commit f7d6000

14 files changed

Lines changed: 38 additions & 257 deletions

File tree

src/CodeCasa.Lights.NetDaemon.Scenes/Generated/SceneAttributes.cs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,6 @@ namespace CodeCasa.Lights.NetDaemon.Scenes.Generated;
44

55
internal record SceneAttributes
66
{
7-
[JsonPropertyName("entity_id")]
8-
public IReadOnlyList<string>? EntityId { get; init; }
9-
107
[JsonPropertyName("id")]
118
public string? Id { get; init; }
12-
13-
[JsonPropertyName("icon")]
14-
public string? Icon { get; init; }
15-
16-
[JsonPropertyName("friendly_name")]
17-
public string? FriendlyName { get; init; }
189
}

src/CodeCasa.Lights.NetDaemon/Extensions/LightAttributesExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public static LightParameters ToLightParameters(this LightAttributes lightAttrib
1717
}
1818
if (string.Equals(lightAttributes.ColorMode, ColorModes.ColorTemp, StringComparison.OrdinalIgnoreCase))
1919
{
20-
return new LightParameters { ColorTemp = (int?)lightAttributes.ColorTemp, Brightness = lightAttributes.Brightness };
20+
return new LightParameters { ColorTempKelvin = (int?)lightAttributes.ColorTempKelvin, Brightness = lightAttributes.Brightness };
2121
}
2222
if (string.Equals(lightAttributes.ColorMode, ColorModes.Brightness, StringComparison.OrdinalIgnoreCase))
2323
{

src/CodeCasa.Lights.NetDaemon/Extensions/LightEntityCoreExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ public static bool SceneEquals(this ILightEntityCore lightEntity, LightParameter
216216
var actualParameters = lightEntity.GetLightParameters();
217217
return
218218
BrightnessEquals(actualParameters.Brightness, lightParameters.Brightness) &&
219-
actualParameters.ColorTemp == lightParameters.ColorTemp;
219+
actualParameters.ColorTempKelvin == lightParameters.ColorTempKelvin;
220220
}
221221

222222
private static bool BrightnessEquals(double? brightness1, double? brightness2)

src/CodeCasa.Lights.NetDaemon/Extensions/LightTransitionExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public static LightTurnOnParameters ToLightTurnOnParameters(this LightTransition
1111
Transition = lightTransition.TransitionTime?.TotalSeconds,
1212
Brightness = lightTransition.LightParameters.Brightness,
1313
RgbColor = lightTransition.LightParameters.RgbColor?.ToRgbCollection(),
14-
ColorTemp = lightTransition.LightParameters.ColorTemp
14+
ColorTempKelvin = lightTransition.LightParameters.ColorTempKelvin
1515
};
1616
}
1717

src/CodeCasa.Lights.NetDaemon/Generated/LightAttributes.cs

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -4,60 +4,18 @@ namespace CodeCasa.Lights.NetDaemon.Generated;
44

55
internal record LightAttributes
66
{
7-
[JsonPropertyName("supported_color_modes")]
8-
public IReadOnlyList<string>? SupportedColorModes { get; init; }
9-
10-
[JsonPropertyName("supported_features")]
11-
public double? SupportedFeatures { get; init; }
12-
137
[JsonPropertyName("color_mode")]
148
public string? ColorMode { get; init; }
159

16-
[JsonPropertyName("min_color_temp_kelvin")]
17-
public double? MinColorTempKelvin { get; init; }
18-
19-
[JsonPropertyName("max_color_temp_kelvin")]
20-
public double? MaxColorTempKelvin { get; init; }
21-
22-
[JsonPropertyName("min_mireds")]
23-
public double? MinMireds { get; init; }
24-
25-
[JsonPropertyName("max_mireds")]
26-
public double? MaxMireds { get; init; }
27-
2810
[JsonPropertyName("brightness")]
2911
public double? Brightness { get; init; }
3012

3113
[JsonPropertyName("color_temp_kelvin")]
3214
public double? ColorTempKelvin { get; init; }
3315

34-
[JsonPropertyName("color_temp")]
35-
public double? ColorTemp { get; init; }
36-
37-
[JsonPropertyName("hs_color")]
38-
public IReadOnlyList<double>? HsColor { get; init; }
39-
4016
[JsonPropertyName("rgb_color")]
4117
public IReadOnlyList<double>? RgbColor { get; init; }
4218

43-
[JsonPropertyName("xy_color")]
44-
public IReadOnlyList<double>? XyColor { get; init; }
45-
4619
[JsonPropertyName("entity_id")]
4720
public IReadOnlyList<string>? EntityId { get; init; }
48-
49-
[JsonPropertyName("effect_list")]
50-
public IReadOnlyList<string>? EffectList { get; init; }
51-
52-
[JsonPropertyName("color")]
53-
public object? Color { get; init; }
54-
55-
[JsonPropertyName("effect")]
56-
public object? Effect { get; init; }
57-
58-
[JsonPropertyName("icon")]
59-
public string? Icon { get; init; }
60-
61-
[JsonPropertyName("friendly_name")]
62-
public string? FriendlyName { get; init; }
6321
}

src/CodeCasa.Lights.NetDaemon/Generated/LightEntityCoreExtensions.cs

Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -10,68 +10,10 @@ public static void TurnOn(this ILightEntityCore target, LightTurnOnParameters da
1010
target.CallService("turn_on", data);
1111
}
1212

13-
///<summary>Turns on one or more lights and adjusts their properties, even when they are turned on already.</summary>
14-
///<param name="target">The ILightEntityCore to call this service for</param>
15-
///<param name="transition">Duration it takes to get to next state.</param>
16-
///<param name="rgbColor">The color in RGB format. A list of three integers between 0 and 255 representing the values of red, green, and blue. eg: [255, 100, 100]</param>
17-
///<param name="kelvin">Color temperature in Kelvin.</param>
18-
///<param name="brightnessPct">Number indicating the percentage of full brightness, where 0 turns the light off, 1 is the minimum brightness, and 100 is the maximum brightness.</param>
19-
///<param name="brightnessStepPct">Change brightness by a percentage.</param>
20-
///<param name="effect">Light effect.</param>
21-
///<param name="rgbwColor"> eg: [255, 100, 100, 50]</param>
22-
///<param name="rgbwwColor"> eg: [255, 100, 100, 50, 70]</param>
23-
///<param name="colorName"></param>
24-
///<param name="hsColor"> eg: [300, 70]</param>
25-
///<param name="xyColor"> eg: [0.52, 0.43]</param>
26-
///<param name="colorTemp"></param>
27-
///<param name="brightness"></param>
28-
///<param name="brightnessStep"></param>
29-
///<param name="white"></param>
30-
///<param name="profile"> eg: relax</param>
31-
///<param name="flash"></param>
32-
public static void TurnOn(this ILightEntityCore target, double? transition = null,
33-
IReadOnlyCollection<int>? rgbColor = null, object? kelvin = null, double? brightnessPct = null,
34-
double? brightnessStepPct = null, string? effect = null, object? rgbwColor = null,
35-
object? rgbwwColor = null, object? colorName = null, object? hsColor = null, object? xyColor = null,
36-
object? colorTemp = null, double? brightness = null, double? brightnessStep = null, object? white = null,
37-
string? profile = null, object? flash = null)
38-
{
39-
target.CallService("turn_on",
40-
new LightTurnOnParameters
41-
{
42-
Transition = transition,
43-
RgbColor = rgbColor,
44-
Kelvin = kelvin,
45-
BrightnessPct = brightnessPct,
46-
BrightnessStepPct = brightnessStepPct,
47-
Effect = effect,
48-
RgbwColor = rgbwColor,
49-
RgbwwColor = rgbwwColor,
50-
ColorName = colorName,
51-
HsColor = hsColor,
52-
XyColor = xyColor,
53-
ColorTemp = colorTemp,
54-
Brightness = brightness,
55-
BrightnessStep = brightnessStep,
56-
White = white,
57-
Profile = profile,
58-
Flash = flash
59-
});
60-
}
61-
6213
///<summary>Turns off one or more lights.</summary>
6314
public static void TurnOff(this ILightEntityCore target, LightTurnOffParameters data)
6415
{
6516
target.CallService("turn_off", data);
6617
}
67-
68-
///<summary>Turns off one or more lights.</summary>
69-
///<param name="target">The ILightEntityCore to call this service for</param>
70-
///<param name="transition">Duration it takes to get to next state.</param>
71-
///<param name="flash"></param>
72-
public static void TurnOff(this ILightEntityCore target, double? transition = null, object? flash = null)
73-
{
74-
target.CallService("turn_off", new LightTurnOffParameters { Transition = transition, Flash = flash });
75-
}
7618
}
7719
}

src/CodeCasa.Lights.NetDaemon/Generated/LightTurnOffParameters.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,4 @@ internal record LightTurnOffParameters
77
///<summary>Duration it takes to get to next state.</summary>
88
[JsonPropertyName("transition")]
99
public double? Transition { get; init; }
10-
11-
[JsonPropertyName("flash")]
12-
public object? Flash { get; init; }
1310
}

src/CodeCasa.Lights.NetDaemon/Generated/LightTurnOnParameters.cs

Lines changed: 3 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -4,65 +4,16 @@ namespace CodeCasa.Lights.NetDaemon.Generated;
44

55
internal record LightTurnOnParameters
66
{
7-
///<summary>Duration it takes to get to next state.</summary>
87
[JsonPropertyName("transition")]
98
public double? Transition { get; init; }
109

11-
///<summary>The color in RGB format. A list of three integers between 0 and 255 representing the values of red, green, and blue. eg: [255, 100, 100]</summary>
10+
///<summary> eg: [255, 100, 100]</summary>
1211
[JsonPropertyName("rgb_color")]
1312
public IReadOnlyCollection<int>? RgbColor { get; init; }
1413

15-
///<summary>Color temperature in Kelvin.</summary>
16-
[JsonPropertyName("kelvin")]
17-
public object? Kelvin { get; init; }
18-
19-
///<summary>Number indicating the percentage of full brightness, where 0 turns the light off, 1 is the minimum brightness, and 100 is the maximum brightness.</summary>
20-
[JsonPropertyName("brightness_pct")]
21-
public double? BrightnessPct { get; init; }
22-
23-
///<summary>Change brightness by a percentage.</summary>
24-
[JsonPropertyName("brightness_step_pct")]
25-
public double? BrightnessStepPct { get; init; }
26-
27-
///<summary>Light effect.</summary>
28-
[JsonPropertyName("effect")]
29-
public string? Effect { get; init; }
30-
31-
///<summary> eg: [255, 100, 100, 50]</summary>
32-
[JsonPropertyName("rgbw_color")]
33-
public object? RgbwColor { get; init; }
34-
35-
///<summary> eg: [255, 100, 100, 50, 70]</summary>
36-
[JsonPropertyName("rgbww_color")]
37-
public object? RgbwwColor { get; init; }
38-
39-
[JsonPropertyName("color_name")]
40-
public object? ColorName { get; init; }
41-
42-
///<summary> eg: [300, 70]</summary>
43-
[JsonPropertyName("hs_color")]
44-
public object? HsColor { get; init; }
45-
46-
///<summary> eg: [0.52, 0.43]</summary>
47-
[JsonPropertyName("xy_color")]
48-
public object? XyColor { get; init; }
49-
50-
[JsonPropertyName("color_temp")]
51-
public object? ColorTemp { get; init; }
14+
[JsonPropertyName("color_temp_kelvin")]
15+
public object? ColorTempKelvin { get; init; }
5216

5317
[JsonPropertyName("brightness")]
5418
public double? Brightness { get; init; }
55-
56-
[JsonPropertyName("brightness_step")]
57-
public double? BrightnessStep { get; init; }
58-
59-
[JsonPropertyName("white")]
60-
public object? White { get; init; }
61-
62-
///<summary> eg: relax</summary>
63-
[JsonPropertyName("profile")]
64-
public string? Profile { get; init; }
65-
66-
[JsonPropertyName("flash")]
67-
public object? Flash { get; init; }
6819
}

src/CodeCasa.Lights/Extensions/LightParametersExtensions.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@ public static LightParameters Interpolate(this LightParameters fromLightParamete
2828
// If one of the parameters have a brightness of 0 and no color values, we copy the color values from the other parameters.
2929
if (fromLightParameters.Brightness == 0)
3030
{
31-
if (fromLightParameters.ColorTemp == null && fromLightParameters.RgbColor == null)
31+
if (fromLightParameters.ColorTempKelvin == null && fromLightParameters.RgbColor == null)
3232
{
3333
fromLightParameters = toLightParameters with { Brightness = 0 };
3434
}
3535
}
3636
else if (toLightParameters.Brightness == 0)
3737
{
38-
if (toLightParameters.ColorTemp == null && toLightParameters.RgbColor == null)
38+
if (toLightParameters.ColorTempKelvin == null && toLightParameters.RgbColor == null)
3939
{
4040
toLightParameters = fromLightParameters with { Brightness = 0 };
4141
}
@@ -59,19 +59,19 @@ public static LightParameters Interpolate(this LightParameters fromLightParamete
5959
};
6060
}
6161

62-
if (fromLightParameters.ColorTemp == null || toLightParameters.ColorTemp == null)
62+
if (fromLightParameters.ColorTempKelvin == null || toLightParameters.ColorTempKelvin == null)
6363
{
64-
throw new InvalidOperationException("Interpolation requires either RGB or ColorTemp value");
64+
throw new InvalidOperationException("Interpolation requires either RGB or ColorTempKelvin value");
6565
}
6666

67-
var fromColorTemp = fromLightParameters.ColorTemp.Value;
68-
var toColorTemp = toLightParameters.ColorTemp.Value;
67+
var fromColorTemp = fromLightParameters.ColorTempKelvin.Value;
68+
var toColorTemp = toLightParameters.ColorTempKelvin.Value;
6969
// Note: This blending is done in Mired, which can be blended linearly. If we ever want to do this using Kelvin, this is no longer the case, and the blending should convert first.
7070
var blendedTemp = (int)Math.Round(fromColorTemp + (toColorTemp - fromColorTemp) * progress);
7171

7272
return result with
7373
{
74-
ColorTemp = blendedTemp
74+
ColorTempKelvin = blendedTemp
7575
};
7676
}
7777

@@ -104,11 +104,11 @@ private static Color GetRgbColor(LightParameters lightParameters)
104104
{
105105
return lightParameters.RgbColor.Value;
106106
}
107-
if (lightParameters.ColorTemp == null)
107+
if (lightParameters.ColorTempKelvin == null)
108108
{
109-
throw new ArgumentException("Rgb color conversion requires either RGB or ColorTemp value");
109+
throw new ArgumentException("Rgb color conversion requires either RGB or ColorTempKelvin value");
110110
}
111111

112-
return ColorConverter.KelvinToRgb(1000000.0 / Convert.ToDouble(lightParameters.ColorTemp));
112+
return ColorConverter.KelvinToRgb(Convert.ToDouble(lightParameters.ColorTempKelvin));
113113
}
114114
}

src/CodeCasa.Lights/LightParameters.Templates.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,25 @@ public partial record LightParameters
55
/// <summary>
66
/// Gets a template that generates parameters for a relaxing scene (warm color temperature, medium brightness).
77
/// </summary>
8-
public static LightParameters Relax = new() { Brightness = 142, ColorTemp = 500 };
8+
public static LightParameters Relax = new() { Brightness = 142, ColorTempKelvin = 2000 };
99

1010
/// <summary>
1111
/// Gets a template that generates parameters for a nightlight scene (very warm color temperature, very low brightness).
1212
/// </summary>
13-
public static LightParameters NightLight = new() { Brightness = 2, ColorTemp = 500 };
13+
public static LightParameters NightLight = new() { Brightness = 2, ColorTempKelvin = 2000 };
1414

1515
/// <summary>
1616
/// Gets a template that generates parameters for a concentrate scene (cool/neutral color temperature, high brightness).
1717
/// </summary>
18-
public static LightParameters Concentrate = new() { Brightness = byte.MaxValue, ColorTemp = 233 };
18+
public static LightParameters Concentrate = new() { Brightness = byte.MaxValue, ColorTempKelvin = 4292 };
1919

2020
/// <summary>
2121
/// Gets a template that generates parameters for a bright scene (warm color temperature, maximum brightness).
2222
/// </summary>
23-
public static LightParameters Bright = new() { Brightness = byte.MaxValue, ColorTemp = 366 };
23+
public static LightParameters Bright = new() { Brightness = byte.MaxValue, ColorTempKelvin = 2732 };
2424

2525
/// <summary>
2626
/// Gets a template that generates parameters for a dimmed scene (warm color temperature, low brightness).
2727
/// </summary>
28-
public static LightParameters Dimmed = new() { Brightness = 76, ColorTemp = 366 };
28+
public static LightParameters Dimmed = new() { Brightness = 76, ColorTempKelvin = 2732 };
2929
}

0 commit comments

Comments
 (0)