[NF] v1.3.0.0 Remove Interface ICommandClass.cs and dublicated classes CommandClass.cs and CommandClassSub.cs, put them into the abstracted class ACommandClass.cs

[NF] v1.2.0.0 Change classid to enum, so its more readable
[NF] v1.1.0.0 Rename a lot of internal functions
This commit is contained in:
BlubbFish 2017-12-17 20:05:03 +00:00
parent 1445a16930
commit d439471051
24 changed files with 439 additions and 316 deletions

View File

@ -1,103 +0,0 @@
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 {
public abstract class CommandClass : ICommandClass {
protected HttpConnection http;
public abstract event UpdatedValue Update;
private enum Ignored {
Basic = 32,
ManufacturerSpecific = 114,
PowerLevel = 115,
Protection = 117,
NodeNaming = 119,
FirmwareUpdate = 122,
Association = 133,
Version = 134,
MultiChannelAssociation = 142,
MultiCmd = 143
}
public Int32 DeviceId { get; }
public Int32 Instance { get; }
public Int32 Commandclass { get; }
public String Id { get; }
public DateTime LastUpdate { get; private set; }
public String Name { get; }
public Boolean Polling { get; set; }
protected CommandClass(JsonData json, HttpConnection http, Tuple<Int32, Int32, Int32> id, Boolean polling) {
this.DeviceId = id.Item1;
this.Instance = id.Item2;
this.Commandclass = id.Item3;
this.http = http;
this.LastUpdate = DateTime.Now;
this.Polling = polling;
this.Id = this.DeviceId + "-" + this.Instance + "-" + this.Commandclass;
if (ZwayController.namelist.ContainsKey(this.Id)) {
this.Name = ZwayController.namelist[this.Id];
}
}
protected Boolean CheckSetUpdateTime(JsonData json) {
if (json.Keys.Contains("updateTime") && (json["updateTime"].IsInt || json["updateTime"].IsLong)) {
DateTime newdate = DateTimeOffset.FromUnixTimeSeconds(Int64.Parse(json["updateTime"].ToString())).ToLocalTime().DateTime;
if(newdate > this.LastUpdate) {
this.LastUpdate = newdate;
return true;
} else {
return false;
}
} else {
return true;
}
}
internal static CommandClass CreateInstance(JsonData json, Tuple<Int32, Int32, Int32> id, HttpConnection http, Boolean polling) {
if (json.Keys.Contains("name") &&
json.Keys.Contains("data") &&
json["data"].Keys.Contains("supported") &&
json["data"]["supported"].Keys.Contains("value") &&
Boolean.Parse(json["data"]["supported"]["value"].ToString()) &&
!Enum.IsDefined(typeof(Ignored), id.Item3)) {
String name = json["name"].ToString();
String objectName = "BlubbFish.IoT.Zway.Devices.CommandClasses." + name[0].ToString().ToUpper() + name.Substring(1).ToLower();
return GetInstanceConcrete(objectName, json, http, id, polling);
}
return null;
}
private static CommandClass GetInstanceConcrete(String objectName, JsonData json, HttpConnection http, Tuple<Int32, Int32, Int32> id, Boolean polling) {
Type t = null;
try {
t = Type.GetType(objectName, true);
} catch (TypeLoadException) {
Console.Error.WriteLine("Konnte Type " + objectName + " nicht laden!");
return null;
}
return (CommandClass)t.GetConstructor(new Type[] { typeof(JsonData), typeof(HttpConnection), typeof(Tuple<Int32, Int32, Int32>), typeof(Boolean) }).Invoke(new Object[] { json, http, id, polling });
}
internal abstract void SetUpdate(JsonData json, Match match);
internal virtual void Poll() {
if(this.Polling) {
this.http.GetVoid("ZWave.zway/Run/devices[" + this.DeviceId + "].instances[" + this.Instance + "].commandClasses[" + this.Commandclass + "].Get()");
}
}
protected void SetInt(Int32 value) {
this.http.GetVoid("ZWave.zway/Run/devices[" + this.DeviceId + "].instances[" + this.Instance + "].commandClasses[" + this.Commandclass + "].Set("+value+")");
}
protected void SetIntTuple(Int32 value1, Int32 value2) {
this.http.GetVoid("ZWave.zway/Run/devices[" + this.DeviceId + "].instances[" + this.Instance + "].commandClasses[" + this.Commandclass + "].Set(" + value1 + "," + value2 + ")");
}
}
}

View File

@ -1,52 +0,0 @@
using System;
using System.Text.RegularExpressions;
using BlubbFish.IoT.Zway.Interfaces;
using BlubbFish.IoT.Zway.lib;
using LitJson;
namespace BlubbFish.IoT.Zway.Devices {
public abstract class CommandClassSub : ICommandClass {
protected HttpConnection http;
public abstract event UpdatedValue Update;
public String Id { get; }
public Int32 DeviceId { get; }
public Int32 Instance { get; }
public Int32 Commandclass { get; }
public Int32 SensorId { get; }
public String Name { get; }
public DateTime LastUpdate { get; private set; }
public Boolean Polling { get; set; }
protected CommandClassSub(JsonData json, Tuple<Int32, Int32, Int32, Int32> id, HttpConnection http, Boolean polling) {
this.DeviceId = id.Item1;
this.Instance = id.Item2;
this.Commandclass = id.Item3;
this.SensorId = id.Item4;
this.http = http;
this.LastUpdate = DateTime.Now;
this.Polling = polling;
this.Id = this.DeviceId + "-" + this.Instance + "-" + this.Commandclass + "-" + this.SensorId;
if (ZwayController.namelist.ContainsKey(this.Id)) {
this.Name = ZwayController.namelist[this.Id];
}
}
protected Boolean CheckSetUpdateTime(JsonData json) {
if (json.Keys.Contains("updateTime") && (json["updateTime"].IsInt || json["updateTime"].IsLong)) {
DateTime newdate = DateTimeOffset.FromUnixTimeSeconds(Int64.Parse(json["updateTime"].ToString())).ToLocalTime().DateTime;
if (newdate > this.LastUpdate) {
this.LastUpdate = newdate;
return true;
} else {
return false;
}
} else {
return true;
}
}
internal abstract void SetUpdate(JsonData json, Match match);
internal abstract void Poll();
}
}

View File

@ -1,4 +1,5 @@
using System; using System;
using System.Collections.Generic;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using BlubbFish.IoT.Zway.Events; using BlubbFish.IoT.Zway.Events;
using BlubbFish.IoT.Zway.Interfaces; using BlubbFish.IoT.Zway.Interfaces;
@ -9,13 +10,13 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses {
/// <summary> /// <summary>
/// 128 = Battery /// 128 = Battery
/// </summary> /// </summary>
public class Battery : CommandClass { public class Battery : ACommandClass {
public Single Level { get; private set; } public Single Level { get; private set; }
public override event UpdatedValue Update; public override event UpdatedValue Update;
public Battery(JsonData json, HttpConnection http, Tuple<Int32, Int32, Int32> id, Boolean polling) : base(json, http, id, polling) { public Battery(JsonData json, Tuple<Int32, Int32, Classes> id, HttpConnection http, Boolean polling) : base(json, id, http, polling) {
this.InitComplex(json); this.InitComplex(json);
} }
@ -50,5 +51,11 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses {
public override String ToString() { public override String ToString() {
return "Battery " + this.Name + " [" + this.Id + "]: " + this.Level; return "Battery " + this.Name + " [" + this.Id + "]: " + this.Level;
} }
public override Dictionary<String, Object> ToDictionary() {
return new Dictionary<String, Object> {
{ "level", this.Level.ToString() },
};
}
} }
} }

View File

