-
Notifications
You must be signed in to change notification settings - Fork 8
/
Program.cs
141 lines (130 loc) · 6.33 KB
/
Program.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
using System;
using System.Collections.Generic;
namespace huecli
{
class Program
{
private static HueBridge activeHueBridge { get; set; }
private static ArgumentParser argParser { get; set; }
private static Settings settings { get; set; }
private static Preferences preferences { get; set; }
static void Main(string[] args)
{
settings = new Settings();
preferences = new Preferences();
argParser = new ArgumentParser();
HueBridgeDiscovery hueBridgeDiscovery = new HueBridgeDiscovery();
string mainAction = argParser.GetMainAction();
// Console.WriteLine(mainAction);
switch (mainAction)
{
case "scan-hubs":
Console.WriteLine("Scanning for hubs...");
List<HueBridgeObject> hueBridges = hueBridgeDiscovery.GetBridges();
if (hueBridges.Count != 0)
{
foreach (HueBridgeObject hueBridge in hueBridges)
{
Console.WriteLine("Found hub at address "+hueBridge.internalipaddress);
}
}
else
{
Console.WriteLine("No hubs could be discovered unfortunately.");
}
break;
case "get-hubs":
foreach (var hub in settings.GetHubs())
{
Console.WriteLine("Hub "+hub["alias"]+" at "+hub["localipaddress"]);
}
break;
case "remove-hub":
if (argParser.RemoveHubCheckEnoughArguments())
{
hueBridgeDiscovery.RemoveBridgeLink(settings.GetIPAddress(argParser.arguments[2]), settings.GetUsername(argParser.arguments[2]));
settings.RemoveHub(argParser.arguments[2]);
}
else
{
Console.WriteLine("Invalid syntax, use huecli remove-hub hubaliasgoeshere");
}
break;
case "add-hub":
if (argParser.AddHubCheckEnoughArguments())
{
Dictionary<string, string> hubToAdd = new Dictionary<string, string>();
hubToAdd.Add("alias", argParser.arguments[2]);
hubToAdd.Add("localipaddress", argParser.arguments[3]);
string bridgeUsername = hueBridgeDiscovery.CreateBridgeLink(hubToAdd["alias"], hubToAdd["localipaddress"]);
hubToAdd.Add("username", bridgeUsername);
settings.AddHub(hubToAdd);
}
else
{
Console.WriteLine("Invalid syntax, use huecli add-hub hubaliashere hubipaddresshere");
}
break;
case "get-lighting":
if (argParser.GetLightingCheckEnoughArguments())
{
HueBridge hueBridge = new HueBridge(argParser.arguments[2], settings.GetIPAddress(argParser.arguments[2]), settings.GetUsername(argParser.arguments[2]));
hueBridge.GetBridgeLighting();
}
else
{
Console.WriteLine("Invalid syntax, use huecli get-lighting hubaliashere");
}
break;
case "turn-on":
if (argParser.TurnOnOffCheckEnoughArguments())
{
HueBridge hueBridge = new HueBridge(argParser.arguments[2], settings.GetIPAddress(argParser.arguments[2]), settings.GetUsername(argParser.arguments[2]));
hueBridge.TurnOnLighting(argParser.arguments[3]);
}
else
{
Console.WriteLine("Invalid syntax, use huecli turn-on hubaliashere lightidhere");
}
break;
case "turn-off":
if (argParser.TurnOnOffCheckEnoughArguments())
{
HueBridge hueBridge = new HueBridge(argParser.arguments[2], settings.GetIPAddress(argParser.arguments[2]), settings.GetUsername(argParser.arguments[2]));
hueBridge.TurnOffLighting(argParser.arguments[3]);
}
else
{
Console.WriteLine("Invalid syntax, use huecli turn-off hubaliashere lightidhere");
}
break;
case "set-brightness":
if (argParser.SetBrightnessCheckEnoughArguments())
{
HueBridge hueBridge = new HueBridge(argParser.arguments[2], settings.GetIPAddress(argParser.arguments[2]), settings.GetUsername(argParser.arguments[2]));
hueBridge.SetLightingBrightness(argParser.arguments[3], argParser.arguments[4]);
}
else
{
Console.WriteLine("Invalid syntax, use huecli set-brightness hubaliashere lightidhere 1-254");
}
break;
case "set-temperature":
if (argParser.SetTemperatureCheckEnoughArguments())
{
HueBridge hueBridge = new HueBridge(argParser.arguments[2], settings.GetIPAddress(argParser.arguments[2]), settings.GetUsername(argParser.arguments[2]));
hueBridge.SetLightingTemperature(argParser.arguments[3], argParser.arguments[4]);
}
else
{
Console.WriteLine("Invalid syntax, use huecli set-temperature hubalias lightid 154-500");
}
break;
default:
argParser.ShowHelp();
break;
}
settings.Save();
}
}
}