From 5705a0d363b6d84a4070bc1ca164e3cfc9d96b8b Mon Sep 17 00:00:00 2001 From: rmmlr Date: Thu, 11 Oct 2018 15:12:48 +0200 Subject: [PATCH] HueCmd are still working --- HueCmd/App.config | 14 +- HueCmd/HueCmd.csproj | 71 +++++++++- HueCmd/Program.cs | 123 +++++++++++++++++- HueCmd/packages.config | 51 ++++++++ {HueHookServer => HueHook}/Hue.cs | 3 +- HueHook/HueHook.csproj | 78 ++++++++++- {HueHookServer => HueHook}/HueParameters.cs | 3 +- .../Util/BooleanParser.cs | 2 +- HueHook/Util/NameValueCollectionExtensions.cs | 74 +++++++++++ HueHook/app.config | 15 +++ HueHook/packages.config | 51 ++++++++ HueHookServer/App.config | 2 +- HueHookServer/HookReceiver.cs | 66 +--------- HueHookServer/HueHookServer.csproj | 32 +++-- HueHookServer/packages.config | 16 +-- HueHook_Test/HueHook_Test.csproj | 13 +- HueHook_Test/app.config | 15 +++ HueHook_Test/packages.config | 4 +- 18 files changed, 530 insertions(+), 103 deletions(-) create mode 100644 HueCmd/packages.config rename {HueHookServer => HueHook}/Hue.cs (95%) rename {HueHookServer => HueHook}/HueParameters.cs (97%) rename HueHookServer/BoolParser.cs => HueHook/Util/BooleanParser.cs (99%) create mode 100644 HueHook/Util/NameValueCollectionExtensions.cs create mode 100644 HueHook/app.config create mode 100644 HueHook/packages.config create mode 100644 HueHook_Test/app.config diff --git a/HueCmd/App.config b/HueCmd/App.config index 731f6de..e15102e 100644 --- a/HueCmd/App.config +++ b/HueCmd/App.config @@ -1,6 +1,18 @@ - + + + + + + + + + + + + + \ No newline at end of file diff --git a/HueCmd/HueCmd.csproj b/HueCmd/HueCmd.csproj index 32ec167..8f8094a 100644 --- a/HueCmd/HueCmd.csproj +++ b/HueCmd/HueCmd.csproj @@ -11,6 +11,8 @@ v4.6.1 512 true + + AnyCPU @@ -32,14 +34,73 @@ 4 + + ..\packages\Microsoft.Win32.Primitives.4.3.0\lib\net46\Microsoft.Win32.Primitives.dll + + + ..\packages\Newtonsoft.Json.11.0.2\lib\net45\Newtonsoft.Json.dll + + + ..\packages\Q42.HueApi.3.7.2\lib\netstandard1.1\Q42.HueApi.dll + + + ..\packages\System.AppContext.4.3.0\lib\net46\System.AppContext.dll + + + + ..\packages\System.Console.4.3.1\lib\net46\System.Console.dll + + + ..\packages\System.Diagnostics.DiagnosticSource.4.5.1\lib\net46\System.Diagnostics.DiagnosticSource.dll + + + ..\packages\System.Globalization.Calendars.4.3.0\lib\net46\System.Globalization.Calendars.dll + + + ..\packages\System.IO.Compression.4.3.0\lib\net46\System.IO.Compression.dll + + + + ..\packages\System.IO.Compression.ZipFile.4.3.0\lib\net46\System.IO.Compression.ZipFile.dll + + + ..\packages\System.IO.FileSystem.4.3.0\lib\net46\System.IO.FileSystem.dll + + + ..\packages\System.IO.FileSystem.Primitives.4.3.0\lib\net46\System.IO.FileSystem.Primitives.dll + + + ..\packages\System.Net.Http.4.3.4\lib\net46\System.Net.Http.dll + + + ..\packages\System.Net.Sockets.4.3.0\lib\net46\System.Net.Sockets.dll + + + + ..\packages\System.Runtime.InteropServices.RuntimeInformation.4.3.0\lib\net45\System.Runtime.InteropServices.RuntimeInformation.dll + + + ..\packages\System.Security.Cryptography.Algorithms.4.3.1\lib\net461\System.Security.Cryptography.Algorithms.dll + + + ..\packages\System.Security.Cryptography.Encoding.4.3.0\lib\net46\System.Security.Cryptography.Encoding.dll + + + ..\packages\System.Security.Cryptography.Primitives.4.3.0\lib\net46\System.Security.Cryptography.Primitives.dll + + + ..\packages\System.Security.Cryptography.X509Certificates.4.3.2\lib\net461\System.Security.Cryptography.X509Certificates.dll + - + + ..\packages\System.Xml.ReaderWriter.4.3.1\lib\net46\System.Xml.ReaderWriter.dll + @@ -47,6 +108,7 @@ + @@ -55,4 +117,11 @@ + + + + Dieses Projekt verweist auf mindestens ein NuGet-Paket, das auf diesem Computer fehlt. Verwenden Sie die Wiederherstellung von NuGet-Paketen, um die fehlenden Dateien herunterzuladen. Weitere Informationen finden Sie unter "http://go.microsoft.com/fwlink/?LinkID=322105". Die fehlende Datei ist "{0}". + + + \ No newline at end of file diff --git a/HueCmd/Program.cs b/HueCmd/Program.cs index 882d8e4..6fc7e80 100644 --- a/HueCmd/Program.cs +++ b/HueCmd/Program.cs @@ -1,17 +1,28 @@ -using System; +using Rca.HueHook; +using Rca.HueHook.Util; +using System; using System.Collections.Generic; +using System.Collections.Specialized; using System.Diagnostics; using System.Linq; using System.Reflection; using System.Text; +using System.Threading; using System.Threading.Tasks; namespace Rca.HueCmd { + class Program { + public static HueHookSettings Settings; + static void Main(string[] args) { + const string SETTINGS_PATH = "HueHookSettings.xml"; + + Hue m_HueClient = new Hue(); + #region Startup var versionInfo = FileVersionInfo.GetVersionInfo(Assembly.GetEntryAssembly().Location); @@ -35,6 +46,116 @@ static void Main(string[] args) Console.WriteLine(); #endregion + + #region handle args + + //All args start with "--" add to NVC + var parameters = new NameValueCollection(); + HueObjects hueObject = HueObjects.None; + + foreach (var arg in args) + { + if (arg.StartsWith("-")) + { + if (arg.EndsWith(".hue")) + { + var obj = arg.Substring(1, arg.Length - 5); + try + { + hueObject = (HueObjects)Enum.Parse(typeof(HueObjects), obj, true); + } + catch (Exception ex) + { + Console.ForegroundColor = ConsoleColor.Red; + Console.WriteLine(ex.Message); + Console.WriteLine(); + Console.Write("Program is closing..."); + Console.ReadKey(); + } + } + var parameter = arg.Split(new string[3] { "-", "=", ":" }, StringSplitOptions.RemoveEmptyEntries); + if (parameter.Length == 2) + parameters.Add(parameter[0], parameter[1]); + } + } + + //TODO: verify parameters + + #endregion + + #region Init program + Console.WriteLine("Load settings: {0}", SETTINGS_PATH); + Console.WriteLine(); + try + { + Settings = HueHookSettings.FromFile(SETTINGS_PATH); + } + catch (Exception ex) + { + Console.ForegroundColor = ConsoleColor.Red; + Console.WriteLine(ex.Message); + Console.WriteLine(); + Console.Write("Program is closing..."); + Console.ReadKey(); + return; + } + Console.WriteLine("Settings loaded successfully"); + Console.WriteLine(); + for (int i = 0; i < 70; i++) + Console.Write("-"); + Console.WriteLine(); + Console.WriteLine(); + + #endregion + + #region Init hue client + Console.WriteLine("Try to connect hue bridge at: {0}", Settings.BridgeIp); + Console.WriteLine(); + m_HueClient.ConnectBridge(Settings.BridgeIp, Settings.BridgeUsername); + Thread.Sleep(2500); + + for (int i = 0; i < 70; i++) + Console.Write("-"); + Console.WriteLine(); + Console.WriteLine(); + #endregion + + #region Execute command + + switch (hueObject) + { + case HueObjects.Light: + Console.ForegroundColor = ConsoleColor.White; + Console.BackgroundColor = ConsoleColor.Magenta; + Console.WriteLine("Setup LIGHT"); + Console.ResetColor(); + + var cmd1 = parameters.ToLightCommand(); + Hue.Client.SendCommandAsync(cmd1, new List {parameters["id"]}); + break; + case HueObjects.Group: + Console.ForegroundColor = ConsoleColor.White; + Console.BackgroundColor = ConsoleColor.Magenta; + Console.WriteLine("Setup GROUP"); + Console.ResetColor(); + + var cmd2 = parameters.ToLightCommand(); + Hue.Client.SendGroupCommandAsync(cmd2, parameters["id"]); + break; + case HueObjects.Scene: + Console.ForegroundColor = ConsoleColor.White; + Console.BackgroundColor = ConsoleColor.Magenta; + Console.WriteLine("Setup SCENE"); + Console.ResetColor(); + + Hue.Client.RecallSceneAsync(parameters["id"]); + break; + } + #endregion + +#if DEBUG + Console.ReadKey(); +#endif } } } diff --git a/HueCmd/packages.config b/HueCmd/packages.config new file mode 100644 index 0000000..280759a --- /dev/null +++ b/HueCmd/packages.config @@ -0,0 +1,51 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/HueHookServer/Hue.cs b/HueHook/Hue.cs similarity index 95% rename from HueHookServer/Hue.cs rename to HueHook/Hue.cs index 20d4f67..cae0ccf 100644 --- a/HueHookServer/Hue.cs +++ b/HueHook/Hue.cs @@ -4,10 +4,9 @@ using System.Linq; using System.Net; using System.Text; -using System.Threading; using System.Threading.Tasks; -namespace Rca.HueHookServer +namespace Rca.HueHook { public class Hue { diff --git a/HueHook/HueHook.csproj b/HueHook/HueHook.csproj index 52148e4..f277399 100644 --- a/HueHook/HueHook.csproj +++ b/HueHook/HueHook.csproj @@ -11,6 +11,8 @@ HueHook v4.6.1 512 + + true @@ -30,19 +32,93 @@ 4 + + ..\packages\Microsoft.Win32.Primitives.4.3.0\lib\net46\Microsoft.Win32.Primitives.dll + + + ..\packages\Newtonsoft.Json.11.0.2\lib\net45\Newtonsoft.Json.dll + + + ..\packages\Q42.HueApi.3.7.2\lib\netstandard1.1\Q42.HueApi.dll + + + ..\packages\System.AppContext.4.3.0\lib\net46\System.AppContext.dll + + + + ..\packages\System.Console.4.3.1\lib\net46\System.Console.dll + + + ..\packages\System.Diagnostics.DiagnosticSource.4.5.1\lib\net46\System.Diagnostics.DiagnosticSource.dll + + + ..\packages\System.Globalization.Calendars.4.3.0\lib\net46\System.Globalization.Calendars.dll + + + ..\packages\System.IO.Compression.4.3.0\lib\net46\System.IO.Compression.dll + + + + ..\packages\System.IO.Compression.ZipFile.4.3.0\lib\net46\System.IO.Compression.ZipFile.dll + + + ..\packages\System.IO.FileSystem.4.3.0\lib\net46\System.IO.FileSystem.dll + + + ..\packages\System.IO.FileSystem.Primitives.4.3.0\lib\net46\System.IO.FileSystem.Primitives.dll + + + ..\packages\System.Net.Http.4.3.4\lib\net46\System.Net.Http.dll + + + ..\packages\System.Net.Sockets.4.3.0\lib\net46\System.Net.Sockets.dll + + + + ..\packages\System.Runtime.InteropServices.RuntimeInformation.4.3.0\lib\net45\System.Runtime.InteropServices.RuntimeInformation.dll + + + ..\packages\System.Security.Cryptography.Algorithms.4.3.1\lib\net461\System.Security.Cryptography.Algorithms.dll + + + ..\packages\System.Security.Cryptography.Encoding.4.3.0\lib\net46\System.Security.Cryptography.Encoding.dll + + + ..\packages\System.Security.Cryptography.Primitives.4.3.0\lib\net46\System.Security.Cryptography.Primitives.dll + + + ..\packages\System.Security.Cryptography.X509Certificates.4.3.2\lib\net461\System.Security.Cryptography.X509Certificates.dll + - + + ..\packages\System.Xml.ReaderWriter.4.3.1\lib\net46\System.Xml.ReaderWriter.dll + + + + + + + + + + + + + Dieses Projekt verweist auf mindestens ein NuGet-Paket, das auf diesem Computer fehlt. Verwenden Sie die Wiederherstellung von NuGet-Paketen, um die fehlenden Dateien herunterzuladen. Weitere Informationen finden Sie unter "http://go.microsoft.com/fwlink/?LinkID=322105". Die fehlende Datei ist "{0}". + + + \ No newline at end of file diff --git a/HueHookServer/HueParameters.cs b/HueHook/HueParameters.cs similarity index 97% rename from HueHookServer/HueParameters.cs rename to HueHook/HueParameters.cs index f89b918..23a3144 100644 --- a/HueHookServer/HueParameters.cs +++ b/HueHook/HueParameters.cs @@ -4,9 +4,8 @@ using System.Text; using System.Threading.Tasks; -namespace Rca.HueHookServer +namespace Rca.HueHook { - [Obsolete("dev! not in use")] public enum HueParameters { [HueParameterAssignment(HueObjects.Group | HueObjects.Light | HueObjects.Scene)] diff --git a/HueHookServer/BoolParser.cs b/HueHook/Util/BooleanParser.cs similarity index 99% rename from HueHookServer/BoolParser.cs rename to HueHook/Util/BooleanParser.cs index feea04b..1a1ce8e 100644 --- a/HueHookServer/BoolParser.cs +++ b/HueHook/Util/BooleanParser.cs @@ -4,7 +4,7 @@ using System.Text; using System.Threading.Tasks; -namespace Rca.HueHookServer +namespace Rca.HueHook.Util { /// /// Parse strings into true or false bools using relaxed parsing rules diff --git a/HueHook/Util/NameValueCollectionExtensions.cs b/HueHook/Util/NameValueCollectionExtensions.cs new file mode 100644 index 0000000..8c234cf --- /dev/null +++ b/HueHook/Util/NameValueCollectionExtensions.cs @@ -0,0 +1,74 @@ +using Q42.HueApi; +using System; +using System.Collections.Generic; +using System.Collections.Specialized; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Rca.HueHook.Util +{ + public static class NameValueCollectionExtensions + { + public static LightCommand ToLightCommand(this NameValueCollection parameters) + { + Console.ForegroundColor = ConsoleColor.Magenta; + + Console.WriteLine("Id: {0}", parameters["id"]); + + var cmd = new LightCommand() + { + Effect = Effect.None + }; + + if (parameters.AllKeys.Contains("on")) + { + cmd.On = parameters["on"].ToBoolean(); + Console.WriteLine("On: {0}", cmd.On); + } + if (parameters.AllKeys.Contains("sat")) + { + int sat = 0; + if (int.TryParse(parameters["sat"], out sat)) + { + cmd.Saturation = sat; + Console.WriteLine("Saturation: {0}", cmd.Saturation); + } + } + if (parameters.AllKeys.Contains("hue")) + { + int hue = 0; + if (int.TryParse(parameters["hue"], out hue)) + { + cmd.Hue = hue; + Console.WriteLine("Hue: {0}", cmd.Hue); + } + } + if (parameters.AllKeys.Contains("bri")) + { + byte bri = 0; + if (byte.TryParse(parameters["bri"], out bri)) + { + cmd.Brightness = bri; + Console.WriteLine("Brightness: {0}", cmd.Brightness); + } + } + if (parameters.AllKeys.Contains("ct")) + { + int ct = 153; + if (int.TryParse(parameters["ct"], out ct)) + { + if (ct >= 153 && ct <= 500) + { + cmd.ColorTemperature = ct; + Console.WriteLine("ColorTemperature: {0}", cmd.ColorTemperature); + } + } + } + + Console.ResetColor(); + + return cmd; + } + } +} diff --git a/HueHook/app.config b/HueHook/app.config new file mode 100644 index 0000000..8ce0d09 --- /dev/null +++ b/HueHook/app.config @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/HueHook/packages.config b/HueHook/packages.config new file mode 100644 index 0000000..280759a --- /dev/null +++ b/HueHook/packages.config @@ -0,0 +1,51 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/HueHookServer/App.config b/HueHookServer/App.config index b84934b..e15102e 100644 --- a/HueHookServer/App.config +++ b/HueHookServer/App.config @@ -11,7 +11,7 @@ - + diff --git a/HueHookServer/HookReceiver.cs b/HueHookServer/HookReceiver.cs index 6dd4afe..8704862 100644 --- a/HueHookServer/HookReceiver.cs +++ b/HueHookServer/HookReceiver.cs @@ -1,4 +1,6 @@ using Q42.HueApi; +using Rca.HueHook; +using Rca.HueHook.Util; using SmartHttpServer; using System; using System.Collections.Generic; @@ -157,68 +159,4 @@ IPAddress getRemoteIp(HttpProcessor p) #endregion Events } - - public static class NameValueCollectionExtensions - { - public static LightCommand ToLightCommand(this NameValueCollection parameters) - { - Console.ForegroundColor = ConsoleColor.Magenta; - - Console.WriteLine("Id: {0}", parameters["id"]); - - var cmd = new LightCommand() - { - Effect = Effect.None - }; - - if (parameters.AllKeys.Contains("on")) - { - cmd.On = parameters["on"].ToBoolean(); - Console.WriteLine("On: {0}", cmd.On); - } - if (parameters.AllKeys.Contains("sat")) - { - int sat = 0; - if (int.TryParse(parameters["sat"], out sat)) - { - cmd.Saturation = sat; - Console.WriteLine("Saturation: {0}", cmd.Saturation); - } - } - if (parameters.AllKeys.Contains("hue")) - { - int hue = 0; - if (int.TryParse(parameters["hue"], out hue)) - { - cmd.Hue = hue; - Console.WriteLine("Hue: {0}", cmd.Hue); - } - } - if (parameters.AllKeys.Contains("bri")) - { - byte bri = 0; - if (byte.TryParse(parameters["bri"], out bri)) - { - cmd.Brightness = bri; - Console.WriteLine("Brightness: {0}", cmd.Brightness); - } - } - if (parameters.AllKeys.Contains("ct")) - { - int ct = 153; - if (int.TryParse(parameters["ct"], out ct)) - { - if (ct >= 153 && ct <= 500) - { - cmd.ColorTemperature = ct; - Console.WriteLine("ColorTemperature: {0}", cmd.ColorTemperature); - } - } - } - - Console.ResetColor(); - - return cmd; - } - } } diff --git a/HueHookServer/HueHookServer.csproj b/HueHookServer/HueHookServer.csproj index 9b4ad9d..2ae6052 100644 --- a/HueHookServer/HueHookServer.csproj +++ b/HueHookServer/HueHookServer.csproj @@ -11,6 +11,8 @@ v4.6.1 512 true + + AnyCPU @@ -49,12 +51,12 @@ ..\packages\System.AppContext.4.3.0\lib\net46\System.AppContext.dll - - ..\packages\System.Console.4.3.0\lib\net46\System.Console.dll + + ..\packages\System.Console.4.3.1\lib\net46\System.Console.dll - - ..\packages\System.Diagnostics.DiagnosticSource.4.3.0\lib\net46\System.Diagnostics.DiagnosticSource.dll + + ..\packages\System.Diagnostics.DiagnosticSource.4.5.1\lib\net46\System.Diagnostics.DiagnosticSource.dll ..\packages\System.Globalization.Calendars.4.3.0\lib\net46\System.Globalization.Calendars.dll @@ -72,8 +74,8 @@ ..\packages\System.IO.FileSystem.Primitives.4.3.0\lib\net46\System.IO.FileSystem.Primitives.dll - - ..\packages\System.Net.Http.4.3.0\lib\net46\System.Net.Http.dll + + ..\packages\System.Net.Http.4.3.4\lib\net46\System.Net.Http.dll ..\packages\System.Net.Sockets.4.3.0\lib\net46\System.Net.Sockets.dll @@ -83,7 +85,7 @@ ..\packages\System.Runtime.InteropServices.RuntimeInformation.4.3.0\lib\net45\System.Runtime.InteropServices.RuntimeInformation.dll - ..\packages\System.Security.Cryptography.Algorithms.4.3.0\lib\net461\System.Security.Cryptography.Algorithms.dll + ..\packages\System.Security.Cryptography.Algorithms.4.3.1\lib\net461\System.Security.Cryptography.Algorithms.dll ..\packages\System.Security.Cryptography.Encoding.4.3.0\lib\net46\System.Security.Cryptography.Encoding.dll @@ -91,8 +93,8 @@ ..\packages\System.Security.Cryptography.Primitives.4.3.0\lib\net46\System.Security.Cryptography.Primitives.dll - - ..\packages\System.Security.Cryptography.X509Certificates.4.3.0\lib\net461\System.Security.Cryptography.X509Certificates.dll + + ..\packages\System.Security.Cryptography.X509Certificates.4.3.2\lib\net461\System.Security.Cryptography.X509Certificates.dll @@ -101,14 +103,11 @@ - ..\packages\System.Xml.ReaderWriter.4.3.0\lib\net46\System.Xml.ReaderWriter.dll + ..\packages\System.Xml.ReaderWriter.4.3.1\lib\net46\System.Xml.ReaderWriter.dll - - - @@ -126,4 +125,11 @@ + + + + Dieses Projekt verweist auf mindestens ein NuGet-Paket, das auf diesem Computer fehlt. Verwenden Sie die Wiederherstellung von NuGet-Paketen, um die fehlenden Dateien herunterzuladen. Weitere Informationen finden Sie unter "http://go.microsoft.com/fwlink/?LinkID=322105". Die fehlende Datei ist "{0}". + + + \ No newline at end of file diff --git a/HueHookServer/packages.config b/HueHookServer/packages.config index 610b1ff..280759a 100644 --- a/HueHookServer/packages.config +++ b/HueHookServer/packages.config @@ -1,16 +1,16 @@  - + - + - + - + @@ -22,7 +22,7 @@ - + @@ -36,16 +36,16 @@ - + - + - + \ No newline at end of file diff --git a/HueHook_Test/HueHook_Test.csproj b/HueHook_Test/HueHook_Test.csproj index 9baa78d..3e2e263 100644 --- a/HueHook_Test/HueHook_Test.csproj +++ b/HueHook_Test/HueHook_Test.csproj @@ -1,6 +1,6 @@  - + Debug AnyCPU @@ -39,10 +39,10 @@ - ..\packages\MSTest.TestFramework.1.2.1\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll + ..\packages\MSTest.TestFramework.1.3.2\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll - ..\packages\MSTest.TestFramework.1.2.1\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll + ..\packages\MSTest.TestFramework.1.3.2\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll @@ -52,6 +52,7 @@ + @@ -66,8 +67,8 @@ Dieses Projekt verweist auf mindestens ein NuGet-Paket, das auf diesem Computer fehlt. Verwenden Sie die Wiederherstellung von NuGet-Paketen, um die fehlenden Dateien herunterzuladen. Weitere Informationen finden Sie unter "http://go.microsoft.com/fwlink/?LinkID=322105". Die fehlende Datei ist "{0}". - - + + - + \ No newline at end of file diff --git a/HueHook_Test/app.config b/HueHook_Test/app.config new file mode 100644 index 0000000..8ce0d09 --- /dev/null +++ b/HueHook_Test/app.config @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/HueHook_Test/packages.config b/HueHook_Test/packages.config index 0908943..102a45c 100644 --- a/HueHook_Test/packages.config +++ b/HueHook_Test/packages.config @@ -1,5 +1,5 @@  - - + + \ No newline at end of file