diff --git a/Zway/Devices/CommandClasses/Alarm.cs b/Zway/Devices/CommandClasses/Alarm.cs index 1baf3b2..33cef64 100644 --- a/Zway/Devices/CommandClasses/Alarm.cs +++ b/Zway/Devices/CommandClasses/Alarm.cs @@ -4,6 +4,7 @@ using System.Text.RegularExpressions; using BlubbFish.IoT.Zway.Events; using BlubbFish.IoT.Zway.Interfaces; using BlubbFish.IoT.Zway.lib; +using BlubbFish.Utils.IoT.Interfaces.Language; using LitJson; namespace BlubbFish.IoT.Zway.Devices.CommandClasses { @@ -13,9 +14,18 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses { class Alarm : ACommandClass { public override event UpdatedValue Update; + #region Properties + /// + /// Unklar + /// public Int32 Level { get; private set; } + /// + /// unklar + /// public Int32 AlarmType { get; private set; } + #endregion + #region Constructor public Alarm(JsonData json, Tuple id, HttpConnection http, Boolean polling) : base(json, id, http, polling) { this.InitComplex(json); } @@ -28,9 +38,22 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses { this.Level = Int32.Parse(json["data"]["V1event"]["level"]["value"].ToString()); } } + #endregion + + #region ACommandClass + public override String ToString() { + return "Alarm " + this.Name + " [" + this.Id + "]: " + this.AlarmType + " " + this.Level; + } + + public override Dictionary ToDictionary() { + return new Dictionary { + { "AlarmType", this.AlarmType }, + { "Level", this.Level }, + }; + } internal override void SetUpdate(JsonData json, Match match) { - if(match.Groups[4].Value == ".data.V1event") { + if (match.Groups[4].Value == ".data.V1event") { if (json.Keys.Contains("alarmType") && json["alarmType"].Keys.Contains("value") && json.Keys.Contains("level") && json["level"].Keys.Contains("value") && this.CheckSetUpdateTime(json)) { @@ -43,17 +66,13 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses { } } - public override String ToString() { - return "Alarm " + this.Name + " [" + this.Id + "]: " + this.AlarmType + " " + this.Level; - } - internal override void Poll() => this.PollNone(); + #endregion - public override Dictionary ToDictionary() { - return new Dictionary { - { "AlarmType", this.AlarmType }, - { "Level", this.Level }, - }; + #region ISenml + protected override List ToSenmlList() { + return new List() { }; } + #endregion } } diff --git a/Zway/Devices/CommandClasses/AlarmSensor.cs b/Zway/Devices/CommandClasses/AlarmSensor.cs index 486024c..64c6032 100644 --- a/Zway/Devices/CommandClasses/AlarmSensor.cs +++ b/Zway/Devices/CommandClasses/AlarmSensor.cs @@ -6,6 +6,7 @@ using BlubbFish.IoT.Zway.Devices.CommandClasses.CommandClassSubs; using BlubbFish.IoT.Zway.Events; using BlubbFish.IoT.Zway.Interfaces; using BlubbFish.IoT.Zway.lib; +using BlubbFish.Utils.IoT.Interfaces.Language; using LitJson; namespace BlubbFish.IoT.Zway.Devices.CommandClasses { @@ -15,6 +16,7 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses { public class Alarmsensor : ACommandClass { public override event UpdatedValue Update; + #region Constructor public Alarmsensor(JsonData json, Tuple id, HttpConnection http, Boolean polling) : base(json, id, http, polling) { this.HasSub = true; this.InitComplex(json); @@ -23,21 +25,6 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses { } } - 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"]; @@ -55,8 +42,30 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses { } } - internal override void Poll() => this.PollSubGlobal(); + private void DeviceUpdate(Object sender, DeviceUpdateEvent e) { + this.Update?.Invoke(this, e); + } + #endregion + + #region ACommandClass + 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!"); + } + } public override Dictionary ToDictionary() => this.ToDictionarySub(); + + internal override void Poll() => this.PollSubGlobal(); + #endregion + + #region ISenml + protected override List ToSenmlList() => this.ToSenmlListSub(); + #endregion } } diff --git a/Zway/Devices/CommandClasses/Battery.cs b/Zway/Devices/CommandClasses/Battery.cs index 71f5f1b..0b7a785 100644 --- a/Zway/Devices/CommandClasses/Battery.cs +++ b/Zway/Devices/CommandClasses/Battery.cs @@ -4,6 +4,7 @@ using System.Text.RegularExpressions; using BlubbFish.IoT.Zway.Events; using BlubbFish.IoT.Zway.Interfaces; using BlubbFish.IoT.Zway.lib; +using BlubbFish.Utils.IoT.Interfaces.Language; using LitJson; namespace BlubbFish.IoT.Zway.Devices.CommandClasses { @@ -11,15 +12,37 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses { /// 128 = Battery /// public class Battery : ACommandClass { - - public Double Level { get; private set; } - public override event UpdatedValue Update; + #region Properties + /// + /// Batterylevel in Percent + /// + public Double Level { get; private set; } + #endregion + + #region Constructor public Battery(JsonData json, Tuple id, HttpConnection http, Boolean polling) : base(json, id, http, polling) { this.InitComplex(json); } + private void InitComplex(JsonData json) { + if (json.Keys.Contains("data") && json["data"].Keys.Contains("last") && json["data"]["last"].Keys.Contains("value")) { + this.Level = Double.Parse(json["data"]["last"]["value"].ToString()); + } + } + #endregion + + #region ACommandClass + public override String ToString() { + return "Battery " + this.Name + " [" + this.Id + "]: " + this.Level; + } + + public override Dictionary ToDictionary() { + return new Dictionary { + { "Level", this.Level }, + }; + } internal override void SetUpdate(JsonData json, Match match) { Boolean success = false; if (match.Groups[4].Value == ".data") { @@ -41,21 +64,13 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses { this.Update?.Invoke(this, new DeviceUpdateEvent(this.Level, this.LastUpdate, this)); } } + #endregion - private void InitComplex(JsonData json) { - if (json.Keys.Contains("data") && json["data"].Keys.Contains("last") && json["data"]["last"].Keys.Contains("value")) { - this.Level = Double.Parse(json["data"]["last"]["value"].ToString()); - } + #region ISenml + protected override List ToSenmlList() { + return new List() { new SenmlDouble("chargelevel", Senml.Units.Percent, this.Level) }; } + #endregion - public override String ToString() { - return "Battery " + this.Name + " [" + this.Id + "]: " + this.Level; - } - - public override Dictionary ToDictionary() { - return new Dictionary { - { "Level", this.Level }, - }; - } } } diff --git a/Zway/Devices/CommandClasses/CentralScene.cs b/Zway/Devices/CommandClasses/CentralScene.cs index 55e475f..d4a9a96 100644 --- a/Zway/Devices/CommandClasses/CentralScene.cs +++ b/Zway/Devices/CommandClasses/CentralScene.cs @@ -5,6 +5,7 @@ using System.Text.RegularExpressions; using BlubbFish.IoT.Zway.Events; using BlubbFish.IoT.Zway.Interfaces; using BlubbFish.IoT.Zway.lib; +using BlubbFish.Utils.IoT.Interfaces.Language; using LitJson; namespace BlubbFish.IoT.Zway.Devices.CommandClasses { @@ -14,15 +15,72 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses { public class Centralscene : ACommandClass { public override event UpdatedValue Update; + #region Properties + /// + /// Combination of Scenes and Modes + /// public ReadOnlyDictionary> ValidScenesModes { get; private set; } + /// + /// Current active Senes + /// public Int32 Scene { get; private set; } + /// + /// Current active mode + /// public Int32 Key { get; private set; } + #endregion + #region Constructor public Centralscene(JsonData json, Tuple id, HttpConnection http, Boolean polling) : base(json, id, http, polling) { this.ValidScenesModes = new ReadOnlyDictionary>(new Dictionary>()); this.InitComplex(json); } + private void InitComplex(JsonData json) { + if (json.Keys.Contains("data")) { + JsonData data = json["data"]; + if (data.Keys.Contains("sceneSupportedKeyAttributesMask")) { + Dictionary> scenes = new Dictionary>(); + foreach (String item in data["sceneSupportedKeyAttributesMask"].Keys) { + if (Int32.TryParse(item, out Int32 mode) && + data["sceneSupportedKeyAttributesMask"][item].Keys.Contains("value") && + data["sceneSupportedKeyAttributesMask"][item]["value"].IsArray) { + JsonData values = data["sceneSupportedKeyAttributesMask"][item]["value"]; + List modes = new List(); + foreach (JsonData value in values) { + modes.Add(Int32.Parse(value.ToString())); + } + scenes.Add(mode, new ReadOnlyCollection(modes)); + } + } + this.ValidScenesModes = new ReadOnlyDictionary>(scenes); + if (data.Keys.Contains("currentScene") && + data["currentScene"].Keys.Contains("value") && + data["currentScene"]["value"] != null) { + this.Scene = Int32.Parse(data["currentScene"]["value"].ToString()); + } + if (data.Keys.Contains("keyAttribute") && + data["keyAttribute"].Keys.Contains("value") && + data["keyAttribute"]["value"] != null) { + this.Key = Int32.Parse(data["keyAttribute"]["value"].ToString()); + } + } + } + } + #endregion + + #region ACommandClass + public override String ToString() { + return "CentralScene " + this.Name + " [" + this.Id + "]: " + this.Scene + "-" + this.Key; + } + + public override Dictionary ToDictionary() { + return new Dictionary { + { "Scene", this.Scene }, + { "Key", this.Key }, + }; + } + internal override void SetUpdate(JsonData json, Match match) { if (match.Groups[4].Value == ".data.currentScene") { if (json.Keys.Contains("value")) { @@ -38,49 +96,13 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses { } } - private void InitComplex(JsonData json) { - if (json.Keys.Contains("data")) { - JsonData data = json["data"]; - if(data.Keys.Contains("sceneSupportedKeyAttributesMask")) { - Dictionary> scenes = new Dictionary>(); - foreach (String item in data["sceneSupportedKeyAttributesMask"].Keys) { - if (Int32.TryParse(item, out Int32 mode) && - data["sceneSupportedKeyAttributesMask"][item].Keys.Contains("value") && - data["sceneSupportedKeyAttributesMask"][item]["value"].IsArray) { - JsonData values = data["sceneSupportedKeyAttributesMask"][item]["value"]; - List modes = new List(); - foreach (JsonData value in values) { - modes.Add(Int32.Parse(value.ToString())); - } - scenes.Add(mode, new ReadOnlyCollection(modes)); - } - } - this.ValidScenesModes = new ReadOnlyDictionary>(scenes); - if (data.Keys.Contains("currentScene") && - data["currentScene"].Keys.Contains("value") && - data["currentScene"]["value"] != null) { - this.Scene = Int32.Parse(data["currentScene"]["value"].ToString()); - } - if (data.Keys.Contains("keyAttribute") && - data["keyAttribute"].Keys.Contains("value") && - data["keyAttribute"]["value"] != null) { - this.Key = Int32.Parse(data["keyAttribute"]["value"].ToString()); - } - } - } - } - - public override String ToString() { - return "CentralScene " + this.Name + " [" + this.Id + "]: " + this.Scene+"-"+this.Key; - } - internal override void Poll() => this.PollNone(); + #endregion - public override Dictionary ToDictionary() { - return new Dictionary { - { "Scene", this.Scene }, - { "Key", this.Key }, - }; + #region ISenml + protected override List ToSenmlList() { + return new List() { new SenmlDouble("scene", Senml.Units.CounterValue, this.Scene), new SenmlDouble("key", Senml.Units.CounterValue, this.Key) }; } + #endregion } } diff --git a/Zway/Devices/CommandClasses/CommandClassSubs/Alarmsensorsub.cs b/Zway/Devices/CommandClasses/CommandClassSubs/Alarmsensorsub.cs index a72b2f4..5f1fbd8 100644 --- a/Zway/Devices/CommandClasses/CommandClassSubs/Alarmsensorsub.cs +++ b/Zway/Devices/CommandClasses/CommandClassSubs/Alarmsensorsub.cs @@ -4,17 +4,33 @@ using System.Text.RegularExpressions; using BlubbFish.IoT.Zway.Events; using BlubbFish.IoT.Zway.Interfaces; using BlubbFish.IoT.Zway.lib; +using BlubbFish.Utils.IoT.Interfaces.Language; using LitJson; namespace BlubbFish.IoT.Zway.Devices.CommandClasses.CommandClassSubs { public class Alarmsensorsub : ACommandClass { public override event UpdatedValue Update; + #region Properties + /// + /// + /// public Int32 Source { get; private set; } + /// + /// + /// public Int32 Level { get; private set; } + /// + /// + /// public Int32 Time { get; private set; } + /// + /// + /// public String Type { get; private set; } + #endregion + #region Constructor public Alarmsensorsub(JsonData json, Tuple id, HttpConnection http, Boolean polling) : base(json, id, http, polling) { this.IsSub = true; InitComplex(json); @@ -31,6 +47,21 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses.CommandClassSubs { this.Type = json["typeString"]["value"].ToString(); } } + #endregion + + #region ACommandClass + public override String ToString() { + return "AlarmSensor " + this.Name + " [" + this.Id + "]: " + this.Type + " " + this.Source + " " + this.Level + " " + this.Time + " " + this.Type; + } + + public override Dictionary ToDictionary() { + return new Dictionary { + { "Source", this.Source }, + { "Level", this.Level }, + { "Time", this.Time }, + { "Type", this.Type } + }; + } internal override void SetUpdate(JsonData json, Match match) { if (json.Keys.Contains("srcId") && json["srcId"].Keys.Contains("value") && @@ -46,19 +77,13 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses.CommandClassSubs { } } - 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(); + #endregion - public override Dictionary ToDictionary() { - return new Dictionary { - { "Source", this.Source }, - { "Level", this.Level }, - { "Time", this.Time }, - { "Type", this.Type } - }; + #region ISenml + protected override List ToSenmlList() { + return new List() { }; } + #endregion } } \ No newline at end of file diff --git a/Zway/Devices/CommandClasses/CommandClassSubs/Configurationsub.cs b/Zway/Devices/CommandClasses/CommandClassSubs/Configurationsub.cs index bcc3b89..30ab86a 100644 --- a/Zway/Devices/CommandClasses/CommandClassSubs/Configurationsub.cs +++ b/Zway/Devices/CommandClasses/CommandClassSubs/Configurationsub.cs @@ -4,13 +4,18 @@ using System.Text.RegularExpressions; using BlubbFish.IoT.Zway.Events; using BlubbFish.IoT.Zway.Interfaces; using BlubbFish.IoT.Zway.lib; +using BlubbFish.Utils.IoT.Interfaces.Language; using LitJson; namespace BlubbFish.IoT.Zway.Devices.CommandClasses.CommandClassSubs { class Configurationsub : ACommandClass { public override event UpdatedValue Update; - private Int64 _level; + #region Properties + private Int64 _level; + /// + /// Value of the Configuration Item + /// public Int64 Level { get { return this._level; @@ -25,8 +30,13 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses.CommandClassSubs { } } } + /// + /// Size of the Configuration slot + /// public Int32 Size { get; private set; } + #endregion + #region Constructor public Configurationsub(JsonData json, Tuple id, HttpConnection http, Boolean polling) : base(json, id, http, polling) { this.IsSub = true; InitComplex(json); @@ -42,8 +52,19 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses.CommandClassSubs { this.Size = Int32.Parse(json["size"]["value"].ToString()); } } + #endregion - internal override void Poll() => this.PollSub(); + #region ACommandClass + public override String ToString() { + return "Configuration " + this.Name + " [" + this.Id + "]: " + this.Level; + } + + public override Dictionary ToDictionary() { + return new Dictionary { + { "Level", this.Level }, + { "Size", this.Size }, + }; + } internal override void SetUpdate(JsonData json, Match match) { if (json.Keys.Contains("val") && json["val"].Keys.Contains("value") && json["val"]["value"] != null && @@ -55,15 +76,13 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses.CommandClassSubs { } } - public override String ToString() { - return "Configuration " + this.Name + " [" + this.Id + "]: " + this.Level; - } + internal override void Poll() => this.PollSub(); + #endregion - public override Dictionary ToDictionary() { - return new Dictionary { - { "Level", this.Level }, - { "Size", this.Size }, - }; + #region ISenml + protected override List ToSenmlList() { + return new List() { }; } + #endregion } } \ No newline at end of file diff --git a/Zway/Devices/CommandClasses/CommandClassSubs/MeterSub.cs b/Zway/Devices/CommandClasses/CommandClassSubs/MeterSub.cs index 562510d..e8aebd8 100644 --- a/Zway/Devices/CommandClasses/CommandClassSubs/MeterSub.cs +++ b/Zway/Devices/CommandClasses/CommandClassSubs/MeterSub.cs @@ -4,15 +4,29 @@ using System.Text.RegularExpressions; using BlubbFish.IoT.Zway.Events; using BlubbFish.IoT.Zway.Interfaces; using BlubbFish.IoT.Zway.lib; +using BlubbFish.Utils.IoT.Interfaces.Language; using LitJson; namespace BlubbFish.IoT.Zway.Devices.CommandClasses.CommandClassSubs { public class Metersub : ACommandClass { public override event UpdatedValue Update; + #region Properties + /// + /// Type of the Sensor + /// public String Type { get; private set; } + /// + /// Actual value of the Sensor + /// public Double Level { get; private set; } + /// + /// Scale of the Sensor + /// public String Scale { get; private set; } + #endregion + + #region Constructor public Metersub(JsonData json, Tuple id, HttpConnection http, Boolean polling) : base(json, id, http, polling) { this.HasReset = true; this.IsSub = true; @@ -31,6 +45,20 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses.CommandClassSubs { this.Scale = json["scaleString"]["value"].ToString(); } } + #endregion + + #region ACommandClass + public override String ToString() { + return "Meter " + this.Name + " [" + this.Id + "]: " + this.Type + " " + this.Level + "" + this.Scale; + } + + public override Dictionary ToDictionary() { + return new Dictionary { + { "Level", this.Level }, + { "Type", this.Type }, + { "Scale", this.Scale }, + }; + } internal override void SetUpdate(JsonData json, Match match) { if (json.Keys.Contains("val") && json["val"].Keys.Contains("value") && @@ -44,18 +72,18 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses.CommandClassSubs { } } - public override String ToString() { - return "Meter " + this.Name + " [" + this.Id + "]: " + this.Type + " " + this.Level + "" + this.Scale; - } - internal override void Poll() => this.PollNone(); + #endregion - public override Dictionary ToDictionary() { - return new Dictionary { - { "Level", this.Level }, - { "Type", this.Type }, - { "Scale", this.Scale }, - }; + #region ISenml + protected override List ToSenmlList() { + if (this.Scale == "W") { + return new List() { new SenmlDouble("power", Senml.Units.Watt, this.Level) }; + } else if(this.Scale == "kWh") { + return new List() { new SenmlDouble("consumption", Senml.Units.Joule, this.Level * 1000 * 3.6 * 1000) }; + } + return new List() {}; } + #endregion } } \ No newline at end of file diff --git a/Zway/Devices/CommandClasses/CommandClassSubs/SceneControllerConfSub.cs b/Zway/Devices/CommandClasses/CommandClassSubs/SceneControllerConfSub.cs index c89b7d7..0da79ae 100644 --- a/Zway/Devices/CommandClasses/CommandClassSubs/SceneControllerConfSub.cs +++ b/Zway/Devices/CommandClasses/CommandClassSubs/SceneControllerConfSub.cs @@ -4,14 +4,25 @@ using System.Text.RegularExpressions; using BlubbFish.IoT.Zway.Events; using BlubbFish.IoT.Zway.Interfaces; using BlubbFish.IoT.Zway.lib; +using BlubbFish.Utils.IoT.Interfaces.Language; using LitJson; namespace BlubbFish.IoT.Zway.Devices.CommandClasses.CommandClassSubs { public class Scenecontrollerconfsub : ACommandClass { public override event UpdatedValue Update; + #region Properties + /// + /// + /// public Int32 Scene { get; private set; } + /// + /// + /// public Int32 Duration { get; private set; } + #endregion + + #region Constructor public Scenecontrollerconfsub(JsonData json, Tuple id, HttpConnection http, Boolean polling) : base(json, id, http, polling) { this.IsSub = true; InitComplex(json); @@ -24,6 +35,19 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses.CommandClassSubs { this.Duration = Int32.Parse(json["duration"]["value"].ToString()); } } + #endregion + + #region ACommandClass + public override String ToString() { + return "SceneControllerConf " + this.Name + " [" + this.Id + "]: " + this.Scene + " " + this.Duration; + } + + public override Dictionary ToDictionary() { + return new Dictionary { + { "Scene", this.Scene }, + { "Duration", this.Duration } + }; + } internal override void SetUpdate(JsonData json, Match match) { if (json.Keys.Contains("scene") && json["scene"].Keys.Contains("value") && @@ -35,17 +59,13 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses.CommandClassSubs { } } - public override String ToString() { - return "SceneControllerConf " + this.Name + " [" + this.Id + "]: " + this.Scene + " " + this.Duration; - } - internal override void Poll() => this.PollSub(); + #endregion - public override Dictionary ToDictionary() { - return new Dictionary { - { "Scene", this.Scene }, - { "Duration", this.Duration } - }; + #region ISenml + protected override List ToSenmlList() { + return new List() { }; } + #endregion } } \ No newline at end of file diff --git a/Zway/Devices/CommandClasses/CommandClassSubs/SensorBinarySub.cs b/Zway/Devices/CommandClasses/CommandClassSubs/SensorBinarySub.cs index 35586e6..883212f 100644 --- a/Zway/Devices/CommandClasses/CommandClassSubs/SensorBinarySub.cs +++ b/Zway/Devices/CommandClasses/CommandClassSubs/SensorBinarySub.cs @@ -4,20 +4,33 @@ using System.Text.RegularExpressions; using BlubbFish.IoT.Zway.Events; using BlubbFish.IoT.Zway.Interfaces; using BlubbFish.IoT.Zway.lib; +using BlubbFish.Utils.IoT.Interfaces.Language; using LitJson; namespace BlubbFish.IoT.Zway.Devices.CommandClasses.CommandClassSubs { public class Sensorbinarysub : ACommandClass { public override event UpdatedValue Update; + #region Properties + /// + /// + /// public String Type { get; private set; } + /// + /// + /// public Boolean State { get; private set; } + /// + /// + /// public Int32 Level { get { return (this.State) ? 1 : 0; } } + #endregion + #region Constructor public Sensorbinarysub(JsonData json, Tuple id, HttpConnection http, Boolean polling) : base(json, id, http, polling) { this.IsSub = true; InitComplex(json); @@ -32,6 +45,20 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses.CommandClassSubs { this.State = (Boolean)json["level"]["value"]; } } + #endregion + + #region ACommandClass + public override String ToString() { + return "SensorBinary " + this.Name + " [" + this.Id + "]: " + this.Type + " " + this.State.ToString(); + } + + public override Dictionary ToDictionary() { + return new Dictionary { + { "State", this.State }, + { "Type", this.Type }, + { "Level", this.Level } + }; + } internal override void SetUpdate(JsonData json, Match match) { if (json.Keys.Contains("level") && json["level"].Keys.Contains("value") && @@ -43,18 +70,13 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses.CommandClassSubs { } } - public override String ToString() { - return "SensorBinary " + this.Name + " [" + this.Id + "]: " + this.Type + " " + this.State.ToString(); - } - internal override void Poll() => this.PollNone(); + #endregion - public override Dictionary ToDictionary() { - return new Dictionary { - { "State", this.State }, - { "Type", this.Type }, - { "Level", this.Level } - }; + #region ISenml + protected override List ToSenmlList() { + return new List() { }; } + #endregion } } \ No newline at end of file diff --git a/Zway/Devices/CommandClasses/CommandClassSubs/SensorMultilevelSub.cs b/Zway/Devices/CommandClasses/CommandClassSubs/SensorMultilevelSub.cs index 887f892..c473c42 100644 --- a/Zway/Devices/CommandClasses/CommandClassSubs/SensorMultilevelSub.cs +++ b/Zway/Devices/CommandClasses/CommandClassSubs/SensorMultilevelSub.cs @@ -4,16 +4,29 @@ using System.Text.RegularExpressions; using BlubbFish.IoT.Zway.Events; using BlubbFish.IoT.Zway.Interfaces; using BlubbFish.IoT.Zway.lib; +using BlubbFish.Utils.IoT.Interfaces.Language; using LitJson; namespace BlubbFish.IoT.Zway.Devices.CommandClasses.CommandClassSubs { public class Sensormultilevelsub : ACommandClass { public override event UpdatedValue Update; + #region Properties + /// + /// Type of the Sensor + /// public String Type { get; private set; } + /// + /// Level of the sensor + /// public Double Level { get; private set; } + /// + /// Scale of the sensor + /// public String Scale { get; private set; } + #endregion + #region Constructor public Sensormultilevelsub(JsonData json, Tuple id, HttpConnection http, Boolean polling) : base(json, id, http, polling) { this.IsSub = true; InitComplex(json); @@ -31,6 +44,20 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses.CommandClassSubs { this.Scale = json["scaleString"]["value"].ToString(); } } + #endregion + + #region ACommandClass + public override String ToString() { + return "SensorMultilevel " + this.Name + " [" + this.Id + "]: " + this.Type + " " + this.Level + "" + this.Scale; + } + + public override Dictionary ToDictionary() { + return new Dictionary { + { "Level", this.Level }, + { "Type", this.Type }, + { "Scale", this.Scale }, + }; + } internal override void SetUpdate(JsonData json, Match match) { if(json.Keys.Contains("val") && json["val"].Keys.Contains("value") && json.Keys.Contains("sensorTypeString") && json["sensorTypeString"].Keys.Contains("value")) { @@ -53,18 +80,18 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses.CommandClassSubs { } } - public override String ToString() { - return "SensorMultilevel " + this.Name + " [" + this.Id + "]: " + this.Type + " " + this.Level + "" + this.Scale; - } - internal override void Poll() => this.PollNone(); + #endregion - public override Dictionary ToDictionary() { - return new Dictionary { - { "Level", this.Level }, - { "Type", this.Type }, - { "Scale", this.Scale }, - }; + #region ISenml + protected override List ToSenmlList() { + if(this.Scale == "W") { + return new List() { new SenmlDouble("power", Senml.Units.Watt, this.Level) }; + } else if(this.Scale == "°C") { + return new List() { new SenmlDouble("temperatur", Senml.Units.Celsius, this.Level) }; + } + return new List() { }; } + #endregion } } \ No newline at end of file diff --git a/Zway/Devices/CommandClasses/CommandClassSubs/ThermostatSetPointSub.cs b/Zway/Devices/CommandClasses/CommandClassSubs/ThermostatSetPointSub.cs index cb9c139..2aee6bf 100644 --- a/Zway/Devices/CommandClasses/CommandClassSubs/ThermostatSetPointSub.cs +++ b/Zway/Devices/CommandClasses/CommandClassSubs/ThermostatSetPointSub.cs @@ -4,13 +4,18 @@ using System.Text.RegularExpressions; using BlubbFish.IoT.Zway.Events; using BlubbFish.IoT.Zway.Interfaces; using BlubbFish.IoT.Zway.lib; +using BlubbFish.Utils.IoT.Interfaces.Language; using LitJson; namespace BlubbFish.IoT.Zway.Devices.CommandClasses.CommandClassSubs { class Thermostatsetpointsub : ACommandClass { public override event UpdatedValue Update; + #region Properties private Double _level; + /// + /// Target-Temperatur + /// public Double Level { get { return this._level; @@ -21,12 +26,29 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses.CommandClassSubs { } } } + /// + /// Scale of the actor + /// public String Scale { get; private set; } + /// + /// Maximum Temperatur of the actor + /// public Double TempMax { get; private set; } + /// + /// Minimum Temperatur of the actor + /// public Double TempMin { get; private set; } + /// + /// Has Maximum and Minimum + /// public Boolean HasMinMax { get; private set; } + /// + /// Type of the actor + /// public String Type { get; private set; } + #endregion + #region Constructor public Thermostatsetpointsub(JsonData json, Tuple id, HttpConnection http, Boolean polling) : base(json, id, http, polling) { this.IsSub = true; InitComplex(json); @@ -49,6 +71,23 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses.CommandClassSubs { this.HasMinMax = false; } } + #endregion + + #region ACommandClass + public override String ToString() { + return "ThermostatSetPoint " + this.Name + " [" + this.Id + "]: " + this.Type + " " + this.Level + "" + this.Scale + " [" + this.TempMin + "," + this.TempMax + "," + this.HasMinMax + "]"; + } + + public override Dictionary ToDictionary() { + return new Dictionary { + { "Level", this.Level }, + { "Type", this.Type }, + { "Scale", this.Scale }, + { "TempMax", this.TempMax }, + { "TempMin", this.TempMin }, + { "HasMinMax", this.HasMinMax }, + }; + } internal override void SetUpdate(JsonData json, Match match) { Boolean ret = false; @@ -74,21 +113,16 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses.CommandClassSubs { } } - public override String ToString() { - return "ThermostatSetPoint " + this.Name + " [" + this.Id + "]: " + this.Type + " " + this.Level + "" + this.Scale + " [" + this.TempMin + "," + this.TempMax + "," + this.HasMinMax + "]"; - } - internal override void Poll() => this.PollSub(); + #endregion - public override Dictionary ToDictionary() { - return new Dictionary { - { "Level", this.Level }, - { "Type", this.Type }, - { "Scale", this.Scale }, - { "TempMax", this.TempMax }, - { "TempMin", this.TempMin }, - { "HasMinMax", this.HasMinMax }, - }; + #region ISenml + protected override List ToSenmlList() { + if(this.Scale == "°C") { + return new List() { new SenmlDouble("temperatur", Senml.Units.Celsius, this.Level) }; + } + return new List() { }; } + #endregion } } \ No newline at end of file diff --git a/Zway/Devices/CommandClasses/Configuration.cs b/Zway/Devices/CommandClasses/Configuration.cs index ec99a4b..eecfb7a 100644 --- a/Zway/Devices/CommandClasses/Configuration.cs +++ b/Zway/Devices/CommandClasses/Configuration.cs @@ -6,6 +6,7 @@ using BlubbFish.IoT.Zway.Devices.CommandClasses.CommandClassSubs; using BlubbFish.IoT.Zway.Events; using BlubbFish.IoT.Zway.Interfaces; using BlubbFish.IoT.Zway.lib; +using BlubbFish.Utils.IoT.Interfaces.Language; using LitJson; namespace BlubbFish.IoT.Zway.Devices.CommandClasses { @@ -15,6 +16,7 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses { class Configuration : ACommandClass { public override event UpdatedValue Update; + #region Constructor public Configuration(JsonData json, Tuple id, HttpConnection http, Boolean polling) : base(json, id, http, polling) { this.HasSub = true; this.InitComplex(json); @@ -23,10 +25,6 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses { } } - private void DeviceUpdate(Object sender, DeviceUpdateEvent e) { - this.Update?.Invoke(this, e); - } - private void InitComplex(JsonData json) { if (json.Keys.Contains("data")) { JsonData data = json["data"]; @@ -44,6 +42,12 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses { } } + private void DeviceUpdate(Object sender, DeviceUpdateEvent e) { + this.Update?.Invoke(this, e); + } + #endregion + + #region ACommandClass internal override void SetUpdate(JsonData json, Match match) { if (match.Groups[4].Value.StartsWith(".data.")) { Int32 subid = Int32.Parse(match.Groups[5].Value); @@ -58,5 +62,10 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses { internal override void Poll() => this.PollPerSub(); public override Dictionary ToDictionary() => this.ToDictionarySub(); + #endregion + + #region ISenml + protected override List ToSenmlList() => this.ToSenmlListSub(); + #endregion } } diff --git a/Zway/Devices/CommandClasses/Indicator.cs b/Zway/Devices/CommandClasses/Indicator.cs index 2de3502..6261636 100644 --- a/Zway/Devices/CommandClasses/Indicator.cs +++ b/Zway/Devices/CommandClasses/Indicator.cs @@ -4,6 +4,7 @@ using System.Text.RegularExpressions; using BlubbFish.IoT.Zway.Events; using BlubbFish.IoT.Zway.Interfaces; using BlubbFish.IoT.Zway.lib; +using BlubbFish.Utils.IoT.Interfaces.Language; using LitJson; namespace BlubbFish.IoT.Zway.Devices.CommandClasses { @@ -11,9 +12,13 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses { /// 135 = Indicator /// class Indicator : ACommandClass { - private Boolean _state; - public override event UpdatedValue Update; + + #region Properties + private Boolean _state; + /// + /// Status of the Indicator + /// public Boolean State { get { return this._state; @@ -22,7 +27,9 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses { this.SetInt(value ? 255 : 0); } } - + /// + /// Int-Representation of the Indicator + /// public Int32 Level { get { return (this.State) ? 1 : 0; @@ -31,7 +38,9 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses { this.State = (value == 1); } } + #endregion + #region Constructor public Indicator(JsonData json, Tuple id, HttpConnection http, Boolean polling) : base(json, id, http, polling) { this.InitComplex(json); } @@ -41,6 +50,19 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses { this._state = Int32.Parse(json["data"]["stat"]["value"].ToString()) == 255; } } + #endregion + + #region ACommandClass + public override String ToString() { + return "Indicator " + this.Name + " [" + this.Id + "]: " + this.State; + } + + public override Dictionary ToDictionary() { + return new Dictionary { + { "State", this.State }, + { "Level", this.Level } + }; + } internal override void SetUpdate(JsonData json, Match match) { if(match.Groups[4].Value == ".data.stat") { @@ -52,16 +74,13 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses { Helper.WriteError("Kenne in " + this.Name + " [" + this.Id + "] " + match.Groups[4].Value + " nicht!"); } } + #endregion - public override String ToString() { - return "Indicator " + this.Name + " [" + this.Id + "]: " + this.State; + #region ISenml + protected override List ToSenmlList() { + return new List() { new SenmlBool("status", Senml.Units.CounterValue, this.State) }; } + #endregion - public override Dictionary ToDictionary() { - return new Dictionary { - { "State", this.State }, - { "Level", this.Level } - }; - } } } diff --git a/Zway/Devices/CommandClasses/Meter.cs b/Zway/Devices/CommandClasses/Meter.cs index c0836f0..d41f060 100644 --- a/Zway/Devices/CommandClasses/Meter.cs +++ b/Zway/Devices/CommandClasses/Meter.cs @@ -6,6 +6,7 @@ using BlubbFish.IoT.Zway.Devices.CommandClasses.CommandClassSubs; using BlubbFish.IoT.Zway.Events; using BlubbFish.IoT.Zway.Interfaces; using BlubbFish.IoT.Zway.lib; +using BlubbFish.Utils.IoT.Interfaces.Language; using LitJson; namespace BlubbFish.IoT.Zway.Devices.CommandClasses { @@ -15,6 +16,7 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses { public class Meter : ACommandClass { public override event UpdatedValue Update; + #region Constructor public Meter(JsonData json, Tuple id, HttpConnection http, Boolean polling) : base(json, id, http, polling) { this.HasSub = true; this.InitComplex(json); @@ -23,21 +25,6 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses { } } - 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"]; @@ -54,8 +41,30 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses { } } + private void DeviceUpdate(Object sender, DeviceUpdateEvent e) { + this.Update?.Invoke(this, e); + } + #endregion + + #region ACommandClass + 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!"); + } + } + internal override void Poll() => this.PollSubGlobal(); public override Dictionary ToDictionary() => this.ToDictionarySub(); + #endregion + + #region ISenml + protected override List ToSenmlList() => this.ToSenmlListSub(); + #endregion } } diff --git a/Zway/Devices/CommandClasses/SceneControllerConf.cs b/Zway/Devices/CommandClasses/SceneControllerConf.cs index ee0ab33..a99f7bf 100644 --- a/Zway/Devices/CommandClasses/SceneControllerConf.cs +++ b/Zway/Devices/CommandClasses/SceneControllerConf.cs @@ -6,6 +6,7 @@ using BlubbFish.IoT.Zway.Devices.CommandClasses.CommandClassSubs; using BlubbFish.IoT.Zway.Events; using BlubbFish.IoT.Zway.Interfaces; using BlubbFish.IoT.Zway.lib; +using BlubbFish.Utils.IoT.Interfaces.Language; using LitJson; namespace BlubbFish.IoT.Zway.Devices.CommandClasses { @@ -15,6 +16,7 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses { public class Scenecontrollerconf : ACommandClass { public override event UpdatedValue Update; + #region Constructor public Scenecontrollerconf(JsonData json, Tuple id, HttpConnection http, Boolean polling) : base(json, id, http, polling) { this.HasSub = true; this.InitComplex(json); @@ -23,21 +25,6 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses { } } - 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"]; @@ -53,8 +40,30 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses { } } + private void DeviceUpdate(Object sender, DeviceUpdateEvent e) { + this.Update?.Invoke(this, e); + } + #endregion + + #region ACommandClass + 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!"); + } + } + internal override void Poll() => this.PollPerSub(); public override Dictionary ToDictionary() => this.ToDictionarySub(); + #endregion + + #region ISenml + protected override List ToSenmlList() => this.ToSenmlListSub(); + #endregion } } diff --git a/Zway/Devices/CommandClasses/SensorBinary.cs b/Zway/Devices/CommandClasses/SensorBinary.cs index 9e59265..5255ae1 100644 --- a/Zway/Devices/CommandClasses/SensorBinary.cs +++ b/Zway/Devices/CommandClasses/SensorBinary.cs @@ -6,6 +6,7 @@ using BlubbFish.IoT.Zway.Devices.CommandClasses.CommandClassSubs; using BlubbFish.IoT.Zway.Events; using BlubbFish.IoT.Zway.Interfaces; using BlubbFish.IoT.Zway.lib; +using BlubbFish.Utils.IoT.Interfaces.Language; using LitJson; namespace BlubbFish.IoT.Zway.Devices.CommandClasses { @@ -15,6 +16,7 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses { public class Sensorbinary : ACommandClass { public override event UpdatedValue Update; + #region Constructor public Sensorbinary(JsonData json, Tuple id, HttpConnection http, Boolean polling) : base(json, id, http, polling) { this.HasSub = true; this.InitComplex(json); @@ -23,21 +25,6 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses { } } - 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"]; @@ -53,8 +40,30 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses { } } + private void DeviceUpdate(Object sender, DeviceUpdateEvent e) { + this.Update?.Invoke(this, e); + } + #endregion + + #region ACommandClass + 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!"); + } + } + internal override void Poll() => this.PollSubGlobal(); public override Dictionary ToDictionary() => this.ToDictionarySub(); + #endregion + + #region ISenml + protected override List ToSenmlList() => this.ToSenmlListSub(); + #endregion } } diff --git a/Zway/Devices/CommandClasses/SensorMultilevel.cs b/Zway/Devices/CommandClasses/SensorMultilevel.cs index fd10cd4..47a2cdd 100644 --- a/Zway/Devices/CommandClasses/SensorMultilevel.cs +++ b/Zway/Devices/CommandClasses/SensorMultilevel.cs @@ -6,6 +6,7 @@ using BlubbFish.IoT.Zway.Devices.CommandClasses.CommandClassSubs; using BlubbFish.IoT.Zway.Events; using BlubbFish.IoT.Zway.Interfaces; using BlubbFish.IoT.Zway.lib; +using BlubbFish.Utils.IoT.Interfaces.Language; using LitJson; namespace BlubbFish.IoT.Zway.Devices.CommandClasses { @@ -15,6 +16,7 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses { public class Sensormultilevel : ACommandClass { public override event UpdatedValue Update; + #region Constructor public Sensormultilevel(JsonData json, Tuple id, HttpConnection http, Boolean polling) : base(json, id, http, polling) { this.HasSub = true; this.InitComplex(json); @@ -23,21 +25,6 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses { } } - 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"]; @@ -54,8 +41,30 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses { } } + private void DeviceUpdate(Object sender, DeviceUpdateEvent e) { + this.Update?.Invoke(this, e); + } + #endregion + + #region ACommandClass + 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!"); + } + } + internal override void Poll() => this.PollSubGlobal(); public override Dictionary ToDictionary() => this.ToDictionarySub(); + #endregion + + #region ISenml + protected override List ToSenmlList() => this.ToSenmlListSub(); + #endregion } } diff --git a/Zway/Devices/CommandClasses/SwitchBinary.cs b/Zway/Devices/CommandClasses/SwitchBinary.cs index cf469de..5b7d68d 100644 --- a/Zway/Devices/CommandClasses/SwitchBinary.cs +++ b/Zway/Devices/CommandClasses/SwitchBinary.cs @@ -4,6 +4,7 @@ using System.Text.RegularExpressions; using BlubbFish.IoT.Zway.Events; using BlubbFish.IoT.Zway.Interfaces; using BlubbFish.IoT.Zway.lib; +using BlubbFish.Utils.IoT.Interfaces.Language; using LitJson; namespace BlubbFish.IoT.Zway.Devices.CommandClasses { @@ -11,10 +12,12 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses { /// 37 = SwitchBinary /// public class Switchbinary : ACommandClass { - private Boolean _state; - public override event UpdatedValue Update; + #region Properties + /// + /// Int representation of Boolean + /// public Int32 Level { get { return (this.State) ? 1 : 0; @@ -23,7 +26,10 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses { this.State = (value == 1); } } - + private Boolean _state; + /// + /// State if Switch is activated + /// public Boolean State { get { return this._state; @@ -32,11 +38,32 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses { this.SetInt(value ? 255 : 0); } } + #endregion + #region Constructor public Switchbinary(JsonData json, Tuple id, HttpConnection http, Boolean polling) : base(json, id, http, polling) { this.InitComplex(json); } + private void InitComplex(JsonData json) { + if (json.Keys.Contains("data") && json["data"].Keys.Contains("level") && json["data"]["level"].Keys.Contains("value") && json["data"]["level"]["value"].IsBoolean) { + this._state = (Boolean)json["data"]["level"]["value"]; + } + } + #endregion + + #region ACommandClass + public override String ToString() { + return "SwitchBinary " + this.Name + " [" + this.Id + "]: " + this.State; + } + + public override Dictionary ToDictionary() { + return new Dictionary { + { "State", this.State }, + { "Level", this.Level } + }; + } + internal override void SetUpdate(JsonData json, Match match) { if(match.Groups[4].Value == ".data.level") { if (json.Keys.Contains("value") && json["value"].IsBoolean && this.CheckSetUpdateTime(json)) { @@ -47,22 +74,12 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses { Helper.WriteError("Kenne in " + this.Name + " [" + this.Id + "] " + match.Groups[4].Value + " nicht!"); } } + #endregion - private void InitComplex(JsonData json) { - if (json.Keys.Contains("data") && json["data"].Keys.Contains("level") && json["data"]["level"].Keys.Contains("value") && json["data"]["level"]["value"].IsBoolean) { - this._state = (Boolean)json["data"]["level"]["value"]; - } - } - - public override String ToString() { - return "SwitchBinary " + this.Name + " [" + this.Id + "]: " + this.State; - } - - public override Dictionary ToDictionary() { - return new Dictionary { - { "State", this.State }, - { "Level", this.Level } - }; + #region ISenml + protected override List ToSenmlList() { + return new List() { new SenmlBool("state", Senml.Units.CounterValue, this.State) }; } + #endregion } } diff --git a/Zway/Devices/CommandClasses/SwitchMultilevel.cs b/Zway/Devices/CommandClasses/SwitchMultilevel.cs index d663771..94b8638 100644 --- a/Zway/Devices/CommandClasses/SwitchMultilevel.cs +++ b/Zway/Devices/CommandClasses/SwitchMultilevel.cs @@ -4,6 +4,7 @@ using System.Text.RegularExpressions; using BlubbFish.IoT.Zway.Events; using BlubbFish.IoT.Zway.Interfaces; using BlubbFish.IoT.Zway.lib; +using BlubbFish.Utils.IoT.Interfaces.Language; using LitJson; namespace BlubbFish.IoT.Zway.Devices.CommandClasses { @@ -11,10 +12,13 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses { /// 38 = SwitchMultilevel /// public class Switchmultilevel : ACommandClass { - private Int32 _level; - public override event UpdatedValue Update; + #region Properties + private Int32 _level; + /// + /// Level of thw Switch + /// public Int32 Level { get { return this._level; @@ -25,11 +29,31 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses { } } } + #endregion + #region Constructor public Switchmultilevel(JsonData json, Tuple id, HttpConnection http, Boolean polling) : base(json, id, http, polling) { this.InitComplex(json); } + private void InitComplex(JsonData json) { + if (json.Keys.Contains("data") && json["data"].Keys.Contains("level") && json["data"]["level"].Keys.Contains("value")) { + this._level = Int32.Parse(json["data"]["level"]["value"].ToString()); + } + } + #endregion + + #region ACommandClass + public override String ToString() { + return "SwitchMultilevel " + this.Name + " [" + this.Id + "]: " + this.Level; + } + + public override Dictionary ToDictionary() { + return new Dictionary { + { "Level", this.Level } + }; + } + internal override void SetUpdate(JsonData json, Match match) { if(match.Groups[4].Value == ".data.level") { if(json.Keys.Contains("value") && this.CheckSetUpdateTime(json)) { @@ -41,21 +65,12 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses { Helper.WriteError("Kenne in " + this.Name + " [" + this.Id + "] " + match.Groups[4].Value + " nicht!"); } } + #endregion - private void InitComplex(JsonData json) { - if (json.Keys.Contains("data") && json["data"].Keys.Contains("level") && json["data"]["level"].Keys.Contains("value")) { - this._level = Int32.Parse(json["data"]["level"]["value"].ToString()); - } - } - - public override String ToString() { - return "SwitchMultilevel " + this.Name + " [" + this.Id + "]: " + this.Level; - } - - public override Dictionary ToDictionary() { - return new Dictionary { - { "Level", this.Level } - }; + #region ISenml + protected override List ToSenmlList() { + return new List() { new SenmlDouble("state", Senml.Units.Percent, (Double)this.Level/255) }; } + #endregion } } diff --git a/Zway/Devices/CommandClasses/ThermostatMode.cs b/Zway/Devices/CommandClasses/ThermostatMode.cs index b83a4bd..412923a 100644 --- a/Zway/Devices/CommandClasses/ThermostatMode.cs +++ b/Zway/Devices/CommandClasses/ThermostatMode.cs @@ -5,6 +5,7 @@ using System.Text.RegularExpressions; using BlubbFish.IoT.Zway.Events; using BlubbFish.IoT.Zway.Interfaces; using BlubbFish.IoT.Zway.lib; +using BlubbFish.Utils.IoT.Interfaces.Language; using LitJson; namespace BlubbFish.IoT.Zway.Devices.CommandClasses { @@ -12,11 +13,17 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses { /// 64 = ThermostatMode /// public class Thermostatmode : ACommandClass { - private Int32 _level; - public override event UpdatedValue Update; + #region Properties + /// + /// Allowd Modes + /// public ReadOnlyDictionary ValidModes { get; private set; } + private Int32 _level; + /// + /// Actual mode + /// public Int32 Level { get { return this._level; } set { @@ -25,23 +32,14 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses { } } } + #endregion + #region Constructor public Thermostatmode(JsonData json, Tuple id, HttpConnection http, Boolean polling) : base(json, id, http, polling) { this.ValidModes = new ReadOnlyDictionary(new Dictionary()); this.InitComplex(json); } - internal override void SetUpdate(JsonData json, Match match) { - if(match.Groups[4].Value == ".data.mode") { - if(json.Keys.Contains("value") && this.CheckSetUpdateTime(json)) { - this._level = Int32.Parse(json["value"].ToString()); - this.Update?.Invoke(this, new DeviceUpdateEvent(this.Level, this.LastUpdate, this)); - } - } 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"]; @@ -60,7 +58,9 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses { } } } + #endregion + #region ACommandClass public override String ToString() { return "ThermostatMode " + this.Name + " [" + this.Id + "]: " + this.ValidModes[this.Level]; } @@ -76,5 +76,23 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses { }; return json; } + + internal override void SetUpdate(JsonData json, Match match) { + if(match.Groups[4].Value == ".data.mode") { + if(json.Keys.Contains("value") && this.CheckSetUpdateTime(json)) { + this._level = Int32.Parse(json["value"].ToString()); + this.Update?.Invoke(this, new DeviceUpdateEvent(this.Level, this.LastUpdate, this)); + } + } else { + Helper.WriteError("Kenne in " + this.Name + " [" + this.Id + "] " + match.Groups[4].Value + " nicht!"); + } + } + #endregion + + #region ISenml + protected override List ToSenmlList() { + return new List() { new SenmlDouble("mode", Senml.Units.CounterValue, this.Level) }; + } + #endregion } } diff --git a/Zway/Devices/CommandClasses/ThermostatSetPoint.cs b/Zway/Devices/CommandClasses/ThermostatSetPoint.cs index dd1d66d..9cc92ca 100644 --- a/Zway/Devices/CommandClasses/ThermostatSetPoint.cs +++ b/Zway/Devices/CommandClasses/ThermostatSetPoint.cs @@ -6,6 +6,7 @@ using BlubbFish.IoT.Zway.Devices.CommandClasses.CommandClassSubs; using BlubbFish.IoT.Zway.Events; using BlubbFish.IoT.Zway.Interfaces; using BlubbFish.IoT.Zway.lib; +using BlubbFish.Utils.IoT.Interfaces.Language; using LitJson; namespace BlubbFish.IoT.Zway.Devices.CommandClasses { @@ -15,6 +16,7 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses { public class Thermostatsetpoint : ACommandClass { public override event UpdatedValue Update; + #region Constructor public Thermostatsetpoint(JsonData json, Tuple id, HttpConnection http, Boolean polling) : base(json, id, http, polling) { this.HasSub = true; this.InitComplex(json); @@ -23,21 +25,6 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses { } } - 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"]; @@ -54,8 +41,30 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses { } } + private void DeviceUpdate(Object sender, DeviceUpdateEvent e) { + this.Update?.Invoke(this, e); + } + #endregion + + #region ACommandClass + 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!"); + } + } + internal override void Poll() => this.PollPerSub(); public override Dictionary ToDictionary() => this.ToDictionarySub(); + #endregion + + #region ISenml + protected override List ToSenmlList() => this.ToSenmlListSub(); + #endregion } } diff --git a/Zway/Devices/CommandClasses/Wakeup.cs b/Zway/Devices/CommandClasses/Wakeup.cs index 19f2234..747cff2 100644 --- a/Zway/Devices/CommandClasses/Wakeup.cs +++ b/Zway/Devices/CommandClasses/Wakeup.cs @@ -4,6 +4,7 @@ using System.Text.RegularExpressions; using BlubbFish.IoT.Zway.Events; using BlubbFish.IoT.Zway.Interfaces; using BlubbFish.IoT.Zway.lib; +using BlubbFish.Utils.IoT.Interfaces.Language; using LitJson; namespace BlubbFish.IoT.Zway.Devices.CommandClasses { @@ -11,10 +12,10 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses { /// 132 = Wakeup /// class Wakeup : ACommandClass { - private Int32 _interval; - private Int32 _againstNode; - public override event UpdatedValue Update; + + #region Properties + private Int32 _interval; public Int32 Interval { get { return this._interval; @@ -25,6 +26,7 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses { } } } + private Int32 _againstNode; public Int32 AgainstNode { get { return this._againstNode; } @@ -41,7 +43,9 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses { public Int32 HasDefaultLevel { get { return (this.HasDefaultState) ? 1 : 0; } } public DateTime LastWakeup { get; private set; } public DateTime LastSleep { get; private set; } + #endregion + #region Constructor public Wakeup(JsonData json, Tuple id, HttpConnection http, Boolean polling) : base(json, id, http, polling) { this.InitComplex(json); } @@ -77,6 +81,28 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses { } } } + #endregion + + #region ACommandClass + public override String ToString() { + return "Wakeup " + this.Name + " [" + this.Id + "]: " + this.LastWakeup + "-" + this.LastSleep + " " + this.Interval + " [" + this.WakeupMin + "," + this.WakeupMax + "," + this.WakeupDefault + "," + this.AgainstNode + "]"; + } + + public override Dictionary ToDictionary() { + return new Dictionary { + { "Interval", this.Interval }, + { "AgainstNode", this.AgainstNode }, + { "WakeupMin", this.WakeupMin }, + { "WakeupMax", this.WakeupMax }, + { "HasMinMaxState", this.HasMinMaxState }, + { "HasMinMaxLevel", this.HasMinMaxLevel }, + { "WakeupDefault", this.WakeupDefault }, + { "HasDefaultState", this.HasDefaultState }, + { "HasDefaultLevel", this.HasDefaultLevel }, + { "LastWakeup", this.LastWakeup.ToString() }, + { "LastSleep", this.LastSleep.ToString() } + }; + } internal override void SetUpdate(JsonData json, Match match) { Boolean success = false; @@ -131,25 +157,12 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses { this.Update?.Invoke(this, new DeviceUpdateEvent(0, this.LastUpdate, this)); } } + #endregion - public override String ToString() { - return "Wakeup " + this.Name + " [" + this.Id + "]: " + this.LastWakeup + "-" + this.LastSleep + " " + this.Interval + " [" + this.WakeupMin + "," + this.WakeupMax + "," + this.WakeupDefault + "," + this.AgainstNode + "]"; - } - - public override Dictionary ToDictionary() { - return new Dictionary { - { "Interval", this.Interval }, - { "AgainstNode", this.AgainstNode }, - { "WakeupMin", this.WakeupMin }, - { "WakeupMax", this.WakeupMax }, - { "HasMinMaxState", this.HasMinMaxState }, - { "HasMinMaxLevel", this.HasMinMaxLevel }, - { "WakeupDefault", this.WakeupDefault }, - { "HasDefaultState", this.HasDefaultState }, - { "HasDefaultLevel", this.HasDefaultLevel }, - { "LastWakeup", this.LastWakeup.ToString() }, - { "LastSleep", this.LastSleep.ToString() } - }; + #region ISenml + protected override List ToSenmlList() { + return new List() { }; } + #endregion } } diff --git a/Zway/Interfaces/ACommandClass.cs b/Zway/Interfaces/ACommandClass.cs index d8252dd..cbb1cf4 100644 --- a/Zway/Interfaces/ACommandClass.cs +++ b/Zway/Interfaces/ACommandClass.cs @@ -4,10 +4,12 @@ using System.Collections.ObjectModel; using System.Text.RegularExpressions; using BlubbFish.IoT.Zway.Events; using BlubbFish.IoT.Zway.lib; +using BlubbFish.Utils.IoT.Interfaces; +using BlubbFish.Utils.IoT.Interfaces.Language; using LitJson; namespace BlubbFish.IoT.Zway.Interfaces { - public abstract class ACommandClass { + public abstract class ACommandClass : IMqtt, ISenml { protected HttpConnection http; public delegate void UpdatedValue(Object sender, DeviceUpdateEvent e); @@ -58,6 +60,7 @@ namespace BlubbFish.IoT.Zway.Interfaces { AlarmSensor = 156 } + #region Properties public Int32 DeviceId { get; } public Int32 Instance { get; } public Classes Commandclass { get; } @@ -71,9 +74,9 @@ namespace BlubbFish.IoT.Zway.Interfaces { public Boolean HasSub { get; protected set; } public Boolean IsSub { get; protected set; } public Boolean HasReset { get; protected set; } + #endregion #region Constructor - protected ACommandClass(JsonData json, Tuple id, HttpConnection http, Boolean polling) { this.DeviceId = id.Item1; this.Instance = id.Item2; @@ -119,7 +122,7 @@ namespace BlubbFish.IoT.Zway.Interfaces { return GetInstanceConcrete(objectName, json, http, id, polling); } if (!Enum.IsDefined(typeof(IgnoredClasses), (Int32)id.Item3) && !Enum.IsDefined(typeof(Classes), id.Item3)) { - Helper.WriteError("CommandClass " + id.Item3 + " not exist."); + Helper.WriteError("CommandClass " + id.Item3 + " not exist. (" + id.Item1 + ", " + id.Item2 + ")"); } return null; } @@ -182,7 +185,6 @@ namespace BlubbFish.IoT.Zway.Interfaces { #endregion #region SetValues - protected void SetInt(Int32 value) { this.http.GetVoid("ZWave.zway/Run/devices[" + this.DeviceId + "].instances[" + this.Instance + "].commandClasses[" + ((Int32)this.Commandclass).ToString() + "].Set(" + value + ")"); } @@ -217,8 +219,25 @@ namespace BlubbFish.IoT.Zway.Interfaces { #endregion - #region Output + #region InternalHelper + protected Dictionary ToDictionarySub() { + Dictionary json = new Dictionary(); + foreach (KeyValuePair item in this.Sub) { + json.Add(item.Key.ToString(), item.Value.ToDictionary()); + } + return json; + } + protected List ToSenmlListSub() { + List list = new List(); + foreach (KeyValuePair item in this.Sub) { + list.AddRange(item.Value.ToSenmlList()); + } + return list; + } + #endregion + + #region IMqtt public String MqttTopic() { return this.DeviceId + "/" + this.Instance + "/" + ((Int32)this.Commandclass).ToString() + (this.IsSub ? "/" + this.SensorId : ""); } @@ -230,19 +249,31 @@ namespace BlubbFish.IoT.Zway.Interfaces { json.Add("Commandclass", this.Commandclass.ToString()); return JsonMapper.ToJson(json); } - - public abstract Dictionary ToDictionary(); - - protected Dictionary ToDictionarySub() { - Dictionary json = new Dictionary(); - foreach (KeyValuePair item in this.Sub) { - json.Add(item.Key.ToString(), item.Value.ToDictionary()); - } - return json; - } - #endregion + #region ISenml + public String ToSenml() { + List l = this.ToSenmlList(); + if(l.Count == 0) { + return null; + } + Dictionary json = new Dictionary { + { "e", l }, + { "bn", "urn:dev:id:" + this.SenmlTopic() }, + { "bt", ((DateTimeOffset)this.LastUpdate).ToUnixTimeSeconds() } + }; + return JsonMapper.ToJson(json); + } + + public String SenmlTopic() { + return this.DeviceId + "/" + this.Instance + "/" + ((Int32)this.Commandclass).ToString() + (this.IsSub ? "/" + this.SensorId : ""); + } + #endregion + + #region Abstract + protected abstract List ToSenmlList(); + public abstract Dictionary ToDictionary(); internal abstract void SetUpdate(JsonData json, Match match); + #endregion } } diff --git a/Zway/Properties/AssemblyInfo.cs b/Zway/Properties/AssemblyInfo.cs index 87b8ea8..2df5c27 100644 --- a/Zway/Properties/AssemblyInfo.cs +++ b/Zway/Properties/AssemblyInfo.cs @@ -10,7 +10,7 @@ using System.Runtime.InteropServices; [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("Zway")] -[assembly: AssemblyCopyright("Copyright © 2017 - 01.01.2018")] +[assembly: AssemblyCopyright("Copyright © 2017 - 03.05.2018")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] @@ -32,5 +32,5 @@ using System.Runtime.InteropServices; // Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden, // indem Sie "*" wie unten gezeigt eingeben: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.3.6.0")] -[assembly: AssemblyFileVersion("1.3.6.0")] +[assembly: AssemblyVersion("1.4.0.0")] +[assembly: AssemblyFileVersion("1.4.0.0")] diff --git a/Zway/Zway.csproj b/Zway/Zway.csproj index 1725bf6..43f3b2d 100644 --- a/Zway/Zway.csproj +++ b/Zway/Zway.csproj @@ -31,9 +31,6 @@ 4 - - ..\packages\LitJson.0.9.0\lib\LitJson.dll - @@ -77,7 +74,14 @@ - + + {91a14cd2-2940-4500-8193-56d37edddbaa} + litjson_4.7.1 + + + {4daada29-c600-4cf3-8ad3-9c97c8d7f632} + Iot-Interfaces + \ No newline at end of file diff --git a/Zway/bin/Release/Iot-Interfaces.dll b/Zway/bin/Release/Iot-Interfaces.dll new file mode 100644 index 0000000..8c2cb2c Binary files /dev/null and b/Zway/bin/Release/Iot-Interfaces.dll differ diff --git a/Zway/bin/Release/LitJson.dll b/Zway/bin/Release/LitJson.dll index f00f11f..d4fa685 100644 Binary files a/Zway/bin/Release/LitJson.dll and b/Zway/bin/Release/LitJson.dll differ diff --git a/Zway/bin/Release/Zway.dll b/Zway/bin/Release/Zway.dll index 991904e..35c2912 100644 Binary files a/Zway/bin/Release/Zway.dll and b/Zway/bin/Release/Zway.dll differ diff --git a/Zway/packages.config b/Zway/packages.config deleted file mode 100644 index 6cbb4e9..0000000 --- a/Zway/packages.config +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file