@ -11,14 +11,14 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses {
/// <summary> /// <summary>
/// 91 = CentralScene /// 91 = CentralScene
/// </summary> /// </summary>
public class Centralscene : CommandClass { public class Centralscene : ACommandClass {
public override event UpdatedValue Update; public override event UpdatedValue Update;
public ReadOnlyDictionary<Int32, ReadOnlyCollection<Int32>> ValidScenesModes { get; private set; } public ReadOnlyDictionary<Int32, ReadOnlyCollection<Int32>> ValidScenesModes { get; private set; }
public Int32 Scene { get; private set; } public Int32 Scene { get; private set; }
public Int32 Key { get; private set; } public Int32 Key { get; private set; }
public Centralscene(JsonData json, HttpConnection http, Tuple<Int32, Int32, Int32> id, Boolean polling) : base(json, http, id, polling) { public Centralscene(JsonData json, Tuple<Int32, Int32, Classes> id, HttpConnection http, Boolean polling) : base(json, id, http, polling) {
this.ValidScenesModes = new ReadOnlyDictionary<Int32, ReadOnlyCollection<Int32>>(new Dictionary<Int32, ReadOnlyCollection<Int32>>()); this.ValidScenesModes = new ReadOnlyDictionary<Int32, ReadOnlyCollection<Int32>>(new Dictionary<Int32, ReadOnlyCollection<Int32>>());
this.InitComplex(json); this.InitComplex(json);
} }
@ -74,7 +74,13 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses {
return "CentralScene " + this.Name + " [" + this.Id + "]: " + this.Scene+"-"+this.Key; return "CentralScene " + this.Name + " [" + this.Id + "]: " + this.Scene+"-"+this.Key;
} }
internal override void Poll() { internal override void Poll() => this.PollNone();
public override Dictionary<String, Object> ToDictionary() {
return new Dictionary<String, Object> {
{ "scene", this.Scene.ToString() },
{ "key", this.Key.ToString() },
};
} }
} }
} }

View File

