-
-
Notifications
You must be signed in to change notification settings - Fork 114
/
EntertainmentConfigurationTests.cs
178 lines (133 loc) · 5.45 KB
/
EntertainmentConfigurationTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
using HueApi.ColorConverters.Original.Extensions;
using HueApi.Extensions.cs;
using HueApi.Models;
using HueApi.Models.Requests;
using Microsoft.Extensions.Configuration;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Linq;
using System.Threading.Tasks;
namespace HueApi.Tests
{
[TestClass]
public class EntertainmentConfigurationTests
{
private readonly LocalHueApi localHueClient;
public EntertainmentConfigurationTests()
{
var builder = new ConfigurationBuilder().AddUserSecrets<EntertainmentConfigurationTests>();
var config = builder.Build();
localHueClient = new LocalHueApi(config["ip"], key: config["key"]);
}
[TestMethod]
public async Task Get()
{
var result = await localHueClient.GetEntertainmentConfigurationsAsync();
Assert.IsNotNull(result);
Assert.IsFalse(result.HasErrors);
}
[TestMethod]
public async Task GetById()
{
var all = await localHueClient.GetEntertainmentConfigurationsAsync();
var id = all.Data.Last().Id;
var result = await localHueClient.GetEntertainmentConfigurationAsync(id);
Assert.IsNotNull(result);
Assert.IsFalse(result.HasErrors);
Assert.IsTrue(result.Data.Count == 1);
//Turn all lights in this entertainment group on
var entServices = result.Data.First().Locations.ServiceLocations.Select(x => x.Service?.Rid).ToList();
var allResources = await localHueClient.GetResourcesAsync();
var devices = allResources.Data.Where(x => entServices.Contains(x.Id)).Select(x => x.Owner?.Rid).ToList();
var lights = allResources.Data.Where(x => devices.Contains(x.Id)).Select(x => x.Services?.Where(x => x.Rtype == "light").FirstOrDefault()?.Rid).ToList();
UpdateLight update = new UpdateLight()
.TurnOn()
.SetColor(new ColorConverters.RGBColor("FF0000"));
foreach(var light in lights.Where(x => x.HasValue))
{
await localHueClient.UpdateLightAsync(light!.Value, update);
}
}
[TestMethod]
public async Task PutById()
{
var all = await localHueClient.GetEntertainmentConfigurationsAsync();
var current = all.Data.Last();
var id = current.Id;
UpdateEntertainmentConfiguration req = new UpdateEntertainmentConfiguration();
req.Locations = current.Locations;
//foreach(var location in current.Locations.ServiceLocations)
//{
// //location.EqualizationFactor = null;
// location.Service.Rtype = null;
//}
var result = await localHueClient.UpdateEntertainmentConfigurationAsync(id, req);
Assert.IsNotNull(result);
Assert.IsFalse(result.HasErrors);
Assert.IsTrue(result.Data.Count == 1);
Assert.AreEqual(id, result.Data.First().Rid);
}
[TestMethod]
public async Task SetGradientLightStripLocation()
{
var all = await localHueClient.GetEntertainmentConfigurationsAsync();
var current = all.Data.Last();
await SetAndCheckPositions(current, new HuePosition(-0.5, -0.2, 0), new HuePosition(-0.1, -0.1, 0));
}
private async Task SetAndCheckPositions(EntertainmentConfiguration current, HuePosition pos1, HuePosition pos2)
{
var id = current.Id;
UpdateEntertainmentConfiguration req = new UpdateEntertainmentConfiguration();
req.Locations = current.Locations;
req.Locations.ServiceLocations[0].Positions[0] = pos1;
req.Locations.ServiceLocations[0].Positions[1] = pos2;
var result = await localHueClient.UpdateEntertainmentConfigurationAsync(id, req);
Assert.IsFalse(result.HasErrors);
var newConfig = await localHueClient.GetEntertainmentConfigurationAsync(id);
Assert.IsNotNull(newConfig);
Assert.AreEqual(newConfig.Data.First().Locations.ServiceLocations[0].Positions[0], pos1);
Assert.AreEqual(newConfig.Data.First().Locations.ServiceLocations[0].Positions[1], pos2);
Assert.AreEqual(newConfig.Data.First().Channels[0].Position, pos1);
Assert.AreEqual(newConfig.Data.First().Channels[2].Position, pos2);
}
[TestMethod]
public async Task CreateGetDeleteEntertainmentConfiguration()
{
//Get light to use in the entertainment area
var lights = await localHueClient.GetEntertainmentServicesAsync();
UpdateEntertainmentConfiguration req = new UpdateEntertainmentConfiguration
{
Metadata = new Models.Metadata
{
Name = "Test Config",
},
ConfigurationType = Models.EntertainmentConfigurationType.other,
Locations = new Models.Locations()
};
foreach (var light in lights.Data.Where(x => x.Renderer))
{
var lightPosition = new HueServiceLocation
{
Service = light.ToResourceIdentifier(),
Positions = new System.Collections.Generic.List<HuePosition>
{
new HuePosition
{
X = 0.42, Y = 0.5, Z = 0
}
}
};
req.Locations.ServiceLocations.Add(lightPosition);
}
var result = await localHueClient.CreateEntertainmentConfigurationAsync(req);
Assert.IsNotNull(result);
Assert.IsFalse(result.HasErrors);
Assert.IsTrue(result.Data.Count == 1);
var newId = result.Data.First().Rid;
//Get it
var getResult = await localHueClient.GetEntertainmentConfigurationAsync(newId);
//Delete it
var deleteResult = await localHueClient.DeleteEntertainmentConfigurationAsync(newId);
}
}
}