Compare commits

..
4 Commits
Author SHA1 Message Date
BlubbFish 75eac65510 [BF] v1.3.4.0 Fixing Json Names
[NF] v1.2.2.0 Mqtt can now get and set values
2017-12-19 20:18:30 +00:00
BlubbFish 44b8daa325 [BF] v.1.3.3 fixing polling once bug 2017-12-19 17:33:31 +00:00
BlubbFish 2cd2c7c02e [BF] v1.3.1.0 Forgot some settings, now configuration setting also works again 2017-12-18 16:02:18 +00:00
BlubbFish 33b1b6527c [NF] Tiny fix for mqtt 2017-12-17 21:53:16 +00:00
9 changed files with 58 additions and 7 deletions
+12
View File
@@ -12,6 +12,8 @@ namespace ZwayBot {
prop.SetValue(o, v32); prop.SetValue(o, v32);
} else if (prop.PropertyType == typeof(Single) && Single.TryParse(value, out Single vs)) { } else if (prop.PropertyType == typeof(Single) && Single.TryParse(value, out Single vs)) {
prop.SetValue(o, 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)) { } else if (prop.PropertyType == typeof(Int64) && Int64.TryParse(value, out Int64 v64)) {
prop.SetValue(o, v64); prop.SetValue(o, v64);
} }
@@ -57,5 +59,15 @@ namespace ZwayBot {
Console.Error.WriteLine("ERROR: " + text); Console.Error.WriteLine("ERROR: " + text);
Console.ResetColor(); 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();
}
} }
} }
+42 -2
View File
@@ -1,9 +1,11 @@
using System; using System;
using System.Text.RegularExpressions;
using BlubbFish.IoT.Zway; using BlubbFish.IoT.Zway;
using BlubbFish.IoT.Zway.Events; using BlubbFish.IoT.Zway.Events;
using BlubbFish.IoT.Zway.Interfaces; using BlubbFish.IoT.Zway.Interfaces;
using BlubbFish.Utils; using BlubbFish.Utils;
using BlubbFish.Utils.IoT.Connector; using BlubbFish.Utils.IoT.Connector;
using LitJson;
namespace ZwayBot.Moduls { namespace ZwayBot.Moduls {
class Mqtt : AModul, IDisposable { class Mqtt : AModul, IDisposable {
@@ -32,8 +34,46 @@ namespace ZwayBot.Moduls {
} }
private void Mqtt_MessageIncomming(Object sender, MqttEventArgs e) { private void Mqtt_MessageIncomming(Object sender, MqttEventArgs e) {
if(e.Message.StartsWith("/zwavebot/devices/") && e.Message.EndsWith("set")) { if (e.Topic.StartsWith("/zwavebot/devices/") && e.Topic.EndsWith("set")) {
Match m = new Regex("^/zwavebot/devices/(\\d+)/(\\d+)/(\\d+)/set$|^/zwavebot/devices/(\\d+)/(\\d+)/(\\d+)/(\\d+)/set$").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;
}
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) { }
}
if(e.Topic.StartsWith("/zwavebot/devices/") && e.Topic.EndsWith("get")) {
Match m = new Regex("^/zwavebot/devices/(\\d+)/(\\d+)/(\\d+)/get$|^/zwavebot/devices/(\\d+)/(\\d+)/(\\d+)/(\\d+)/get$").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;
}
c.PollOnce = true;
this.mqtt.Send("/zwavebot/devices/" + c.MqttTopic(), c.ToJson());
this.Update?.Invoke(this, new MqttEvent(e.Topic, "Dataget"));
} }
} }
+4 -5
View File
@@ -1,6 +1,5 @@
using System.Resources; using System.Reflection;
using System.Reflection; using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
// Allgemeine Informationen über eine Assembly werden über die folgenden // Allgemeine Informationen über eine Assembly werden über die folgenden
@@ -33,8 +32,8 @@ using System.Runtime.InteropServices;
// Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden, // Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden,
// übernehmen, indem Sie "*" eingeben: // übernehmen, indem Sie "*" eingeben:
// [assembly: AssemblyVersion("1.0.*")] // [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.2.0.0")] [assembly: AssemblyVersion("1.2.2.0")]
[assembly: AssemblyFileVersion("1.2.0.0")] [assembly: AssemblyFileVersion("1.2.2.0")]
[assembly: NeutralResourcesLanguage("de-DE")] [assembly: NeutralResourcesLanguage("de-DE")]
// “Internet Of Things” icon by By Michael Wohlwend, US, from thenounproject.com. // “Internet Of Things” icon by By Michael Wohlwend, US, from thenounproject.com.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.