@ -1,4 +1,5 @@
using System; using System;
using System.Collections.Generic;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using BlubbFish.IoT.Zway.Events; using BlubbFish.IoT.Zway.Events;
using BlubbFish.IoT.Zway.Interfaces; using BlubbFish.IoT.Zway.Interfaces;
@ -6,10 +7,9 @@ using BlubbFish.IoT.Zway.lib;
using LitJson; using LitJson;
namespace BlubbFish.IoT.Zway.Devices.CommandClasses.CommandClassSubs { namespace BlubbFish.IoT.Zway.Devices.CommandClasses.CommandClassSubs {
class Configurationsub : CommandClassSub { class Configurationsub : ACommandClass {
private Int64 _level;
public override event UpdatedValue Update; public override event UpdatedValue Update;
private Int64 _level;
public Int64 Level { public Int64 Level {
get { get {
@ -27,7 +27,8 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses.CommandClassSubs {
} }
public Int32 Size { get; private set; } public Int32 Size { get; private set; }
public Configurationsub(JsonData json, Tuple<Int32, Int32, Int32, Int32> id, HttpConnection http, Boolean polling) : base(json, id, http, polling) { public Configurationsub(JsonData json, Tuple<Int32, Int32, Classes, Int32> id, HttpConnection http, Boolean polling) : base(json, id, http, polling) {
this.IsSub = true;
InitComplex(json); InitComplex(json);
} }
@ -42,11 +43,7 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses.CommandClassSubs {
} }
} }
internal override void Poll() { internal override void Poll() => this.PollSub();
if(this.Polling) {
this.http.GetVoid("ZWave.zway/Run/devices[" + this.DeviceId + "].instances[" + this.Instance + "].commandClasses[" + this.Commandclass + "].Get("+this.SensorId+")");
}
}
internal override void SetUpdate(JsonData json, Match match) { internal override void SetUpdate(JsonData json, Match match) {
if (json.Keys.Contains("val") && json["val"].Keys.Contains("value") && json["val"]["value"] != null && if (json.Keys.Contains("val") && json["val"].Keys.Contains("value") && json["val"]["value"] != null &&
@ -61,5 +58,12 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses.CommandClassSubs {
public override String ToString() { public override String ToString() {
return "Configuration " + this.Name + " [" + this.Id + "]: " + this.Level; return "Configuration " + this.Name + " [" + this.Id + "]: " + this.Level;
} }
public override Dictionary<String, Object> ToDictionary() {
return new Dictionary<String, Object> {
{ "level", this.Level.ToString() },
{ "size", this.Size.ToString() },
};
}
} }
} }

View File

@ -1,4 +1,5 @@
using System; using System;
using System.Collections.Generic;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using BlubbFish.IoT.Zway.Events; using BlubbFish.IoT.Zway.Events;
using BlubbFish.IoT.Zway.Interfaces; using BlubbFish.IoT.Zway.Interfaces;
@ -6,20 +7,18 @@ using BlubbFish.IoT.Zway.lib;
using LitJson; using LitJson;
namespace BlubbFish.IoT.Zway.Devices.CommandClasses.CommandClassSubs { namespace BlubbFish.IoT.Zway.Devices.CommandClasses.CommandClassSubs {
public class Metersub : CommandClassSub { public class Metersub : ACommandClass {
public override event UpdatedValue Update; public override event UpdatedValue Update;
public String Type { get; private set; } public String Type { get; private set; }
public Single Level { get; private set; } public Single Level { get; private set; }
public String Scale { get; private set; } public String Scale { get; private set; }
public Metersub(JsonData json, Tuple<Int32, Int32, Int32, Int32> id, HttpConnection http, Boolean polling) : base(json, id, http, polling) { public Metersub(JsonData json, Tuple<Int32, Int32, Classes, Int32> id, HttpConnection http, Boolean polling) : base(json, id, http, polling) {
this.HasReset = true;
this.IsSub = true;
InitComplex(json); InitComplex(json);
} }
public void Reset() {
this.http.GetVoid("ZWave.zway/Run/devices[" + this.DeviceId + "].instances[" + this.Instance + "].commandClasses[" + this.Commandclass + "].Reset()");
}
private void InitComplex(JsonData json) { private void InitComplex(JsonData json) {
if (json.Keys.Contains("sensorTypeString") && if (json.Keys.Contains("sensorTypeString") &&
json["sensorTypeString"].Keys.Contains("value") && json["sensorTypeString"].Keys.Contains("value") &&
@ -49,6 +48,14 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses.CommandClassSubs {
return "Meter " + this.Name + " [" + this.Id + "]: " + this.Type + " " + this.Level + "" + this.Scale; return "Meter " + this.Name + " [" + this.Id + "]: " + this.Type + " " + this.Level + "" + this.Scale;
} }
internal override void Poll() { } internal override void Poll() => this.PollNone();
public override Dictionary<String, Object> ToDictionary() {
return new Dictionary<String, Object> {
{ "level", this.Level.ToString() },
{ "type", this.Type },
{ "scale", this.Scale },
};
}
} }
} }

View File

@ -1,4 +1,5 @@
using System; using System;
using System.Collections.Generic;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using BlubbFish.IoT.Zway.Events; using BlubbFish.IoT.Zway.Events;
using BlubbFish.IoT.Zway.Interfaces; using BlubbFish.IoT.Zway.Interfaces;
@ -6,13 +7,15 @@ using BlubbFish.IoT.Zway.lib;
using LitJson; using LitJson;
namespace BlubbFish.IoT.Zway.Devices.CommandClasses.CommandClassSubs { namespace BlubbFish.IoT.Zway.Devices.CommandClasses.CommandClassSubs {
public class Sensormultilevelsub : CommandClassSub { public class Sensormultilevelsub : ACommandClass {
public override event UpdatedValue Update; public override event UpdatedValue Update;
public String Type { get; private set; } public String Type { get; private set; }
public Single Level { get; private set; } public Single Level { get; private set; }
public String Scale { get; private set; } public String Scale { get; private set; }
public Sensormultilevelsub(JsonData json, Tuple<Int32, Int32, Int32, Int32> id, HttpConnection http, Boolean polling) : base(json, id, http, polling) { public Sensormultilevelsub(JsonData json, Tuple<Int32, Int32, Classes, Int32> id, HttpConnection http, Boolean polling) : base(json, id, http, polling) {
this.IsSub = true;
InitComplex(json); InitComplex(json);
} }
@ -45,6 +48,14 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses.CommandClassSubs {
return "SensorMultilevel " + this.Name + " [" + this.Id + "]: " + this.Type + " " + this.Level + "" + this.Scale; return "SensorMultilevel " + this.Name + " [" + this.Id + "]: " + this.Type + " " + this.Level + "" + this.Scale;
} }
internal override void Poll() { } internal override void Poll() => this.PollNone();
public override Dictionary<String, Object> ToDictionary() {
return new Dictionary<String, Object> {
{ "level", this.Level.ToString() },
{ "type", this.Type },
{ "scale", this.Scale },
};
}
} }
} }

View File

@ -1,4 +1,5 @@
using System; using System;
using System.Collections.Generic;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using BlubbFish.IoT.Zway.Events; using BlubbFish.IoT.Zway.Events;
using BlubbFish.IoT.Zway.Interfaces; using BlubbFish.IoT.Zway.Interfaces;
@ -6,19 +7,17 @@ using BlubbFish.IoT.Zway.lib;
using LitJson; using LitJson;
namespace BlubbFish.IoT.Zway.Devices.CommandClasses.CommandClassSubs { namespace BlubbFish.IoT.Zway.Devices.CommandClasses.CommandClassSubs {
class Thermostatsetpointsub : CommandClassSub { class Thermostatsetpointsub : ACommandClass {
private Single _level;
public override event UpdatedValue Update; public override event UpdatedValue Update;
private Single _level;
public Single Level { public Single Level {
get { get {
return this._level; return this._level;
} }
set { set {
if (!this.HasMinMax || (this.HasMinMax && value >= this.TempMin && value <= this.TempMax)) { if (!this.HasMinMax || (this.HasMinMax && value >= this.TempMin && value <= this.TempMax)) {
Single t = (Single)Math.Round(value * 2, MidpointRounding.AwayFromZero) / 2; this.SetTuple(this.SensorId, (Single)Math.Round(value * 2, MidpointRounding.AwayFromZero) / 2);
this.http.GetVoid("ZWave.zway/Run/devices[" + this.DeviceId + "].instances[" + this.Instance + "].commandClasses[" + this.Commandclass + "].Set(" + this.SensorId + "," + t + ")");
} }
} }
} }
@ -28,7 +27,8 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses.CommandClassSubs {
public Boolean HasMinMax { get; private set; } public Boolean HasMinMax { get; private set; }
public String Type { get; private set; } public String Type { get; private set; }
public Thermostatsetpointsub(JsonData json, Tuple<Int32, Int32, Int32, Int32> id, HttpConnection http, Boolean polling) : base(json, id, http, polling) { public Thermostatsetpointsub(JsonData json, Tuple<Int32, Int32, Classes, Int32> id, HttpConnection http, Boolean polling) : base(json, id, http, polling) {
this.IsSub = true;
InitComplex(json); InitComplex(json);
} }
@ -40,7 +40,7 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses.CommandClassSubs {
this._level = Single.Parse(json["val"]["value"].ToString()); this._level = Single.Parse(json["val"]["value"].ToString());
this.Scale = json["deviceScaleString"]["value"].ToString(); this.Scale = json["deviceScaleString"]["value"].ToString();
} }
if(json.Keys.Contains("min") && json["min"].Keys.Contains("value") && if (json.Keys.Contains("min") && json["min"].Keys.Contains("value") &&
json.Keys.Contains("max") && json["max"].Keys.Contains("value")) { json.Keys.Contains("max") && json["max"].Keys.Contains("value")) {
this.TempMin = Single.Parse(json["min"]["value"].ToString()); this.TempMin = Single.Parse(json["min"]["value"].ToString());
this.TempMax = Single.Parse(json["max"]["value"].ToString()); this.TempMax = Single.Parse(json["max"]["value"].ToString());
@ -78,10 +78,17 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses.CommandClassSubs {
return "ThermostatSetPoint " + this.Name + " [" + this.Id + "]: " + this.Type + " " + this.Level + "" + this.Scale + " [" + this.TempMin + "," + this.TempMax + "," + this.HasMinMax + "]"; return "ThermostatSetPoint " + this.Name + " [" + this.Id + "]: " + this.Type + " " + this.Level + "" + this.Scale + " [" + this.TempMin + "," + this.TempMax + "," + this.HasMinMax + "]";
} }
internal override void Poll() { internal override void Poll() => this.PollSub();
if (this.Polling) {
this.http.GetVoid("ZWave.zway/Run/devices[" + this.DeviceId + "].instances[" + this.Instance + "].commandClasses[" + this.Commandclass + "].Get(" + this.SensorId + ")"); public override Dictionary<String, Object> ToDictionary() {
} return new Dictionary<String, Object> {
{ "level", this.Level.ToString() },
{ "type", this.Type },
{ "scale", this.Scale },
{ "tempmax", this.TempMax.ToString() },
{ "tempmin", this.TempMin.ToString() },
{ "hasminmax", this.HasMinMax.ToString() },
};
} }
} }
} }

View File

@ -12,13 +12,13 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses {
/// <summary> /// <summary>
/// 112 = Configuration /// 112 = Configuration
/// </summary> /// </summary>
class Configuration : CommandClass { class Configuration : ACommandClass {
public override event UpdatedValue Update; public override event UpdatedValue Update;
public ReadOnlyDictionary<Int32, CommandClassSub> Sub { get; private set; } public Configuration(JsonData json, Tuple<Int32, Int32, Classes> id, HttpConnection http, Boolean polling) : base(json, id, http, polling) {
public Configuration(JsonData json, HttpConnection http, Tuple<Int32, Int32, Int32> id, Boolean polling) : base(json, http, id, polling) { this.HasSub = true;
this.InitComplex(json); this.InitComplex(json);
foreach (KeyValuePair<Int32, CommandClassSub> item in this.Sub) { foreach (KeyValuePair<Int32, ACommandClass> item in this.Sub) {
item.Value.Update += this.DeviceUpdate; item.Value.Update += this.DeviceUpdate;
} }
} }
@ -30,17 +30,17 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses {
private void InitComplex(JsonData json) { private void InitComplex(JsonData json) {
if (json.Keys.Contains("data")) { if (json.Keys.Contains("data")) {
JsonData data = json["data"]; JsonData data = json["data"];
Dictionary<Int32, CommandClassSub> subs = new Dictionary<Int32, CommandClassSub>(); Dictionary<Int32, ACommandClass> subs = new Dictionary<Int32, ACommandClass>();
foreach (String item in data.Keys) { foreach (String item in data.Keys) {
if (Int32.TryParse(item, out Int32 subid) && if (Int32.TryParse(item, out Int32 subid) &&
data[item].Keys.Contains("size") && data[item].Keys.Contains("size") &&
data[item].Keys.Contains("val") && data[item].Keys.Contains("val") &&
data[item]["val"].Keys.Contains("value") && data[item]["val"].Keys.Contains("value") &&
data[item]["val"]["value"] != null) { data[item]["val"]["value"] != null) {
subs.Add(subid, new Configurationsub(data[item], new Tuple<Int32, Int32, Int32, Int32>(this.DeviceId, this.Instance, this.Commandclass, subid), this.http, this.Polling)); subs.Add(subid, new Configurationsub(data[item], new Tuple<Int32, Int32, Classes, Int32>(this.DeviceId, this.Instance, this.Commandclass, subid), this.http, this.Polling));
} }
} }
this.Sub = new ReadOnlyDictionary<Int32, CommandClassSub>(subs); this.Sub = new ReadOnlyDictionary<Int32, ACommandClass>(subs);
} }
} }
@ -55,10 +55,8 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses {
} }
} }
internal override void Poll() { internal override void Poll() => this.PollPerSub();
foreach (KeyValuePair<Int32, CommandClassSub> item in this.Sub) {
item.Value.Poll(); public override Dictionary<String, Object> ToDictionary() => this.ToDictionarySub();
}
}
} }
} }

View File

@ -1,4 +1,5 @@
using System; using System;
using System.Collections.Generic;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using BlubbFish.IoT.Zway.Events; using BlubbFish.IoT.Zway.Events;
using BlubbFish.IoT.Zway.Interfaces; using BlubbFish.IoT.Zway.Interfaces;
@ -9,7 +10,7 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses {
/// <summary> /// <summary>
/// 135 = Indicator /// 135 = Indicator
/// </summary> /// </summary>
class Indicator : CommandClass { class Indicator : ACommandClass {
private Boolean _level; private Boolean _level;
public override event UpdatedValue Update; public override event UpdatedValue Update;
@ -22,7 +23,7 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses {
} }
} }
public Indicator(JsonData json, HttpConnection http, Tuple<Int32, Int32, Int32> id, Boolean polling) : base(json, http, id, polling) { public Indicator(JsonData json, Tuple<Int32, Int32, Classes> id, HttpConnection http, Boolean polling) : base(json, id, http, polling) {
this.InitComplex(json); this.InitComplex(json);
} }
@ -46,5 +47,11 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses {
public override String ToString() { public override String ToString() {
return "Indicator " + this.Name + " [" + this.Id + "]: " + this.Level; return "Indicator " + this.Name + " [" + this.Id + "]: " + this.Level;
} }
public override Dictionary<String, Object> ToDictionary() {
return new Dictionary<String, Object> {
{ "level", this.Level.ToString() },
};
}
} }
} }

View File

@ -12,15 +12,13 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses {
/// <summary> /// <summary>
/// 50 = Meter /// 50 = Meter
/// </summary> /// </summary>
public class Meter : CommandClass { public class Meter : ACommandClass {
public override event UpdatedValue Update; public override event UpdatedValue Update;
public ReadOnlyDictionary<Int32, CommandClassSub> Sub { get; private set; } public Meter(JsonData json, Tuple<Int32, Int32, Classes> id, HttpConnection http, Boolean polling) : base(json, id, http, polling) {
this.HasSub = true;
public Meter(JsonData json, HttpConnection http, Tuple<Int32, Int32, Int32> id, Boolean polling) : base(json, http, id, polling) {
this.InitComplex(json); this.InitComplex(json);
foreach (KeyValuePair<Int32, CommandClassSub> item in this.Sub) { foreach (KeyValuePair<Int32, ACommandClass> item in this.Sub) {
item.Value.Update += this.DeviceUpdate; item.Value.Update += this.DeviceUpdate;
} }
} }
@ -43,29 +41,21 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses {
private void InitComplex(JsonData json) { private void InitComplex(JsonData json) {
if (json.Keys.Contains("data")) { if (json.Keys.Contains("data")) {
JsonData data = json["data"]; JsonData data = json["data"];
Dictionary<Int32, CommandClassSub> subs = new Dictionary<Int32, CommandClassSub>(); Dictionary<Int32, ACommandClass> subs = new Dictionary<Int32, ACommandClass>();
foreach (String item in data.Keys) { foreach (String item in data.Keys) {
if (Int32.TryParse(item, out Int32 subid) && if (Int32.TryParse(item, out Int32 subid) &&
data[item].Keys.Contains("sensorTypeString") && data[item].Keys.Contains("sensorTypeString") &&
data[item].Keys.Contains("val") && data[item].Keys.Contains("val") &&
data[item].Keys.Contains("scaleString")) { data[item].Keys.Contains("scaleString")) {
subs.Add(subid, new Metersub(data[item], new Tuple<Int32, Int32, Int32, Int32>(this.DeviceId, this.Instance, this.Commandclass, subid), this.http, this.Polling)); subs.Add(subid, new Metersub(data[item], new Tuple<Int32, Int32, Classes, Int32>(this.DeviceId, this.Instance, this.Commandclass, subid), this.http, this.Polling));
} }
} }
this.Sub = new ReadOnlyDictionary<Int32, CommandClassSub>(subs); this.Sub = new ReadOnlyDictionary<Int32, ACommandClass>(subs);
} }
} }
internal override void Poll() { internal override void Poll() => this.PollSubGlobal();
Boolean poll = false;
foreach (KeyValuePair<Int32, CommandClassSub> item in this.Sub) { public override Dictionary<String, Object> ToDictionary() => this.ToDictionarySub();
if (item.Value.Polling) {
poll = true;
}
}
if (poll) {
this.http.GetVoid("ZWave.zway/Run/devices[" + this.DeviceId + "].instances[" + this.Instance + "].commandClasses[" + this.Commandclass + "].Get()");
}
}
} }
} }

View File

@ -12,15 +12,13 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses {
/// <summary> /// <summary>
/// 49 = SensorMultilevel /// 49 = SensorMultilevel
/// </summary> /// </summary>
public class Sensormultilevel : CommandClass { public class Sensormultilevel : ACommandClass {
public override event UpdatedValue Update; public override event UpdatedValue Update;
public ReadOnlyDictionary<Int32, CommandClassSub> Sub { get; private set; } public Sensormultilevel(JsonData json, Tuple<Int32, Int32, Classes> id, HttpConnection http, Boolean polling) : base(json, id, http, polling) {
this.HasSub = true;
public Sensormultilevel(JsonData json, HttpConnection http, Tuple<Int32, Int32, Int32> id, Boolean polling) : base(json, http, id, polling) {
this.InitComplex(json); this.InitComplex(json);
foreach (KeyValuePair<Int32, CommandClassSub> item in this.Sub) { foreach (KeyValuePair<Int32, ACommandClass> item in this.Sub) {
item.Value.Update += this.DeviceUpdate; item.Value.Update += this.DeviceUpdate;
} }
} }
@ -43,29 +41,21 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses {
private void InitComplex(JsonData json) { private void InitComplex(JsonData json) {
if (json.Keys.Contains("data")) { if (json.Keys.Contains("data")) {
JsonData data = json["data"]; JsonData data = json["data"];
Dictionary<Int32, CommandClassSub> subs = new Dictionary<Int32, CommandClassSub>(); Dictionary<Int32, ACommandClass> subs = new Dictionary<Int32, ACommandClass>();
foreach (String item in data.Keys) { foreach (String item in data.Keys) {
if (Int32.TryParse(item, out Int32 subid) && if (Int32.TryParse(item, out Int32 subid) &&
data[item].Keys.Contains("sensorTypeString") && data[item].Keys.Contains("sensorTypeString") &&
data[item].Keys.Contains("val") && data[item].Keys.Contains("val") &&
data[item].Keys.Contains("scaleString")) { data[item].Keys.Contains("scaleString")) {
subs.Add(subid, new Sensormultilevelsub(data[item], new Tuple<Int32, Int32, Int32, Int32>(this.DeviceId, this.Instance, this.Commandclass, subid), this.http, this.Polling)); subs.Add(subid, new Sensormultilevelsub(data[item], new Tuple<Int32, Int32, Classes, Int32>(this.DeviceId, this.Instance, this.Commandclass, subid), this.http, this.Polling));
} }
} }
this.Sub = new ReadOnlyDictionary<Int32, CommandClassSub>(subs); this.Sub = new ReadOnlyDictionary<Int32, ACommandClass>(subs);
} }
} }
internal override void Poll() { internal override void Poll() => this.PollSubGlobal();
Boolean poll = false;
foreach (KeyValuePair<Int32, CommandClassSub> item in this.Sub) { public override Dictionary<String, Object> ToDictionary() => this.ToDictionarySub();
if (item.Value.Polling) {
poll = true;
}
}
if (poll) {
this.http.GetVoid("ZWave.zway/Run/devices[" + this.DeviceId + "].instances[" + this.Instance + "].commandClasses[" + this.Commandclass + "].Get()");
}
}
} }
} }

View File

@ -1,4 +1,5 @@
using System; using System;
using System.Collections.Generic;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using BlubbFish.IoT.Zway.Events; using BlubbFish.IoT.Zway.Events;
using BlubbFish.IoT.Zway.Interfaces; using BlubbFish.IoT.Zway.Interfaces;
@ -9,7 +10,7 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses {
/// <summary> /// <summary>
/// 37 = SwitchBinary /// 37 = SwitchBinary
/// </summary> /// </summary>
public class Switchbinary : CommandClass { public class Switchbinary : ACommandClass {
private Boolean _level; private Boolean _level;
public override event UpdatedValue Update; public override event UpdatedValue Update;
@ -23,7 +24,7 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses {
} }
} }
public Switchbinary(JsonData json, HttpConnection http, Tuple<Int32, Int32, Int32> id, Boolean polling) : base(json, http, id, polling) { public Switchbinary(JsonData json, Tuple<Int32, Int32, Classes> id, HttpConnection http, Boolean polling) : base(json, id, http, polling) {
this.InitComplex(json); this.InitComplex(json);
} }
@ -47,5 +48,11 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses {
public override String ToString() { public override String ToString() {
return "SwitchBinary " + this.Name + " [" + this.Id + "]: " + this.Level; return "SwitchBinary " + this.Name + " [" + this.Id + "]: " + this.Level;
} }
public override Dictionary<String, Object> ToDictionary() {
return new Dictionary<String, Object> {
{ "level", this.Level.ToString() }
};
}
} }
} }

