commit bc694f2fd99718c1b57073b0c8ae064a8e5c8276 Author: BlubbFish Date: Tue May 1 21:46:56 2018 +0000 [NF] Hue-Lib fertig [DW] Hue-Bot beginn Arbeit diff --git a/Hue-Bot.sln b/Hue-Bot.sln new file mode 100644 index 0000000..aac4024 --- /dev/null +++ b/Hue-Bot.sln @@ -0,0 +1,55 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.27004.2010 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Hue-Bot", "Hue-Bot\Hue-Bot.csproj", "{4C2F9593-4CF6-47DC-85D3-2D098C404C70}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Hue", "..\Hue\Hue\Hue.csproj", "{738A6137-8FCA-4CE1-BD1C-042B21B6B5F2}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "litjson_4.7.1", "..\Librarys\litjson\litjson\litjson_4.7.1.csproj", "{91A14CD2-2940-4500-8193-56D37EDDDBAA}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Utils", "..\Utils\Utils\Utils.csproj", "{FAC8CE64-BF13-4ECE-8097-AEB5DD060098}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConnectorDataMqtt", "..\Utils\IoT\Connector\Data\Mqtt\ConnectorDataMqtt.csproj", "{EE6C8F68-ED46-4C1C-ABDD-CFCDF75104F2}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Utils-IoT", "..\Utils\IoT\Utils-IoT.csproj", "{B870E4D5-6806-4A0B-B233-8907EEDC5AFC}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {4C2F9593-4CF6-47DC-85D3-2D098C404C70}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4C2F9593-4CF6-47DC-85D3-2D098C404C70}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4C2F9593-4CF6-47DC-85D3-2D098C404C70}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4C2F9593-4CF6-47DC-85D3-2D098C404C70}.Release|Any CPU.Build.0 = Release|Any CPU + {738A6137-8FCA-4CE1-BD1C-042B21B6B5F2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {738A6137-8FCA-4CE1-BD1C-042B21B6B5F2}.Debug|Any CPU.Build.0 = Debug|Any CPU + {738A6137-8FCA-4CE1-BD1C-042B21B6B5F2}.Release|Any CPU.ActiveCfg = Release|Any CPU + {738A6137-8FCA-4CE1-BD1C-042B21B6B5F2}.Release|Any CPU.Build.0 = Release|Any CPU + {91A14CD2-2940-4500-8193-56D37EDDDBAA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {91A14CD2-2940-4500-8193-56D37EDDDBAA}.Debug|Any CPU.Build.0 = Debug|Any CPU + {91A14CD2-2940-4500-8193-56D37EDDDBAA}.Release|Any CPU.ActiveCfg = Release|Any CPU + {91A14CD2-2940-4500-8193-56D37EDDDBAA}.Release|Any CPU.Build.0 = Release|Any CPU + {FAC8CE64-BF13-4ECE-8097-AEB5DD060098}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {FAC8CE64-BF13-4ECE-8097-AEB5DD060098}.Debug|Any CPU.Build.0 = Debug|Any CPU + {FAC8CE64-BF13-4ECE-8097-AEB5DD060098}.Release|Any CPU.ActiveCfg = Release|Any CPU + {FAC8CE64-BF13-4ECE-8097-AEB5DD060098}.Release|Any CPU.Build.0 = Release|Any CPU + {EE6C8F68-ED46-4C1C-ABDD-CFCDF75104F2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {EE6C8F68-ED46-4C1C-ABDD-CFCDF75104F2}.Debug|Any CPU.Build.0 = Debug|Any CPU + {EE6C8F68-ED46-4C1C-ABDD-CFCDF75104F2}.Release|Any CPU.ActiveCfg = Release|Any CPU + {EE6C8F68-ED46-4C1C-ABDD-CFCDF75104F2}.Release|Any CPU.Build.0 = Release|Any CPU + {B870E4D5-6806-4A0B-B233-8907EEDC5AFC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B870E4D5-6806-4A0B-B233-8907EEDC5AFC}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B870E4D5-6806-4A0B-B233-8907EEDC5AFC}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B870E4D5-6806-4A0B-B233-8907EEDC5AFC}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {15702E91-23B8-44F6-9544-A0C8E506A91E} + EndGlobalSection +EndGlobal diff --git a/Hue-Bot/Hue-Bot.csproj b/Hue-Bot/Hue-Bot.csproj new file mode 100644 index 0000000..97fb554 --- /dev/null +++ b/Hue-Bot/Hue-Bot.csproj @@ -0,0 +1,124 @@ + + + + + Debug + AnyCPU + {4C2F9593-4CF6-47DC-85D3-2D098C404C70} + Exe + BlubbFish.IoT.Bot.HueBot + Hue-Bot + v4.7.1 + 512 + true + + publish\ + true + Disk + false + Foreground + 7 + Days + false + false + true + 0 + 1.0.0.%2a + false + false + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + Resources\Icon.ico + + + + + + + + + + + + + + + + + + + + + True + True + Resources.resx + + + + + + + + ResXFileCodeGenerator + Resources.Designer.cs + + + + + + + + {738a6137-8fca-4ce1-bd1c-042b21b6b5f2} + Hue + + + {91a14cd2-2940-4500-8193-56d37edddbaa} + litjson_4.7.1 + + + {ee6c8f68-ed46-4c1c-abdd-cfcdf75104f2} + ConnectorDataMqtt + + + {b870e4d5-6806-4a0b-b233-8907eedc5afc} + Utils-IoT + + + {fac8ce64-bf13-4ece-8097-aeb5dd060098} + Utils + + + + + False + Microsoft .NET Framework 4.6.1 %28x86 und x64%29 + true + + + False + .NET Framework 3.5 SP1 + false + + + + \ No newline at end of file diff --git a/Hue-Bot/Hue-Bot.csproj.user b/Hue-Bot/Hue-Bot.csproj.user new file mode 100644 index 0000000..ca5bf3c --- /dev/null +++ b/Hue-Bot/Hue-Bot.csproj.user @@ -0,0 +1,13 @@ + + + + publish\ + + + + + + de-DE + false + + \ No newline at end of file diff --git a/Hue-Bot/Interfaces/AModul.cs b/Hue-Bot/Interfaces/AModul.cs new file mode 100644 index 0000000..dc1be07 --- /dev/null +++ b/Hue-Bot/Interfaces/AModul.cs @@ -0,0 +1,72 @@ +using System; +using System.Collections.Generic; +using BlubbFish.IoT.Bot.HueBot.lib; +using BlubbFish.IoT.Hue; +using BlubbFish.Utils; + +namespace BlubbFish.IoT.Bot.HueBot.Interfaces { + abstract class AModul { + protected HueController hue; + private InIReader settings; + protected Dictionary> config = new Dictionary>(); + + public Boolean HasConfig { get; private set; } + public Boolean ConfigPublic { get; private set; } + + public delegate void ModulEvent(Object sender, ModulEventArgs e); + public abstract event ModulEvent Update; + + public AModul(HueController huec, InIReader settings) { + this.HasConfig = false; + this.ConfigPublic = false; + this.hue = huec; + this.settings = settings; + this.ParseConfig(); + } + + private void ParseConfig() { + if (this.settings != null) { + this.HasConfig = true; + foreach (String item in this.settings.GetSections(false)) { + this.config.Add(item, this.settings.GetSection(item)); + } + if (this.config.ContainsKey("modul")) { + this.ConfigPublic = this.config["modul"].ContainsKey("config") && this.config["modul"]["config"].ToLower() == "public"; + } + } + } + + public Dictionary> GetConfig() { + if (this.HasConfig && this.ConfigPublic) { + Dictionary> ret = new Dictionary>(this.config); + if (ret.ContainsKey("modul")) { + ret.Remove("modul"); + } + return ret; + } + return new Dictionary>(); + } + + public virtual void Interconnect(Dictionary moduls) { } + + public virtual void SetInterconnection(String param, Action hook, Object data) { } + + public abstract void Dispose(); + + internal void SetConfig(Dictionary> newconf) { + if (this.HasConfig && this.ConfigPublic) { + if (newconf.ContainsKey("modul")) { + newconf.Remove("modul"); + } + if (this.config.ContainsKey("modul")) { + newconf.Add("modul", this.config["modul"]); + } + this.config = newconf; + this.settings.SetSections(this.config); + this.UpdateConfig(); + } + } + + protected abstract void UpdateConfig(); + } +} diff --git a/Hue-Bot/Moduls/Mqtt.cs b/Hue-Bot/Moduls/Mqtt.cs new file mode 100644 index 0000000..4537555 --- /dev/null +++ b/Hue-Bot/Moduls/Mqtt.cs @@ -0,0 +1,139 @@ +using System; +using System.Collections.Generic; +using System.Text.RegularExpressions; +using BlubbFish.IoT.Bot.HueBot.Interfaces; +using BlubbFish.IoT.Bot.HueBot.lib; +using BlubbFish.IoT.Hue; +using BlubbFish.IoT.Hue.Events; +using BlubbFish.IoT.Hue.Interfaces; +using BlubbFish.Utils; +using BlubbFish.Utils.IoT.Connector; +using LitJson; + +namespace BlubbFish.IoT.Bot.HueBot.Moduls { + class Mqtt : AModul, IDisposable { + private ADataBackend mqtt; + private Dictionary modules; + + public override event ModulEvent Update; + + public Mqtt(HueController hue, InIReader settings) : base(hue, settings) { + if (this.config.ContainsKey("settings")) { + this.mqtt = ADataBackend.GetInstance(this.config["settings"]); + this.mqtt.MessageIncomming += this.Mqtt_MessageIncomming; + this.hue.Update += this.ZwayEvent; + } + } + + private void ZwayEvent(Object sender, AllUpdateEvent e) { + String topic = ""; + String data = ""; + if (e.Parent.GetType().HasInterface("IMqtt")) { + IMqtt sensor = (IMqtt)e.Parent; + topic = "/hue/" + sensor.MqttTopic(); + data = sensor.ToJson(); + } + if (topic != "" && data != "") { + this.mqtt.Send(topic, data); + this.Update?.Invoke(this, new MqttEvent(topic, data)); + } + } + + private void Mqtt_MessageIncomming(Object sender, MqttEventArgs e) { + if (e.Topic.StartsWith("/hue/") && (e.Topic.EndsWith("/set") || e.Topic.EndsWith("/get"))) { + /*Match m = new Regex("^/zwavebot/devices/(\\d+)/(\\d+)/(\\d+)/[gs]et$|^/zwavebot/devices/(\\d+)/(\\d+)/(\\d+)/(\\d+)/[gs]et$").Match(e.Topic); + String id = ""; + if (m.Groups[1].Success) { + id = m.Groups[1].Value + "-" + m.Groups[2].Value + "-" + m.Groups[3].Value; + } + if (m.Groups[4].Success) { + id = m.Groups[4].Value + "-" + m.Groups[5].Value + "-" + m.Groups[6].Value + "-" + m.Groups[7].Value; + } + ACommandClass c = this.zw.GetCommandClass(id); + if (c == null) { + return; + } + if (e.Topic.EndsWith("/set")) { + try { + JsonData a = JsonMapper.ToObject(e.Message); + foreach (String item in a.Keys) { + String key = item.ToUpperLower(); + if (c.HasProperty(key)) { + c.SetProperty(key, a[item].ToString()); + this.Update?.Invoke(this, new MqttEvent(c.Id, a[item].ToString())); + } + } + } catch (Exception) { } + } else if (e.Topic.EndsWith("/get")) { + c.PollOnce = true; + this.mqtt.Send("/zwavebot/devices/" + c.MqttTopic(), c.ToJson()); + this.Update?.Invoke(this, new MqttEvent(e.Topic, "Dataget")); + }*/ + } + if (e.Topic.StartsWith("/hue/config/") && (e.Topic.EndsWith("/set") || e.Topic.EndsWith("/get"))) { + Match m = new Regex("^/hue/config/(\\w+)/[gs]et$|").Match(e.Topic); + if (!m.Groups[1].Success) { + return; + } + AModul modul = null; + foreach (KeyValuePair item in this.modules) { + if (item.Key.ToLower() == m.Groups[1].Value) { + modul = item.Value; + } + } + if (modul == null) { + return; + } + if (e.Topic.EndsWith("/get") && modul.HasConfig && modul.ConfigPublic) { + String topic = "/hue/config/" + m.Groups[1].Value; + String data = JsonMapper.ToJson(modul.GetConfig()).ToString(); + this.mqtt.Send(topic, data); + this.Update?.Invoke(this, new MqttEvent(topic, data)); + } + if (e.Topic.EndsWith("/set") && modul.HasConfig && modul.ConfigPublic) { + try { + JsonData a = JsonMapper.ToObject(e.Message); + Dictionary> newconf = new Dictionary>(); + foreach (String section in a.Keys) { + Dictionary sectiondata = new Dictionary(); + foreach (String item in a[section].Keys) { + sectiondata.Add(item, a[section][item].ToString()); + } + newconf.Add(section, sectiondata); + } + modul.SetConfig(newconf); + this.Update?.Invoke(this, new MqttEvent("New Config", "Write")); + } catch (Exception) { } + } + } + } + + public override void Interconnect(Dictionary moduls) { + this.modules = moduls; + } + + protected override void UpdateConfig() { } + + #region IDisposable Support + private Boolean disposedValue = false; + + protected virtual void Dispose(Boolean disposing) { + if (!this.disposedValue) { + if (disposing) { + this.mqtt.Dispose(); + } + this.disposedValue = true; + } + } + + ~Mqtt() { + Dispose(false); + } + + public override void Dispose() { + Dispose(true); + GC.SuppressFinalize(this); + } + #endregion + } +} diff --git a/Hue-Bot/Program.cs b/Hue-Bot/Program.cs new file mode 100644 index 0000000..0c46fdb --- /dev/null +++ b/Hue-Bot/Program.cs @@ -0,0 +1,88 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Reflection; +using BlubbFish.IoT.Bot.HueBot.Interfaces; +using BlubbFish.IoT.Bot.HueBot.lib; +using BlubbFish.IoT.Hue; +using BlubbFish.IoT.Hue.Events; +using BlubbFish.Utils; + +namespace BlubbFish.IoT.Bot.HueBot { + class Program { + static void Main(String[] args) => new Program(args); + + private HueController hue; + private Dictionary moduls = new Dictionary(); + public Program(String[] args) { + if (!File.Exists("settings.ini")) { + Helper.WriteError("No settings.ini found. Abord!"); + return; + } + this.hue = new HueController(InIReader.GetInstance("settings.ini").GetSection("hue")); + this.hue.Update += this.HueDataUpdate; + this.ModulLoader(); + this.ModulInterconnect(); + this.ModulEvents(); + this.WaitForShutdown(); + this.ModulDispose(); + } + + private void ModulLoader() { + Assembly asm = Assembly.GetExecutingAssembly(); + foreach (Type item in asm.GetTypes()) { + if (item.Namespace == "BlubbFish.IoT.Bot.HueBot.Moduls") { + Type t = item; + String name = t.Name; + if (File.Exists(name.ToLower() + ".ini")) { + this.moduls.Add(name, (AModul)t.GetConstructor(new Type[] { typeof(HueController), typeof(InIReader) }).Invoke(new Object[] { this.hue, InIReader.GetInstance(name.ToLower() + ".ini") })); + Console.WriteLine("Load Modul " + name); + } else if (t.HasInterface("IForceLoad")) { + this.moduls.Add(name, (AModul)t.GetConstructor(new Type[] { typeof(HueController), typeof(InIReader) }).Invoke(new Object[] { this.hue, null })); + Console.WriteLine("Load Modul Forced " + name); + } + } + } + } + + private void ModulInterconnect() { + foreach (KeyValuePair item in this.moduls) { + item.Value.Interconnect(this.moduls); + } + } + + private void ModulEvents() { + foreach (KeyValuePair item in this.moduls) { + item.Value.Update += this.ModulUpdate; + } + } + + private void WaitForShutdown() { + while (true) { + System.Threading.Thread.Sleep(100); + if (Console.KeyAvailable) { + ConsoleKeyInfo key = Console.ReadKey(false); + if (key.Key == ConsoleKey.Escape) { + break; + } + } + } + } + + private void ModulDispose() { + foreach (KeyValuePair item in this.moduls) { + item.Value.Dispose(); + Console.WriteLine("Modul entladen: " + item.Key); + } + this.hue.Dispose(); + } + + private void HueDataUpdate(Object sender, AllUpdateEvent e) { + Console.WriteLine("-> Hue [" + e.UpdateTime + "]: " + e.Parent.ToString()); + } + + private void ModulUpdate(Object sender, ModulEventArgs e) { + Console.WriteLine(e.ToString()); + } + } +} diff --git a/Hue-Bot/Properties/AssemblyInfo.cs b/Hue-Bot/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..6050e60 --- /dev/null +++ b/Hue-Bot/Properties/AssemblyInfo.cs @@ -0,0 +1,39 @@ +using System.Resources; +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// Allgemeine Informationen über eine Assembly werden über die folgenden +// Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern, +// die einer Assembly zugeordnet sind. +[assembly: AssemblyTitle("Hue-Bot")] +[assembly: AssemblyDescription("Is a Bot for Hue Devices")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("BlubbFish")] +[assembly: AssemblyProduct("Hue-Bot")] +[assembly: AssemblyCopyright("Copyright © 2018 - 15.04.2018")] +[assembly: AssemblyTrademark("BlubbFish")] +[assembly: AssemblyCulture("")] + +// Durch Festlegen von ComVisible auf FALSE werden die Typen in dieser Assembly +// für COM-Komponenten unsichtbar. Wenn Sie auf einen Typ in dieser Assembly von +// COM aus zugreifen müssen, sollten Sie das ComVisible-Attribut für diesen Typ auf "True" festlegen. +[assembly: ComVisible(false)] + +// Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird +[assembly: Guid("4c2f9593-4cf6-47dc-85d3-2d098c404c70")] + +// Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten: +// +// Hauptversion +// Nebenversion +// Buildnummer +// Revision +// +// Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden, +// übernehmen, indem Sie "*" eingeben: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] +[assembly: NeutralResourcesLanguage("de-DE")] + diff --git a/Hue-Bot/Properties/Resources.Designer.cs b/Hue-Bot/Properties/Resources.Designer.cs new file mode 100644 index 0000000..d79e800 --- /dev/null +++ b/Hue-Bot/Properties/Resources.Designer.cs @@ -0,0 +1,73 @@ +//------------------------------------------------------------------------------ +// +// Dieser Code wurde von einem Tool generiert. +// Laufzeitversion:4.0.30319.42000 +// +// Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn +// der Code erneut generiert wird. +// +//------------------------------------------------------------------------------ + +namespace BlubbFish.IoT.Bot.HueBot.Properties { + using System; + + + /// + /// Eine stark typisierte Ressourcenklasse zum Suchen von lokalisierten Zeichenfolgen usw. + /// + // Diese Klasse wurde von der StronglyTypedResourceBuilder automatisch generiert + // -Klasse über ein Tool wie ResGen oder Visual Studio automatisch generiert. + // Um einen Member hinzuzufügen oder zu entfernen, bearbeiten Sie die .ResX-Datei und führen dann ResGen + // mit der /str-Option erneut aus, oder Sie erstellen Ihr VS-Projekt neu. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "15.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() { + } + + /// + /// Gibt die zwischengespeicherte ResourceManager-Instanz zurück, die von dieser Klasse verwendet wird. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("BlubbFish.IoT.Bot.HueBot.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Überschreibt die CurrentUICulture-Eigenschaft des aktuellen Threads für alle + /// Ressourcenzuordnungen, die diese stark typisierte Ressourcenklasse verwenden. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + /// + /// Sucht eine lokalisierte Ressource vom Typ System.Drawing.Icon ähnlich wie (Symbol). + /// + internal static System.Drawing.Icon Icon { + get { + object obj = ResourceManager.GetObject("Icon", resourceCulture); + return ((System.Drawing.Icon)(obj)); + } + } + } +} diff --git a/Hue-Bot/Properties/Resources.resx b/Hue-Bot/Properties/Resources.resx new file mode 100644 index 0000000..653c9e8 --- /dev/null +++ b/Hue-Bot/Properties/Resources.resx @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + + ..\Resources\Icon.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + \ No newline at end of file diff --git a/Hue-Bot/Resources/Icon.ico b/Hue-Bot/Resources/Icon.ico new file mode 100644 index 0000000..241c871 Binary files /dev/null and b/Hue-Bot/Resources/Icon.ico differ diff --git a/Hue-Bot/Resources/Icon.png b/Hue-Bot/Resources/Icon.png new file mode 100644 index 0000000..f367b5d Binary files /dev/null and b/Hue-Bot/Resources/Icon.png differ diff --git a/Hue-Bot/bin/Release/ConnectorDataMqtt.dll b/Hue-Bot/bin/Release/ConnectorDataMqtt.dll new file mode 100644 index 0000000..fcf01f5 Binary files /dev/null and b/Hue-Bot/bin/Release/ConnectorDataMqtt.dll differ diff --git a/Hue-Bot/bin/Release/Hue-Bot.exe b/Hue-Bot/bin/Release/Hue-Bot.exe new file mode 100644 index 0000000..245436e Binary files /dev/null and b/Hue-Bot/bin/Release/Hue-Bot.exe differ diff --git a/Hue-Bot/bin/Release/Hue.dll b/Hue-Bot/bin/Release/Hue.dll new file mode 100644 index 0000000..f73a4a4 Binary files /dev/null and b/Hue-Bot/bin/Release/Hue.dll differ diff --git a/Hue-Bot/bin/Release/M2Mqtt.Net.dll b/Hue-Bot/bin/Release/M2Mqtt.Net.dll new file mode 100644 index 0000000..154580d Binary files /dev/null and b/Hue-Bot/bin/Release/M2Mqtt.Net.dll differ diff --git a/Hue-Bot/bin/Release/Utils-IoT.dll b/Hue-Bot/bin/Release/Utils-IoT.dll new file mode 100644 index 0000000..025e3da Binary files /dev/null and b/Hue-Bot/bin/Release/Utils-IoT.dll differ diff --git a/Hue-Bot/bin/Release/Utils.dll b/Hue-Bot/bin/Release/Utils.dll new file mode 100644 index 0000000..0fe042f Binary files /dev/null and b/Hue-Bot/bin/Release/Utils.dll differ diff --git a/Hue-Bot/bin/Release/litjson.dll b/Hue-Bot/bin/Release/litjson.dll new file mode 100644 index 0000000..892f38a Binary files /dev/null and b/Hue-Bot/bin/Release/litjson.dll differ diff --git a/Hue-Bot/lib/Events.cs b/Hue-Bot/lib/Events.cs new file mode 100644 index 0000000..9117178 --- /dev/null +++ b/Hue-Bot/lib/Events.cs @@ -0,0 +1,72 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlubbFish.IoT.Bot.HueBot.lib { + public class CronEvent : ModulEventArgs { + + public CronEvent() { + } + + public CronEvent(String addr, String prop, String value) { + this.Address = addr; + this.Property = prop; + this.Value = value; + this.Source = "Cronjob"; + } + } + public class OvertakerEvent : ModulEventArgs { + + public OvertakerEvent() { + } + + public OvertakerEvent(String addr, String prop, String value) { + this.Address = addr; + this.Property = prop; + this.Value = value; + this.Source = "Overtaker"; + } + } + + public class MqttEvent : ModulEventArgs { + public MqttEvent() { + } + public MqttEvent(String topic, String text) { + this.Address = topic; + this.Value = text; + this.Source = "MQTT"; + } + public override String ToString() { + return this.Source + ": on " + this.Address + " set " + this.Value; + } + } + + public class StatusPollingEvent : ModulEventArgs { + public StatusPollingEvent() { + } + + public StatusPollingEvent(String text, String node) { + this.Value = text; + this.Address = node; + this.Source = "POLLING"; + } + + public override String ToString() { + return this.Source + ": " + this.Value + " on " + this.Address; + } + } + + public class ModulEventArgs : EventArgs { + public ModulEventArgs() { + } + public String Address { get; protected set; } + public String Property { get; protected set; } + public String Value { get; protected set; } + public String Source { get; protected set; } + public override String ToString() { + return this.Source + ": " + this.Address + " set " + this.Property + " to " + this.Value; + } + } +} diff --git a/Hue-Bot/lib/Helper.cs b/Hue-Bot/lib/Helper.cs new file mode 100644 index 0000000..bb4f905 --- /dev/null +++ b/Hue-Bot/lib/Helper.cs @@ -0,0 +1,73 @@ +using System; +using System.Reflection; + +namespace BlubbFish.IoT.Bot.HueBot.lib { + static class Helper { + public static void SetProperty(this Object o, String name, String value) { + PropertyInfo prop = o.GetType().GetProperty(name); + if (prop.CanWrite) { + if (prop.PropertyType == typeof(Boolean) && Boolean.TryParse(value, out Boolean vb)) { + prop.SetValue(o, vb); + } else if (prop.PropertyType == typeof(Int32) && Int32.TryParse(value, out Int32 v32)) { + prop.SetValue(o, v32); + } else if (prop.PropertyType == typeof(Single) && Single.TryParse(value, out Single vs)) { + prop.SetValue(o, vs); + } else if (prop.PropertyType == typeof(Double) && Double.TryParse(value, out Double vd)) { + prop.SetValue(o, vd); + } else if (prop.PropertyType == typeof(Int64) && Int64.TryParse(value, out Int64 v64)) { + prop.SetValue(o, v64); + } + } + } + + internal static Boolean HasProperty(this Object o, String type) { + Type t = o.GetType(); + foreach (PropertyInfo item in t.GetProperties()) { + if (item.Name == type) { + return true; + } + } + return false; + } + + internal static Object GetProperty(this Object o, String name) { + PropertyInfo prop = o.GetType().GetProperty(name); + if (prop.CanRead) { + return prop.GetValue(o); + } + return null; + } + + internal static Boolean HasAbstract(this Object o, Type type) { + if (o.GetType().BaseType == type) { + return true; + } + return false; + } + + internal static Boolean HasInterface(this Type o, String type) { + foreach (Type item in o.GetInterfaces()) { + if (item.Name == type) { + return true; + } + } + return false; + } + + internal static void WriteError(String text) { + Console.ForegroundColor = ConsoleColor.Red; + Console.Error.WriteLine("ERROR: " + text); + Console.ResetColor(); + } + + internal static String ToUpperLower(this String s) { + if (s.Length == 0) { + return ""; + } + if (s.Length == 1) { + return s.ToUpper(); + } + return s[0].ToString().ToUpper() + s.Substring(1).ToLower(); + } + } +}