[BF] v1.3.4.0 Fixing Json Names
[NF] v1.2.2.0 Mqtt can now get and set values
This commit is contained in:
parent
44b8daa325
commit
75eac65510
@ -59,5 +59,15 @@ namespace ZwayBot {
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,11 @@
|
||||
using System;
|
||||
using System.Text.RegularExpressions;
|
||||
using BlubbFish.IoT.Zway;
|
||||
using BlubbFish.IoT.Zway.Events;
|
||||
using BlubbFish.IoT.Zway.Interfaces;
|
||||
using BlubbFish.Utils;
|
||||
using BlubbFish.Utils.IoT.Connector;
|
||||
using LitJson;
|
||||
|
||||
namespace ZwayBot.Moduls {
|
||||
class Mqtt : AModul, IDisposable {
|
||||
@ -32,8 +34,46 @@ namespace ZwayBot.Moduls {
|
||||
}
|
||||
|
||||
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"));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
using System.Resources;
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Reflection;
|
||||
using System.Resources;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// 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,
|
||||
// übernehmen, indem Sie "*" eingeben:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.2.1.0")]
|
||||
[assembly: AssemblyFileVersion("1.2.1.0")]
|
||||
[assembly: AssemblyVersion("1.2.2.0")]
|
||||
[assembly: AssemblyFileVersion("1.2.2.0")]
|
||||
[assembly: NeutralResourcesLanguage("de-DE")]
|
||||
|
||||
// “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.
Loading…
Reference in New Issue
Block a user