View File

@ -1,4 +1,5 @@
using System; using System;
using System.Collections.Generic;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using BlubbFish.IoT.Zway.Events; using BlubbFish.IoT.Zway.Events;
using BlubbFish.IoT.Zway.Interfaces; using BlubbFish.IoT.Zway.Interfaces;
@ -9,7 +10,7 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses {
/// <summary> /// <summary>
/// 38 = SwitchMultilevel /// 38 = SwitchMultilevel
/// </summary> /// </summary>
public class Switchmultilevel : CommandClass { public class Switchmultilevel : ACommandClass {
private Int32 _level; private Int32 _level;
public override event UpdatedValue Update; public override event UpdatedValue Update;
@ -20,12 +21,12 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses {
} }
set { set {
if(value == 0 || (value > 0 && value <= 99) || value == 255) { if(value == 0 || (value > 0 && value <= 99) || value == 255) {
this.SetIntTuple(value, 0); this.SetTuple(value, 0);
} }
} }
} }
public Switchmultilevel(JsonData json, HttpConnection http, Tuple<Int32, Int32, Int32> id, Boolean polling) : base(json, http, id, polling) { public Switchmultilevel(JsonData json, Tuple<Int32, Int32, Classes> id, HttpConnection http, Boolean polling) : base(json, id, http, polling) {
this.InitComplex(json); this.InitComplex(json);
} }
@ -50,5 +51,11 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses {
public override String ToString() { public override String ToString() {
return "SwitchMultilevel " + this.Name + " [" + this.Id + "]: " + this.Level; return "SwitchMultilevel " + this.Name + " [" + this.Id + "]: " + this.Level;
} }
public override Dictionary<String, Object> ToDictionary() {
return new Dictionary<String, Object> {
{ "level", this.Level.ToString() }
};
}
} }
} }

