-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathJsonBuilder.cs
More file actions
102 lines (99 loc) · 4.5 KB
/
JsonBuilder.cs
File metadata and controls
102 lines (99 loc) · 4.5 KB
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
namespace Kevsoft.WLED.Tests;
public class JsonBuilder
{
public static string CreateStateJson(StateResponse state)
{
return $@"{{
""on"": {state.On.ToString().ToLower()},
""bri"": {state.Brightness},
""transition"": {state.Transition},
""ps"": {state.PresetId},
""pl"": {state.PlaylistId},
""nl"": {{
""on"": {state.Nightlight.On.ToString().ToLower()},
""dur"": {state.Nightlight.Duration},
""mode"": {state.Nightlight.Mode},
""tbri"": {state.Nightlight.TargetBrightness}
}},
""udpn"": {{
""send"": {state.UdpPackets.Send.ToString().ToLower()},
""recv"": {state.UdpPackets.Receive.ToString().ToLower()}
}},
""lor"": {state.LiveDataOverride},
""mainseg"": {state.MainSegment},
""seg"": [{String.Join(", ", state.Segments.Select(seg =>
{
return $@"{{
""id"": {seg.Id},
""start"": {seg.Start},
""stop"": {seg.Stop},
""len"": {seg.Length},
""grp"": {seg.Group},
""spc"": {seg.Spacing},
""of"": {seg.Offset},
""col"": [
{String.Join(", ", seg.Colors.Select(col => $"[{String.Join(",", col)}]"))}
],
""fx"": {seg.EffectId},
""sx"": {seg.EffectSpeed},
""ix"": {seg.EffectIntensity},
""pal"": {seg.ColorPaletteId},
""sel"": {seg.Selected.ToString().ToLower()},
""rev"": {seg.Reverse.ToString().ToLower()},
""on"": {seg.SegmentState.ToString().ToLower()},
""bri"": {seg.Brightness}
}}";
}))}],
""tb"": {state.Timebase}
}}";
}
public static string CreateInformationJson(InformationResponse information)
{
return $@"{{
""ver"": ""{information.VersionName}"",
""vid"": {information.BuildId},
""leds"": {{
""count"": {information.Leds.Count},
""fps"": {information.Leds.Fps},
""lc"": {information.Leds.LightCapabilities},
""pwr"": {information.Leds.PowerUsage},
""maxpwr"": {information.Leds.MaximumPower},
""maxseg"": {information.Leds.MaximumSegments},
""bootps"": {information.Leds.BootupPreset},
""matrix"": {{
""w"": {information.Leds.Matrix.Width},
""h"": {information.Leds.Matrix.Height}
}}
}},
""str"": {information.ToggleSendReceive.ToString().ToLower()},
""name"": ""{information.Name}"",
""udpport"": {information.UdpPort},
""live"": {information.Live.ToString().ToLower()},
""fxcount"": {information.EffectsCount},
""palcount"": {information.PalettesCount},
""arch"": ""{information.Arch}"",
""core"": ""{information.Core}"",
""freeheap"": {information.FreeHeapMemory},
""uptime"": {information.UpTime},
""opt"": {information.Opt},
""brand"": ""{information.Brand}"",
""product"": ""{information.Product}"",
""btype"": ""{information.BuildType}"",
""mac"": ""{information.MacAddress}"",
""ip"": ""{information.NetworkAddress}""
}}";
}
public static string CreateRootResponse(WLedRootResponse expected)
{
return $@"{{
""state"": {CreateStateJson(expected.State)},
""info"": {CreateInformationJson(expected.Information)},
""effects"": [
{String.Join(", ", expected.Effects.Select(x => $@"""{x}"""))}
],
""palettes"": [
{String.Join(", ", expected.Palettes.Select(x => $@"""{x}"""))}
]
}}";
}
}