diff --git a/Hue-Bot.sln b/Hue-Bot.sln index aac4024..d4b7856 100644 --- a/Hue-Bot.sln +++ b/Hue-Bot.sln @@ -15,6 +15,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConnectorDataMqtt", "..\Uti EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Utils-IoT", "..\Utils\IoT\Utils-IoT.csproj", "{B870E4D5-6806-4A0B-B233-8907EEDC5AFC}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "M2Mqtt", "..\Librarys\mqtt\M2Mqtt\M2Mqtt.csproj", "{A11AEF5A-B246-4FE8-8330-06DB73CC8074}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -45,6 +47,10 @@ Global {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 + {A11AEF5A-B246-4FE8-8330-06DB73CC8074}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A11AEF5A-B246-4FE8-8330-06DB73CC8074}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A11AEF5A-B246-4FE8-8330-06DB73CC8074}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A11AEF5A-B246-4FE8-8330-06DB73CC8074}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Hue-Bot/Hue-Bot.csproj b/Hue-Bot/Hue-Bot.csproj index 97fb554..b8bb41c 100644 --- a/Hue-Bot/Hue-Bot.csproj +++ b/Hue-Bot/Hue-Bot.csproj @@ -74,9 +74,6 @@ Resources.resx - - - ResXFileCodeGenerator diff --git a/Hue-Bot/Moduls/Mqtt.cs b/Hue-Bot/Moduls/Mqtt.cs index 4537555..00eac4d 100644 --- a/Hue-Bot/Moduls/Mqtt.cs +++ b/Hue-Bot/Moduls/Mqtt.cs @@ -41,15 +41,26 @@ namespace BlubbFish.IoT.Bot.HueBot.Moduls { 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); + //return "sensor/" + this.SensorId; (Int32) + //return "scene/" + this.SceneId; (String) + //return "light/" + this.LightId; (Int32) + //return "group/" + this.GroupId; (Int32) + //return "config"; + Match m = new Regex("^/hue/(config)/[gs]et$|^/hue/(scene)/([^/]+)/[gs]et$|^/hue/(sensor|light|group)/(\\d+)/[gs]et$").Match(e.Topic); + String type = ""; String id = ""; if (m.Groups[1].Success) { - id = m.Groups[1].Value + "-" + m.Groups[2].Value + "-" + m.Groups[3].Value; + type = m.Groups[1].Value; + } + if (m.Groups[2].Success) { + type = m.Groups[2].Value; + id = 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; + type = m.Groups[4].Value; + id = m.Groups[5].Value; } - ACommandClass c = this.zw.GetCommandClass(id); + AConnector c = this.hue.GetConnector(type, id); if (c == null) { return; } @@ -60,18 +71,18 @@ namespace BlubbFish.IoT.Bot.HueBot.Moduls { 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())); + this.Update?.Invoke(this, new MqttEvent(type + " " + 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.mqtt.Send("/hue/" + ((IMqtt)c).MqttTopic(), ((IMqtt)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 (e.Topic.StartsWith("/huebot/config/") && (e.Topic.EndsWith("/set") || e.Topic.EndsWith("/get"))) { + Match m = new Regex("^/huebot/config/(\\w+)/[gs]et$|").Match(e.Topic); if (!m.Groups[1].Success) { return; } @@ -85,7 +96,7 @@ namespace BlubbFish.IoT.Bot.HueBot.Moduls { return; } if (e.Topic.EndsWith("/get") && modul.HasConfig && modul.ConfigPublic) { - String topic = "/hue/config/" + m.Groups[1].Value; + String topic = "/huebot/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)); diff --git a/Hue-Bot/bin/Release/ConnectorDataMqtt.dll b/Hue-Bot/bin/Release/ConnectorDataMqtt.dll index fcf01f5..ef7007b 100644 Binary files a/Hue-Bot/bin/Release/ConnectorDataMqtt.dll 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 index 245436e..ddb356e 100644 Binary files a/Hue-Bot/bin/Release/Hue-Bot.exe 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 index f73a4a4..30deab9 100644 Binary files a/Hue-Bot/bin/Release/Hue.dll 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 deleted file mode 100644 index 154580d..0000000 Binary files a/Hue-Bot/bin/Release/M2Mqtt.Net.dll and /dev/null differ diff --git a/Hue-Bot/bin/Release/M2Mqtt.dll b/Hue-Bot/bin/Release/M2Mqtt.dll new file mode 100644 index 0000000..dcbbb88 Binary files /dev/null and b/Hue-Bot/bin/Release/M2Mqtt.dll differ diff --git a/Hue-Bot/bin/Release/Utils-IoT.dll b/Hue-Bot/bin/Release/Utils-IoT.dll index 025e3da..88af254 100644 Binary files a/Hue-Bot/bin/Release/Utils-IoT.dll 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 index 0fe042f..1153098 100644 Binary files a/Hue-Bot/bin/Release/Utils.dll 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 index 892f38a..d2229a7 100644 Binary files a/Hue-Bot/bin/Release/litjson.dll and b/Hue-Bot/bin/Release/litjson.dll differ diff --git a/Hue-Bot/lib/Helper.cs b/Hue-Bot/lib/Helper.cs index bb4f905..debd498 100644 --- a/Hue-Bot/lib/Helper.cs +++ b/Hue-Bot/lib/Helper.cs @@ -8,6 +8,8 @@ namespace BlubbFish.IoT.Bot.HueBot.lib { if (prop.CanWrite) { if (prop.PropertyType == typeof(Boolean) && Boolean.TryParse(value, out Boolean vb)) { prop.SetValue(o, vb); + } else if (prop.PropertyType == typeof(Byte) && Byte.TryParse(value, out Byte v8)) { + prop.SetValue(o, v8); } 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)) { @@ -16,6 +18,10 @@ namespace BlubbFish.IoT.Bot.HueBot.lib { prop.SetValue(o, vd); } else if (prop.PropertyType == typeof(Int64) && Int64.TryParse(value, out Int64 v64)) { prop.SetValue(o, v64); + } else if (prop.PropertyType.BaseType == typeof(Enum)) { + try { + prop.SetValue(o, Enum.Parse(prop.PropertyType, value)); + } catch (Exception) { } } } }