View File

@ -11,7 +11,7 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses {
/// <summary> /// <summary>
/// 64 = ThermostatMode /// 64 = ThermostatMode
/// </summary> /// </summary>
public class Thermostatmode : CommandClass { public class Thermostatmode : ACommandClass {
private Int32 _level; private Int32 _level;
public override event UpdatedValue Update; public override event UpdatedValue Update;
@ -26,7 +26,7 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses {
} }
} }
public Thermostatmode(JsonData json, HttpConnection http, Tuple<Int32, Int32, Int32> id, Boolean polling) : base(json, http, id, polling) { public Thermostatmode(JsonData json, Tuple<Int32, Int32, Classes> id, HttpConnection http, Boolean polling) : base(json, id, http, polling) {
this.ValidModes = new ReadOnlyDictionary<Int32, String>(new Dictionary<Int32, String>()); this.ValidModes = new ReadOnlyDictionary<Int32, String>(new Dictionary<Int32, String>());
this.InitComplex(json); this.InitComplex(json);
} }
@ -64,5 +64,17 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses {
public override String ToString() { public override String ToString() {
return "ThermostatMode " + this.Name + " [" + this.Id + "]: " + this.ValidModes[this.Level]; return "ThermostatMode " + this.Name + " [" + this.Id + "]: " + this.ValidModes[this.Level];
} }
public override Dictionary<String, Object> ToDictionary() {
Dictionary<String, String> modes = new Dictionary<String, String>();
foreach (KeyValuePair<Int32, String> item in this.ValidModes) {
modes.Add(item.Key.ToString(), item.Value);
}
Dictionary<String, Object> json = new Dictionary<String, Object> {
{ "level", this.Level.ToString() },
{ "modes", modes }
};
return json;
}
} }
} }

View File

@ -12,14 +12,13 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses {
/// <summary> /// <summary>
/// 67 = ThermostatSetPoint /// 67 = ThermostatSetPoint
/// </summary> /// </summary>
public class Thermostatsetpoint : CommandClass { public class Thermostatsetpoint : ACommandClass {
public override event UpdatedValue Update; public override event UpdatedValue Update;
public ReadOnlyDictionary<Int32, CommandClassSub> Sub { get; private set; } public Thermostatsetpoint(JsonData json, Tuple<Int32, Int32, Classes> id, HttpConnection http, Boolean polling) : base(json, id, http, polling) {
this.HasSub = true;
public Thermostatsetpoint(JsonData json, HttpConnection http, Tuple<Int32, Int32, Int32> id, Boolean polling) : base(json, http, id, polling) {
this.InitComplex(json); this.InitComplex(json);
foreach (KeyValuePair<Int32, CommandClassSub> item in this.Sub) { foreach (KeyValuePair<Int32, ACommandClass> item in this.Sub) {
item.Value.Update += this.DeviceUpdate; item.Value.Update += this.DeviceUpdate;
} }
} }
@ -42,23 +41,21 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses {
private void InitComplex(JsonData json) { private void InitComplex(JsonData json) {
if (json.Keys.Contains("data")) { if (json.Keys.Contains("data")) {
JsonData data = json["data"]; JsonData data = json["data"];
Dictionary<Int32, CommandClassSub> subs = new Dictionary<Int32, CommandClassSub>(); Dictionary<Int32, ACommandClass> subs = new Dictionary<Int32, ACommandClass>();
foreach (String item in data.Keys) { foreach (String item in data.Keys) {
if (Int32.TryParse(item, out Int32 subid) && if (Int32.TryParse(item, out Int32 subid) &&
data[item].Keys.Contains("modeName") && data[item].Keys.Contains("modeName") &&
data[item].Keys.Contains("val") && data[item].Keys.Contains("val") &&
data[item].Keys.Contains("deviceScaleString")) { data[item].Keys.Contains("deviceScaleString")) {
subs.Add(subid, new Thermostatsetpointsub(data[item], new Tuple<Int32, Int32, Int32, Int32>(this.DeviceId, this.Instance, this.Commandclass, subid), this.http, this.Polling)); subs.Add(subid, new Thermostatsetpointsub(data[item], new Tuple<Int32, Int32, Classes, Int32>(this.DeviceId, this.Instance, this.Commandclass, subid), this.http, this.Polling));
} }
} }
this.Sub = new ReadOnlyDictionary<Int32, CommandClassSub>(subs); this.Sub = new ReadOnlyDictionary<Int32, ACommandClass>(subs);
} }
} }
internal override void Poll() { internal override void Poll() => this.PollPerSub();
foreach (KeyValuePair<Int32, CommandClassSub> item in this.Sub) {
item.Value.Poll(); public override Dictionary<String, Object> ToDictionary() => this.ToDictionarySub();
}
}
} }
} }

