From 8dd8605d73db7f1e7a2a02769c74ad3b423c5236 Mon Sep 17 00:00:00 2001 From: BlubbFish Date: Fri, 29 Dec 2017 13:09:52 +0000 Subject: [PATCH] [DW] Alarmsensor added --- Zway/Devices/CommandClasses/AlarmSensor.cs | 62 ++++++++++++++++++ .../CommandClassSubs/Alarmsensorsub.cs | 64 +++++++++++++++++++ Zway/Interfaces/ACommandClass.cs | 6 +- Zway/Zway.csproj | 8 ++- Zway/packages.config | 2 +- 5 files changed, 135 insertions(+), 7 deletions(-) create mode 100644 Zway/Devices/CommandClasses/AlarmSensor.cs create mode 100644 Zway/Devices/CommandClasses/CommandClassSubs/Alarmsensorsub.cs diff --git a/Zway/Devices/CommandClasses/AlarmSensor.cs b/Zway/Devices/CommandClasses/AlarmSensor.cs new file mode 100644 index 0000000..486024c --- /dev/null +++ b/Zway/Devices/CommandClasses/AlarmSensor.cs @@ -0,0 +1,62 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Text.RegularExpressions; +using BlubbFish.IoT.Zway.Devices.CommandClasses.CommandClassSubs; +using BlubbFish.IoT.Zway.Events; +using BlubbFish.IoT.Zway.Interfaces; +using BlubbFish.IoT.Zway.lib; +using LitJson; + +namespace BlubbFish.IoT.Zway.Devices.CommandClasses { + /// + /// 50 = Meter + /// + public class Alarmsensor : ACommandClass { + public override event UpdatedValue Update; + + public Alarmsensor(JsonData json, Tuple id, HttpConnection http, Boolean polling) : base(json, id, http, polling) { + this.HasSub = true; + this.InitComplex(json); + foreach (KeyValuePair item in this.Sub) { + item.Value.Update += this.DeviceUpdate; + } + } + + private void DeviceUpdate(Object sender, DeviceUpdateEvent e) { + this.Update?.Invoke(this, e); + } + + internal override void SetUpdate(JsonData json, Match match) { + if (match.Groups[4].Value.StartsWith(".data.")) { + Int32 subid = Int32.Parse(match.Groups[5].Value); + if (this.Sub.ContainsKey(subid)) { + this.Sub[subid].SetUpdate(json, match); + } + } else { + Helper.WriteError("Kenne in " + this.Name + " [" + this.Id + "] " + match.Groups[4].Value + " nicht!"); + } + } + + private void InitComplex(JsonData json) { + if (json.Keys.Contains("data")) { + JsonData data = json["data"]; + Dictionary subs = new Dictionary(); + foreach (String item in data.Keys) { + if (Int32.TryParse(item, out Int32 subid) && + data[item].Keys.Contains("srcId") && + data[item].Keys.Contains("sensorState") && + data[item].Keys.Contains("sensorTime") && + data[item].Keys.Contains("typeString")) { + subs.Add(subid, new Alarmsensorsub(data[item], new Tuple(this.DeviceId, this.Instance, this.Commandclass, subid), this.http, this.Polling)); + } + } + this.Sub = new ReadOnlyDictionary(subs); + } + } + + internal override void Poll() => this.PollSubGlobal(); + + public override Dictionary ToDictionary() => this.ToDictionarySub(); + } +} diff --git a/Zway/Devices/CommandClasses/CommandClassSubs/Alarmsensorsub.cs b/Zway/Devices/CommandClasses/CommandClassSubs/Alarmsensorsub.cs new file mode 100644 index 0000000..a72b2f4 --- /dev/null +++ b/Zway/Devices/CommandClasses/CommandClassSubs/Alarmsensorsub.cs @@ -0,0 +1,64 @@ +using System; +using System.Collections.Generic; +using System.Text.RegularExpressions; +using BlubbFish.IoT.Zway.Events; +using BlubbFish.IoT.Zway.Interfaces; +using BlubbFish.IoT.Zway.lib; +using LitJson; + +namespace BlubbFish.IoT.Zway.Devices.CommandClasses.CommandClassSubs { + public class Alarmsensorsub : ACommandClass { + public override event UpdatedValue Update; + + public Int32 Source { get; private set; } + public Int32 Level { get; private set; } + public Int32 Time { get; private set; } + public String Type { get; private set; } + + public Alarmsensorsub(JsonData json, Tuple id, HttpConnection http, Boolean polling) : base(json, id, http, polling) { + this.IsSub = true; + InitComplex(json); + } + + private void InitComplex(JsonData json) { + if (json.Keys.Contains("srcId") && json["srcId"].Keys.Contains("value") && + json.Keys.Contains("sensorState") && json["sensorState"].Keys.Contains("value") && + json.Keys.Contains("sensorTime") && json["sensorTime"].Keys.Contains("value") && + json.Keys.Contains("typeString") && json["typeString"].Keys.Contains("value")) { + this.Source = Int32.Parse(json["srcId"]["value"].ToString()); + this.Level = Int32.Parse(json["sensorState"]["value"].ToString()); + this.Time = Int32.Parse(json["sensorTime"]["value"].ToString()); + this.Type = json["typeString"]["value"].ToString(); + } + } + + internal override void SetUpdate(JsonData json, Match match) { + if (json.Keys.Contains("srcId") && json["srcId"].Keys.Contains("value") && + json.Keys.Contains("sensorState") && json["sensorState"].Keys.Contains("value") && + json.Keys.Contains("sensorTime") && json["sensorTime"].Keys.Contains("value") && + json.Keys.Contains("typeString") && json["typeString"].Keys.Contains("value") && + this.CheckSetUpdateTime(json)) { + this.Source = Int32.Parse(json["srcId"]["value"].ToString()); + this.Level = Int32.Parse(json["sensorState"]["value"].ToString()); + this.Time = Int32.Parse(json["sensorTime"]["value"].ToString()); + this.Type = json["typeString"]["value"].ToString(); + this.Update?.Invoke(this, new DeviceUpdateEvent(new Tuple(this.Source, this.Level, this.Time, this.Type), this.LastUpdate, this)); + } + } + + public override String ToString() { + return "AlarmSensor " + this.Name + " [" + this.Id + "]: " + this.Type + " " + this.Source + " " + this.Level + " " + this.Time + " " + this.Type; + } + + internal override void Poll() => this.PollNone(); + + public override Dictionary ToDictionary() { + return new Dictionary { + { "Source", this.Source }, + { "Level", this.Level }, + { "Time", this.Time }, + { "Type", this.Type } + }; + } + } +} \ No newline at end of file diff --git a/Zway/Interfaces/ACommandClass.cs b/Zway/Interfaces/ACommandClass.cs index 8cf10bf..991cc11 100644 --- a/Zway/Interfaces/ACommandClass.cs +++ b/Zway/Interfaces/ACommandClass.cs @@ -36,8 +36,7 @@ namespace BlubbFish.IoT.Zway.Interfaces { Proprietary = 136, MultiChannelAssociation = 142, MultiCmd = 143, - Security = 152, - AlarmSensor = 156 // + Security = 152 } public enum Classes : Int32 { @@ -54,7 +53,8 @@ namespace BlubbFish.IoT.Zway.Interfaces { Alarm = 113, Battery = 128, Wakeup = 132, - Indicator = 135 + Indicator = 135, + AlarmSensor = 156 } public Int32 DeviceId { get; } diff --git a/Zway/Zway.csproj b/Zway/Zway.csproj index 9b409d4..1725bf6 100644 --- a/Zway/Zway.csproj +++ b/Zway/Zway.csproj @@ -9,8 +9,9 @@ Properties BlubbFish.IoT.Zway Zway - v4.6.1 + v4.7.1 512 + true @@ -31,7 +32,7 @@ - ..\..\IoT-Bot\packages\LitJson.0.9.0\lib\LitJson.dll + ..\packages\LitJson.0.9.0\lib\LitJson.dll @@ -46,11 +47,13 @@ + + @@ -76,6 +79,5 @@ - \ No newline at end of file diff --git a/Zway/packages.config b/Zway/packages.config index 1d1f601..6cbb4e9 100644 --- a/Zway/packages.config +++ b/Zway/packages.config @@ -1,4 +1,4 @@  - + \ No newline at end of file