View File

@ -1,4 +1,5 @@
using System; using System;
using System.Collections.Generic;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using BlubbFish.IoT.Zway.Events; using BlubbFish.IoT.Zway.Events;
using BlubbFish.IoT.Zway.Interfaces; using BlubbFish.IoT.Zway.Interfaces;
@ -9,7 +10,7 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses {
/// <summary> /// <summary>
/// 132 = Wakeup /// 132 = Wakeup
/// </summary> /// </summary>
class Wakeup : CommandClass { class Wakeup : ACommandClass {
private Int32 _interval; private Int32 _interval;
private Int32 _againstNode; private Int32 _againstNode;
@ -20,7 +21,7 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses {
} }
set { set {
if(value >= this.WakeupMin && value <= this.WakeupMax) { if(value >= this.WakeupMin && value <= this.WakeupMax) {
this.SetIntTuple(value, this.AgainstNode); this.SetTuple(value, this.AgainstNode);
} }
} }
} }
@ -28,7 +29,7 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses {
return this._againstNode; return this._againstNode;
} }
set { set {
this.SetIntTuple(this.Interval, value); this.SetTuple(this.Interval, value);
} }
} }
public Int32 WakeupMin { get; private set; } public Int32 WakeupMin { get; private set; }
@ -37,7 +38,7 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses {
public DateTime LastWakeup { get; private set; } public DateTime LastWakeup { get; private set; }
public DateTime LastSleep { get; private set; } public DateTime LastSleep { get; private set; }
public Wakeup(JsonData json, HttpConnection http, Tuple<Int32, Int32, Int32> id, Boolean polling) : base(json, http, id, polling) { public Wakeup(JsonData json, Tuple<Int32, Int32, Classes> id, HttpConnection http, Boolean polling) : base(json, id, http, polling) {
this.InitComplex(json); this.InitComplex(json);
} }
@ -120,5 +121,15 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses {
public override String ToString() { public override String ToString() {
return "Wakeup " + this.Name + " [" + this.Id + "]: " + this.LastWakeup + "-" + this.LastSleep + " " + this.Interval + " [" + this.WakeupMin + "," + this.WakeupMax + "," + this.WakeupDefault + "," + this.AgainstNode + "]"; return "Wakeup " + this.Name + " [" + this.Id + "]: " + this.LastWakeup + "-" + this.LastSleep + " " + this.Interval + " [" + this.WakeupMin + "," + this.WakeupMax + "," + this.WakeupDefault + "," + this.AgainstNode + "]";
} }
public override Dictionary<String, Object> ToDictionary() {
return new Dictionary<String, Object> {
{ "wakeupmin", this.WakeupMin.ToString() },
{ "wakeupmax", this.WakeupMax.ToString() },
{ "wakeupdefault", this.WakeupDefault.ToString() },
{ "lastwakeup", this.LastWakeup.ToString() },
{ "lastsleep", this.LastSleep.ToString() }
};
}
} }
} }

View File

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using BlubbFish.IoT.Zway.Devices.CommandClasses; using BlubbFish.IoT.Zway.Devices.CommandClasses;
using BlubbFish.IoT.Zway.Events; using BlubbFish.IoT.Zway.Events;
using BlubbFish.IoT.Zway.Interfaces;
using BlubbFish.IoT.Zway.lib; using BlubbFish.IoT.Zway.lib;
using LitJson; using LitJson;
@ -16,22 +17,22 @@ namespace BlubbFish.IoT.Zway.Devices {
public Int32 DeviceId { get; } public Int32 DeviceId { get; }
public Int32 InstanceId { get; } public Int32 InstanceId { get; }
public ReadOnlyDictionary<Int32, CommandClass> CommandClasses { get; private set; } public ReadOnlyDictionary<ACommandClass.Classes, ACommandClass> CommandClasses { get; private set; }
private Instance(JsonData json, Tuple<Int32, Int32> id, HttpConnection http, Boolean polling) { private Instance(JsonData json, Tuple<Int32, Int32> id, HttpConnection http, Boolean polling) {
this.DeviceId = id.Item1; this.DeviceId = id.Item1;
this.InstanceId = id.Item2; this.InstanceId = id.Item2;
this.polling = polling; this.polling = polling;
this.CreateInstances(json["commandClasses"], http); this.CreateInstances(json["commandClasses"], http);
foreach (KeyValuePair<Int32, CommandClass> item in this.CommandClasses) { foreach (KeyValuePair<ACommandClass.Classes, ACommandClass> item in this.CommandClasses) {
item.Value.Update += this.ClassUpdate; item.Value.Update += this.ClassUpdate;
} }
this.MakePolltimer(); this.MakePolltimer();
} }
private void MakePolltimer() { private void MakePolltimer() {
if(this.CommandClasses.ContainsKey(132)) { if(this.CommandClasses.ContainsKey(ACommandClass.Classes.Wakeup)) {
this.nextwakeup = ((Wakeup)this.CommandClasses[132]).LastWakeup.AddSeconds(((Wakeup)this.CommandClasses[132]).Interval).AddSeconds(-20); this.nextwakeup = ((Wakeup)this.CommandClasses[ACommandClass.Classes.Wakeup]).LastWakeup.AddSeconds(((Wakeup)this.CommandClasses[ACommandClass.Classes.Wakeup]).Interval).AddSeconds(-20);
} else { } else {
this.nextwakeup = DateTime.Now.AddSeconds(60); this.nextwakeup = DateTime.Now.AddSeconds(60);
} }
@ -42,14 +43,14 @@ namespace BlubbFish.IoT.Zway.Devices {
} }
private void CreateInstances(JsonData json, HttpConnection http) { private void CreateInstances(JsonData json, HttpConnection http) {
Dictionary<Int32, CommandClass> commands = new Dictionary<Int32, CommandClass>(); Dictionary<ACommandClass.Classes, ACommandClass> commands = new Dictionary<ACommandClass.Classes, ACommandClass>();
foreach (String commandid in json.Keys) { foreach (String commandid in json.Keys) {
CommandClass c = CommandClass.CreateInstance(json[commandid], new Tuple<Int32, Int32, Int32>(this.DeviceId, this.InstanceId, Int32.Parse(commandid)), http, this.polling); ACommandClass c = ACommandClass.CreateInstance(json[commandid], new Tuple<Int32, Int32, ACommandClass.Classes>(this.DeviceId, this.InstanceId, (ACommandClass.Classes)Int32.Parse(commandid)), http, this.polling);
if (c != null) { if (c != null) {
commands.Add(Int32.Parse(commandid), c); commands.Add((ACommandClass.Classes)Int32.Parse(commandid), c);
} }
} }
this.CommandClasses = new ReadOnlyDictionary<Int32, CommandClass>(commands); this.CommandClasses = new ReadOnlyDictionary<ACommandClass.Classes, ACommandClass>(commands);
} }
internal static Instance CreateInstance(JsonData json, Tuple<Int32, Int32> id, HttpConnection http, Boolean polling) { internal static Instance CreateInstance(JsonData json, Tuple<Int32, Int32> id, HttpConnection http, Boolean polling) {
@ -68,7 +69,7 @@ namespace BlubbFish.IoT.Zway.Devices {
internal void Poll() { internal void Poll() {
if(DateTime.Now > this.nextwakeup) { if(DateTime.Now > this.nextwakeup) {
this.MakePolltimer(); this.MakePolltimer();
foreach (KeyValuePair<Int32, CommandClass> item in this.CommandClasses) { foreach (KeyValuePair<ACommandClass.Classes, ACommandClass> item in this.CommandClasses) {
item.Value.Poll(); item.Value.Poll();
} }
} }

View File

@ -0,0 +1,231 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Text.RegularExpressions;
using BlubbFish.IoT.Zway.Events;
using BlubbFish.IoT.Zway.lib;
using LitJson;
namespace BlubbFish.IoT.Zway.Interfaces {
public abstract class ACommandClass {
protected HttpConnection http;
public delegate void UpdatedValue(Object sender, DeviceUpdateEvent e);
public abstract event UpdatedValue Update;
protected enum IgnoredClasses : Int32 {
Basic = 32,
ControllerReplication = 33,
ApplicationStatus = 34,
SensorBinary = 48,
SwitchColor = 51,
MeterPulse = 53,
MultiChannel = 96,
Alarm = 113,
ManufacturerSpecific = 114,
PowerLevel = 115,
Protection = 117,
NodeNaming = 119,
FirmwareUpdate = 122,
Association = 133,
Version = 134,
MultiChannelAssociation = 142,
MultiCmd = 143
}
public enum Classes : Int32 {
SwitchBinary = 37,
SwitchMultilevel = 38,
SensorMultilevel = 49,
Meter = 50,
ThermostatMode = 64,
ThermostatSetPoint = 67,
CentralScene = 91,
Configuration = 112,
Battery = 128,
Wakeup = 132,
Indicator = 135
}
public Int32 DeviceId { get; }
public Int32 Instance { get; }
public Classes Commandclass { get; }
public String Id { get; }
public Int32 SensorId { get; }
public DateTime LastUpdate { get; protected set; }
public String Name { get; }
public Boolean Polling { get; set; }
public Boolean PollOnce { get; set; }
public ReadOnlyDictionary<Int32, ACommandClass> Sub { get; protected set; }
public Boolean HasSub { get; protected set; }
public Boolean IsSub { get; protected set; }
public Boolean HasReset { get; protected set; }
#region Constructor
protected ACommandClass(JsonData json, Tuple<Int32, Int32, Classes, Int32> id, HttpConnection http, Boolean polling) {
this.DeviceId = id.Item1;
this.Instance = id.Item2;
this.Commandclass = id.Item3;
this.SensorId = id.Item4;
this.http = http;
this.LastUpdate = DateTime.Now;
this.Polling = polling;
this.HasSub = false;
this.HasReset = false;
this.IsSub = false;
this.Id = this.DeviceId + "-" + this.Instance + "-" + (Int32)this.Commandclass + "-" + this.SensorId;
if (ZwayController.namelist.ContainsKey(this.Id)) {
this.Name = ZwayController.namelist[this.Id];
}
}
protected ACommandClass(JsonData json, Tuple<Int32, Int32, Classes> id, HttpConnection http, Boolean polling) {
this.DeviceId = id.Item1;
this.Instance = id.Item2;
this.Commandclass = id.Item3;
this.http = http;
this.LastUpdate = DateTime.Now;
this.Polling = polling;
this.HasSub = false;
this.HasReset = false;
this.IsSub = false;
this.Id = this.DeviceId + "-" + this.Instance + "-" + (Int32)this.Commandclass;
if (ZwayController.namelist.ContainsKey(this.Id)) {
this.Name = ZwayController.namelist[this.Id];
}
}
internal static ACommandClass CreateInstance(JsonData json, Tuple<Int32, Int32, Classes> id, HttpConnection http, Boolean polling) {
if (json.Keys.Contains("name") &&
json.Keys.Contains("data") &&
json["data"].Keys.Contains("supported") &&
json["data"]["supported"].Keys.Contains("value") &&
Boolean.Parse(json["data"]["supported"]["value"].ToString()) &&
!Enum.IsDefined(typeof(IgnoredClasses), (Int32)id.Item3) && Enum.IsDefined(typeof(Classes), id.Item3)) {
String name = id.Item3.ToString();
String objectName = "BlubbFish.IoT.Zway.Devices.CommandClasses." + name[0].ToString().ToUpper() + name.Substring(1).ToLower();
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.");
}
return null;
}
private static ACommandClass GetInstanceConcrete(String objectName, JsonData json, HttpConnection http, Tuple<Int32, Int32, Classes> id, Boolean polling) {
Type t = null;
try {
t = Type.GetType(objectName, true);
} catch (TypeLoadException) {
Console.Error.WriteLine("Konnte Type " + objectName + " nicht laden!");
return null;
}
return (ACommandClass)t.GetConstructor(new Type[] { typeof(JsonData), typeof(Tuple<Int32, Int32, Classes>), typeof(HttpConnection), typeof(Boolean) }).Invoke(new Object[] { json, id, http, polling });
}
#endregion
#region Polling
internal virtual void Poll() {
if (this.Polling || this.PollOnce) {
this.PollOnce = false;
this.http.GetVoid("ZWave.zway/Run/devices[" + this.DeviceId + "].instances[" + this.Instance + "].commandClasses[" + ((Int32)this.Commandclass).ToString() + "].Get()");
}
}
protected void PollNone() {
this.PollOnce = false;
}
protected void PollSub() {
if (this.Polling || this.PollOnce) {
this.PollOnce = false;
this.http.GetVoid("ZWave.zway/Run/devices[" + this.DeviceId + "].instances[" + this.Instance + "].commandClasses[" + ((Int32)this.Commandclass).ToString() + "].Get(" + this.SensorId + ")");
}
}
protected void PollPerSub() {
foreach (KeyValuePair<Int32, ACommandClass> item in this.Sub) {
item.Value.Poll();
}
}
protected void PollSubGlobal() {
Boolean poll = false;
foreach (KeyValuePair<Int32, ACommandClass> item in this.Sub) {
if (item.Value.Polling) {
poll = true;
break;
}
}
if (poll) {
this.http.GetVoid("ZWave.zway/Run/devices[" + this.DeviceId + "].instances[" + this.Instance + "].commandClasses[" + ((Int32)this.Commandclass).ToString() + "].Get()");
}
}
#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 + ")");
}
protected void SetTuple(Single value1, Single value2) {
this.http.GetVoid("ZWave.zway/Run/devices[" + this.DeviceId + "].instances[" + this.Instance + "].commandClasses[" + ((Int32)this.Commandclass).ToString() + "].Set(" + value1 + "," + value2 + ")");
}
protected void SetTuple(Int32 v1, Int32 v2) => this.SetTuple(v1, (Single)v2);
protected Boolean CheckSetUpdateTime(JsonData json) {
if (json.Keys.Contains("updateTime") && (json["updateTime"].IsInt || json["updateTime"].IsLong)) {
DateTime newdate = DateTimeOffset.FromUnixTimeSeconds(Int64.Parse(json["updateTime"].ToString())).ToLocalTime().DateTime;
if (newdate > this.LastUpdate) {
this.LastUpdate = newdate;
return true;
} else {
return false;
}
} else {
return true;
}
}
public virtual void Reset() {
if (this.HasReset) {
this.http.GetVoid("ZWave.zway/Run/devices[" + this.DeviceId + "].instances[" + this.Instance + "].commandClasses[" + ((Int32)this.Commandclass).ToString() + "].Reset()");
}
}
#endregion
#region Output
public String MqttTopic() {
return this.DeviceId + "/" + this.Instance + "/" + ((Int32)this.Commandclass).ToString() + (this.IsSub ? "/" + this.SensorId : "");
}
public String ToJson() {
Dictionary<String, Object> json = this.ToDictionary();
json.Add("date", this.LastUpdate.ToString());
json.Add("name", this.Name);
json.Add("class", this.Commandclass.ToString());
return JsonMapper.ToJson(json);
}
public abstract Dictionary<String, Object> ToDictionary();
protected Dictionary<String, Object> ToDictionarySub() {
Dictionary<String, Object> json = new Dictionary<String, Object>();
foreach (KeyValuePair<Int32, ACommandClass> item in this.Sub) {
json.Add(item.Key.ToString(), item.Value.ToDictionary());
}
return json;
}
#endregion
internal abstract void SetUpdate(JsonData json, Match match);
}
}

View File

@ -1,14 +0,0 @@
using System;
using BlubbFish.IoT.Zway.Events;
namespace BlubbFish.IoT.Zway.Interfaces {
public delegate void UpdatedValue(Object sender, DeviceUpdateEvent e);
public interface ICommandClass {
String Name { get; }
String Id { get; }
DateTime LastUpdate { get; }
Boolean Polling { get; set; }
event UpdatedValue Update;
}
}

View File

@ -32,5 +32,5 @@ 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,
// indem Sie "*" wie unten gezeigt eingeben: // indem Sie "*" wie unten gezeigt eingeben:
// [assembly: AssemblyVersion("1.0.*")] // [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")] [assembly: AssemblyVersion("1.3.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyFileVersion("1.3.0.0")]

View File

@ -44,7 +44,6 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="Devices\CommandClasses\Battery.cs" /> <Compile Include="Devices\CommandClasses\Battery.cs" />
<Compile Include="Devices\CommandClass.cs" />
<Compile Include="Devices\CommandClasses\CommandClassSubs\Configurationsub.cs" /> <Compile Include="Devices\CommandClasses\CommandClassSubs\Configurationsub.cs" />
<Compile Include="Devices\CommandClasses\CommandClassSubs\ThermostatSetPointSub.cs" /> <Compile Include="Devices\CommandClasses\CommandClassSubs\ThermostatSetPointSub.cs" />
<Compile Include="Devices\CommandClasses\Configuration.cs" /> <Compile Include="Devices\CommandClasses\Configuration.cs" />
@ -53,9 +52,8 @@
<Compile Include="Devices\CommandClasses\CommandClassSubs\MeterSub.cs" /> <Compile Include="Devices\CommandClasses\CommandClassSubs\MeterSub.cs" />
<Compile Include="Devices\CommandClasses\CommandClassSubs\SensorMultilevelSub.cs" /> <Compile Include="Devices\CommandClasses\CommandClassSubs\SensorMultilevelSub.cs" />
<Compile Include="Devices\CommandClasses\Wakeup.cs" /> <Compile Include="Devices\CommandClasses\Wakeup.cs" />
<Compile Include="Devices\CommandClassSub.cs" />
<Compile Include="Devices\Device.cs" /> <Compile Include="Devices\Device.cs" />
<Compile Include="Interfaces\ICommandClass.cs" /> <Compile Include="Interfaces\ACommandClass.cs" />
<Compile Include="Devices\Instance.cs" /> <Compile Include="Devices\Instance.cs" />
<Compile Include="Devices\CommandClasses\CentralScene.cs" /> <Compile Include="Devices\CommandClasses\CentralScene.cs" />
<Compile Include="Devices\CommandClasses\SensorMultilevel.cs" /> <Compile Include="Devices\CommandClasses\SensorMultilevel.cs" />

View File

@ -73,23 +73,24 @@ namespace BlubbFish.IoT.Zway {
} }
} }
public ICommandClass GetCommandClass(Int32 deviceid, Int32 instanceid, Int32 classid) { public ACommandClass GetCommandClass(String id) {
if(this.Devices.ContainsKey(deviceid) && this.Devices[deviceid].Instances.ContainsKey(instanceid) && this.Devices[deviceid].Instances[instanceid].CommandClasses.ContainsKey(classid)) { String[] addr = id.Split('-');
return this.Devices[deviceid].Instances[instanceid].CommandClasses[classid]; if (addr.Length == 3 || addr.Length == 4) {
return this.GetCommandClass(Int32.Parse(addr[0]), Int32.Parse(addr[1]), (ACommandClass.Classes)Int32.Parse(addr[2]), (addr.Length == 4 ? Int32.Parse(addr[3]) : -1));
} }
return null; return null;
} }
public ICommandClass GetCommandClassSub(Int32 deviceid, Int32 instanceid, Int32 classid, Int32 subcid) { public ACommandClass GetCommandClass(Int32 deviceid, Int32 instanceid, ACommandClass.Classes classid, Int32 subcid = -1) {
ICommandClass comandclass = this.GetCommandClass(deviceid, instanceid, classid); if(this.Devices.ContainsKey(deviceid) && this.Devices[deviceid].Instances.ContainsKey(instanceid) && this.Devices[deviceid].Instances[instanceid].CommandClasses.ContainsKey(classid)) {
if (comandclass != null) { ACommandClass commandclass = this.Devices[deviceid].Instances[instanceid].CommandClasses[classid];
foreach (PropertyInfo item in comandclass.GetType().GetProperties()) { if(subcid == -1) {
if (item.Name == "Sub") { return commandclass;
if (comandclass.GetType().GetProperty("Sub").PropertyType == typeof(ReadOnlyDictionary<Int32, CommandClassSub>)) { }
ReadOnlyDictionary<Int32, CommandClassSub> commandclasssub = (ReadOnlyDictionary<Int32, CommandClassSub>)comandclass.GetType().GetProperty("Sub").GetValue(comandclass); if (commandclass != null) {
if (commandclasssub.ContainsKey(subcid)) { if(commandclass.HasSub) {
return commandclasssub[subcid]; if(commandclass.Sub.ContainsKey(subcid)) {
} return commandclass.Sub[subcid];
} }
} }
} }
@ -112,7 +113,7 @@ namespace BlubbFish.IoT.Zway {
if(match.Success) { if(match.Success) {
Int32 deviceid = Int32.Parse(match.Groups[1].Value); Int32 deviceid = Int32.Parse(match.Groups[1].Value);
Int32 instanceid = Int32.Parse(match.Groups[2].Value); Int32 instanceid = Int32.Parse(match.Groups[2].Value);
Int32 commandid = Int32.Parse(match.Groups[3].Value); ACommandClass.Classes commandid = (ACommandClass.Classes)Int32.Parse(match.Groups[3].Value);
if (this.Devices.ContainsKey(deviceid) && this.Devices[deviceid].Instances.ContainsKey(instanceid) && this.Devices[deviceid].Instances[instanceid].CommandClasses.ContainsKey(commandid)) { if (this.Devices.ContainsKey(deviceid) && this.Devices[deviceid].Instances.ContainsKey(instanceid) && this.Devices[deviceid].Instances[instanceid].CommandClasses.ContainsKey(commandid)) {
this.Devices[deviceid].Instances[instanceid].CommandClasses[commandid].SetUpdate(notifications[item], match); this.Devices[deviceid].Instances[instanceid].CommandClasses[commandid].SetUpdate(notifications[item], match);
} }
@ -149,13 +150,13 @@ namespace BlubbFish.IoT.Zway {
this.Devices = new ReadOnlyDictionary<Int32, Device>(devices); this.Devices = new ReadOnlyDictionary<Int32, Device>(devices);
} }
public List<T> GetCommandClasses<T>() { public Dictionary<String, ACommandClass> GetCommandClasses(ACommandClass.Classes classes) {
List<T> ret = new List<T>(); Dictionary<String, ACommandClass> ret = new Dictionary<String, ACommandClass>();
foreach (KeyValuePair<Int32, Device> device in this.Devices) { foreach (KeyValuePair<Int32, Device> device in this.Devices) {
foreach (KeyValuePair<Int32, Instance> instance in device.Value.Instances) { foreach (KeyValuePair<Int32, Instance> instance in device.Value.Instances) {
foreach (KeyValuePair<Int32, CommandClass> commandclass in instance.Value.CommandClasses) { foreach (KeyValuePair<ACommandClass.Classes, ACommandClass> commandclass in instance.Value.CommandClasses) {
if (commandclass.Value is T) { if (commandclass.Key == classes) {
ret.Add((T)Convert.ChangeType(commandclass.Value, typeof(T))); ret.Add(commandclass.Value.Id, commandclass.Value);
} }
} }
} }

Binary file not shown.