Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
beea6c1ee0 | ||
|
|
1082ee0d2a | ||
|
|
6d395107cb | ||
|
|
ae999384c7 | ||
|
|
9d09f09c12 | ||
|
|
08047db287 | ||
|
|
f406b09ffa | ||
|
|
0834e09178 | ||
|
|
b29e1d2a14 | ||
|
|
d9dfe7d63a | ||
|
|
db935e019c | ||
|
|
d7f27fad4f | ||
|
|
d439471051 | ||
|
|
1445a16930 | ||
|
|
b51f88badb | ||
|
|
8166e6e646 | ||
|
|
06e57c4559 | ||
|
|
53e4ba9d14 | ||
|
|
c6dec361d5 | ||
|
|
fffd2b3c2e | ||
|
|
57de0b4ce9 | ||
|
|
26b3a02d58 | ||
|
|
99dc37d751 |
@@ -1,97 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Text.RegularExpressions;
|
|
||||||
using BlubbFish.IoT.Zway.Events;
|
|
||||||
using BlubbFish.IoT.Zway.lib;
|
|
||||||
using LitJson;
|
|
||||||
|
|
||||||
namespace BlubbFish.IoT.Zway.Devices {
|
|
||||||
public abstract class CommandClass {
|
|
||||||
protected HttpConnection http;
|
|
||||||
private enum Ignored {
|
|
||||||
Basic = 32,
|
|
||||||
Configuration = 112,
|
|
||||||
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 Name { get; }
|
|
||||||
|
|
||||||
public DateTime LastUpdate { get; private set; }
|
|
||||||
|
|
||||||
protected CommandClass(JsonData json, HttpConnection http, Tuple<Int32, Int32, Int32> id) {
|
|
||||||
this.DeviceId = id.Item1;
|
|
||||||
this.Instance = id.Item2;
|
|
||||||
this.Commandclass = id.Item3;
|
|
||||||
this.Name = this.DeviceId + "-" + this.Instance + "-" + this.Commandclass;
|
|
||||||
this.http = http;
|
|
||||||
this.LastUpdate = DateTime.Now;
|
|
||||||
}
|
|
||||||
|
|
||||||
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) {
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static CommandClass GetInstanceConcrete(String objectName, JsonData json, HttpConnection http, Tuple<Int32, Int32, Int32> id) {
|
|
||||||
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>) }).Invoke(new Object[] { json, http, id });
|
|
||||||
}
|
|
||||||
|
|
||||||
protected abstract void InitComplex(JsonData json);
|
|
||||||
internal abstract void SetUpdate(JsonData json, Match match);
|
|
||||||
|
|
||||||
public delegate void UpdatedValue(Object sender, DeviceUpdateEvent e);
|
|
||||||
public abstract event UpdatedValue Update;
|
|
||||||
|
|
||||||
internal virtual void Poll() {
|
|
||||||
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 + ")");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,51 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Text.RegularExpressions;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using BlubbFish.IoT.Zway.Events;
|
|
||||||
using BlubbFish.IoT.Zway.lib;
|
|
||||||
using LitJson;
|
|
||||||
|
|
||||||
namespace BlubbFish.IoT.Zway.Devices {
|
|
||||||
public abstract class CommandClassSub {
|
|
||||||
protected HttpConnection http;
|
|
||||||
|
|
||||||
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; }
|
|
||||||
|
|
||||||
protected CommandClassSub(JsonData json, Tuple<Int32, Int32, Int32, Int32> id, HttpConnection http) {
|
|
||||||
this.DeviceId = id.Item1;
|
|
||||||
this.Instance = id.Item2;
|
|
||||||
this.Commandclass = id.Item3;
|
|
||||||
this.SensorId = id.Item4;
|
|
||||||
this.http = http;
|
|
||||||
this.Name = this.DeviceId + "-" + this.Instance + "-" + this.Commandclass + "-" + this.SensorId;
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected abstract void InitComplex(JsonData json);
|
|
||||||
internal abstract void SetUpdate(JsonData json, Match match);
|
|
||||||
|
|
||||||
public delegate void UpdatedValue(Object sender, DeviceUpdateEvent e);
|
|
||||||
public abstract event UpdatedValue Update;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,59 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
using BlubbFish.IoT.Zway.Events;
|
||||||
|
using BlubbFish.IoT.Zway.Interfaces;
|
||||||
|
using BlubbFish.IoT.Zway.lib;
|
||||||
|
using LitJson;
|
||||||
|
|
||||||
|
namespace BlubbFish.IoT.Zway.Devices.CommandClasses {
|
||||||
|
/// <summary>
|
||||||
|
/// 135 = Indicator
|
||||||
|
/// </summary>
|
||||||
|
class Alarm : ACommandClass {
|
||||||
|
public override event UpdatedValue Update;
|
||||||
|
|
||||||
|
public Int32 Level { get; private set; }
|
||||||
|
public Int32 AlarmType { get; private set; }
|
||||||
|
|
||||||
|
public Alarm(JsonData json, Tuple<Int32, Int32, Classes> 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("V1event") &&
|
||||||
|
json["data"]["V1event"].Keys.Contains("alarmType") && json["data"]["V1event"]["alarmType"].Keys.Contains("value") &&
|
||||||
|
json["data"]["V1event"].Keys.Contains("level") && json["data"]["V1event"]["level"].Keys.Contains("value")) {
|
||||||
|
this.AlarmType = Int32.Parse(json["data"]["V1event"]["alarmType"]["value"].ToString());
|
||||||
|
this.Level = Int32.Parse(json["data"]["V1event"]["level"]["value"].ToString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
internal override void SetUpdate(JsonData json, Match match) {
|
||||||
|
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)) {
|
||||||
|
this.AlarmType = Int32.Parse(json["alarmType"]["value"].ToString());
|
||||||
|
this.Level = Int32.Parse(json["level"]["value"].ToString());
|
||||||
|
this.Update?.Invoke(this, new DeviceUpdateEvent(new Tuple<Int32, Int32>(this.AlarmType, this.Level), this.LastUpdate, this));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Helper.WriteError("Kenne in " + this.Name + " [" + this.Id + "] " + match.Groups[4].Value + " nicht!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public override String ToString() {
|
||||||
|
return "Alarm " + this.Name + " [" + this.Id + "]: " + this.AlarmType + " " + this.Level;
|
||||||
|
}
|
||||||
|
|
||||||
|
internal override void Poll() => this.PollNone();
|
||||||
|
|
||||||
|
public override Dictionary<String, Object> ToDictionary() {
|
||||||
|
return new Dictionary<String, Object> {
|
||||||
|
{ "AlarmType", this.AlarmType },
|
||||||
|
{ "Level", this.Level },
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,17 +1,22 @@
|
|||||||
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.lib;
|
using BlubbFish.IoT.Zway.lib;
|
||||||
using LitJson;
|
using LitJson;
|
||||||
|
|
||||||
namespace BlubbFish.IoT.Zway.Devices.CommandClasses {
|
namespace BlubbFish.IoT.Zway.Devices.CommandClasses {
|
||||||
public class Battery : CommandClass {
|
/// <summary>
|
||||||
|
/// 128 = Battery
|
||||||
|
/// </summary>
|
||||||
|
public class Battery : ACommandClass {
|
||||||
|
|
||||||
public Single Level { get; private set; }
|
public Double 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) : base(json, http, id) {
|
public Battery(JsonData json, Tuple<Int32, Int32, Classes> id, HttpConnection http, Boolean polling) : base(json, id, http, polling) {
|
||||||
this.InitComplex(json);
|
this.InitComplex(json);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -19,32 +24,38 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses {
|
|||||||
Boolean success = false;
|
Boolean success = false;
|
||||||
if (match.Groups[4].Value == ".data") {
|
if (match.Groups[4].Value == ".data") {
|
||||||
if (json.Keys.Contains("last") && json["last"].Keys.Contains("value")) {
|
if (json.Keys.Contains("last") && json["last"].Keys.Contains("value")) {
|
||||||
this.Level = Single.Parse(json["last"]["value"].ToString());
|
this.Level = Double.Parse(json["last"]["value"].ToString());
|
||||||
success = true;
|
success = true;
|
||||||
}
|
}
|
||||||
} else if (match.Groups[4].Value == ".data.last") {
|
} else if (match.Groups[4].Value == ".data.last") {
|
||||||
if (json.Keys.Contains("value")) {
|
if (json.Keys.Contains("value")) {
|
||||||
this.Level = Single.Parse(json["value"].ToString());
|
this.Level = Double.Parse(json["value"].ToString());
|
||||||
success = true;
|
success = true;
|
||||||
}
|
}
|
||||||
} else if (match.Groups[4].Value.StartsWith(".data.history.")) {
|
} else if (match.Groups[4].Value.StartsWith(".data.history.")) {
|
||||||
} else if (match.Groups[4].Value == ".data.lastChange") {
|
} else if (match.Groups[4].Value == ".data.lastChange") {
|
||||||
} else {
|
} else {
|
||||||
throw new NotImplementedException();
|
Helper.WriteError("Kenne in "+this.Name+" ["+this.Id+"] "+ match.Groups[4].Value+" nicht!");
|
||||||
}
|
}
|
||||||
if (success && this.CheckSetUpdateTime(json)) {
|
if (success && this.CheckSetUpdateTime(json)) {
|
||||||
this.Update?.Invoke(this, new DeviceUpdateEvent(this.Level, this.LastUpdate));
|
this.Update?.Invoke(this, new DeviceUpdateEvent(this.Level, this.LastUpdate, this));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void InitComplex(JsonData json) {
|
private void InitComplex(JsonData json) {
|
||||||
if(json.Keys.Contains("data") && json["data"].Keys.Contains("last") && json["data"]["last"].Keys.Contains("value")) {
|
if (json.Keys.Contains("data") && json["data"].Keys.Contains("last") && json["data"]["last"].Keys.Contains("value")) {
|
||||||
this.Level = Single.Parse(json["data"]["last"]["value"].ToString());
|
this.Level = Double.Parse(json["data"]["last"]["value"].ToString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override String ToString() {
|
public override String ToString() {
|
||||||
return "Battery " + this.Name + ": " + this.Level;
|
return "Battery " + this.Name + " [" + this.Id + "]: " + this.Level;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override Dictionary<String, Object> ToDictionary() {
|
||||||
|
return new Dictionary<String, Object> {
|
||||||
|
{ "Level", this.Level },
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,18 +3,22 @@ using System.Collections.Generic;
|
|||||||
using System.Collections.ObjectModel;
|
using System.Collections.ObjectModel;
|
||||||
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.lib;
|
using BlubbFish.IoT.Zway.lib;
|
||||||
using LitJson;
|
using LitJson;
|
||||||
|
|
||||||
namespace BlubbFish.IoT.Zway.Devices.CommandClasses {
|
namespace BlubbFish.IoT.Zway.Devices.CommandClasses {
|
||||||
public class Centralscene : CommandClass {
|
/// <summary>
|
||||||
|
/// 91 = CentralScene
|
||||||
|
/// </summary>
|
||||||
|
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) : base(json, http, id) {
|
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);
|
||||||
}
|
}
|
||||||
@@ -27,14 +31,14 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses {
|
|||||||
} else if (match.Groups[4].Value == ".data.keyAttribute") {
|
} else if (match.Groups[4].Value == ".data.keyAttribute") {
|
||||||
if (json.Keys.Contains("value") && this.CheckSetUpdateTime(json)) {
|
if (json.Keys.Contains("value") && this.CheckSetUpdateTime(json)) {
|
||||||
this.Key = Int32.Parse(json["value"].ToString());
|
this.Key = Int32.Parse(json["value"].ToString());
|
||||||
this.Update?.Invoke(this, new DeviceUpdateEvent(new Tuple<Int32, Int32>(this.Scene, this.Key), this.LastUpdate));
|
this.Update?.Invoke(this, new DeviceUpdateEvent(new Tuple<Int32, Int32>(this.Scene, this.Key), this.LastUpdate, this));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new NotImplementedException();
|
Helper.WriteError("Kenne in " + this.Name + " [" + this.Id + "] " + match.Groups[4].Value + " nicht!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override 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"];
|
||||||
if(data.Keys.Contains("sceneSupportedKeyAttributesMask")) {
|
if(data.Keys.Contains("sceneSupportedKeyAttributesMask")) {
|
||||||
@@ -67,10 +71,16 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public override String ToString() {
|
public override String ToString() {
|
||||||
return "CentralScene " + this.Name + ": "+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 },
|
||||||
|
{ "Key", this.Key },
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,69 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
using BlubbFish.IoT.Zway.Events;
|
||||||
|
using BlubbFish.IoT.Zway.Interfaces;
|
||||||
|
using BlubbFish.IoT.Zway.lib;
|
||||||
|
using LitJson;
|
||||||
|
|
||||||
|
namespace BlubbFish.IoT.Zway.Devices.CommandClasses.CommandClassSubs {
|
||||||
|
class Configurationsub : ACommandClass {
|
||||||
|
public override event UpdatedValue Update;
|
||||||
|
private Int64 _level;
|
||||||
|
|
||||||
|
public Int64 Level {
|
||||||
|
get {
|
||||||
|
return this._level;
|
||||||
|
}
|
||||||
|
set {
|
||||||
|
if (this.Size == 1 && Int16.TryParse(value.ToString(), out Int16 value16)) {
|
||||||
|
this.SetTriple(this.SensorId, value16, 1);
|
||||||
|
} else if(this.Size == 2 && Int32.TryParse(value.ToString(), out Int32 value32)) {
|
||||||
|
this.SetTriple(this.SensorId, value32, 2);
|
||||||
|
} else if(this.Size == 4) {
|
||||||
|
this.SetTriple(this.SensorId, value, 4);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public Int32 Size { get; private set; }
|
||||||
|
|
||||||
|
public Configurationsub(JsonData json, Tuple<Int32, Int32, Classes, Int32> id, HttpConnection http, Boolean polling) : base(json, id, http, polling) {
|
||||||
|
this.IsSub = true;
|
||||||
|
InitComplex(json);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void InitComplex(JsonData json) {
|
||||||
|
if (json.Keys.Contains("val") &&
|
||||||
|
json["val"].Keys.Contains("value") &&
|
||||||
|
json["val"]["value"] != null &&
|
||||||
|
json.Keys.Contains("size") &&
|
||||||
|
json["size"].Keys.Contains("value")) {
|
||||||
|
this._level = Int64.Parse(json["val"]["value"].ToString());
|
||||||
|
this.Size = Int32.Parse(json["size"]["value"].ToString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
internal override void Poll() => this.PollSub();
|
||||||
|
|
||||||
|
internal override void SetUpdate(JsonData json, Match match) {
|
||||||
|
if (json.Keys.Contains("val") && json["val"].Keys.Contains("value") && json["val"]["value"] != null &&
|
||||||
|
json.Keys.Contains("size") && json["size"].Keys.Contains("value") &&
|
||||||
|
this.CheckSetUpdateTime(json)) {
|
||||||
|
this._level = Int64.Parse(json["val"]["value"].ToString());
|
||||||
|
this.Size = Int32.Parse(json["size"]["value"].ToString());
|
||||||
|
this.Update?.Invoke(this, new DeviceUpdateEvent(new Tuple<Int64, Int32>(this.Level, this.Size), this.LastUpdate, this));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public override String ToString() {
|
||||||
|
return "Configuration " + this.Name + " [" + this.Id + "]: " + this.Level;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override Dictionary<String, Object> ToDictionary() {
|
||||||
|
return new Dictionary<String, Object> {
|
||||||
|
{ "Level", this.Level },
|
||||||
|
{ "Size", this.Size },
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,25 +1,25 @@
|
|||||||
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.lib;
|
using BlubbFish.IoT.Zway.lib;
|
||||||
using LitJson;
|
using LitJson;
|
||||||
|
|
||||||
namespace BlubbFish.IoT.Zway.Devices.CommandClasses.CommandClassSubs {
|
namespace BlubbFish.IoT.Zway.Devices.CommandClasses.CommandClassSubs {
|
||||||
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 Double 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) : base(json, id, http) {
|
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() {
|
private void InitComplex(JsonData json) {
|
||||||
this.http.GetVoid("ZWave.zway/Run/devices[" + this.DeviceId + "].instances[" + this.Instance + "].commandClasses[" + this.Commandclass + "].Reset()");
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void InitComplex(JsonData json) {
|
|
||||||
if (json.Keys.Contains("sensorTypeString") &&
|
if (json.Keys.Contains("sensorTypeString") &&
|
||||||
json["sensorTypeString"].Keys.Contains("value") &&
|
json["sensorTypeString"].Keys.Contains("value") &&
|
||||||
json.Keys.Contains("val") &&
|
json.Keys.Contains("val") &&
|
||||||
@@ -27,7 +27,7 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses.CommandClassSubs {
|
|||||||
json.Keys.Contains("scaleString") &&
|
json.Keys.Contains("scaleString") &&
|
||||||
json["scaleString"].Keys.Contains("value")) {
|
json["scaleString"].Keys.Contains("value")) {
|
||||||
this.Type = json["sensorTypeString"]["value"].ToString();
|
this.Type = json["sensorTypeString"]["value"].ToString();
|
||||||
this.Level = Single.Parse(json["val"]["value"].ToString());
|
this.Level = Double.Parse(json["val"]["value"].ToString());
|
||||||
this.Scale = json["scaleString"]["value"].ToString();
|
this.Scale = json["scaleString"]["value"].ToString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -37,15 +37,25 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses.CommandClassSubs {
|
|||||||
json.Keys.Contains("sensorTypeString") && json["sensorTypeString"].Keys.Contains("value") &&
|
json.Keys.Contains("sensorTypeString") && json["sensorTypeString"].Keys.Contains("value") &&
|
||||||
json.Keys.Contains("scaleString") && json["scaleString"].Keys.Contains("value") &&
|
json.Keys.Contains("scaleString") && json["scaleString"].Keys.Contains("value") &&
|
||||||
this.CheckSetUpdateTime(json)) {
|
this.CheckSetUpdateTime(json)) {
|
||||||
this.Level = Single.Parse(json["val"]["value"].ToString());
|
this.Level = Double.Parse(json["val"]["value"].ToString());
|
||||||
this.Type = json["sensorTypeString"]["value"].ToString();
|
this.Type = json["sensorTypeString"]["value"].ToString();
|
||||||
this.Scale = json["scaleString"]["value"].ToString();
|
this.Scale = json["scaleString"]["value"].ToString();
|
||||||
this.Update?.Invoke(this, new DeviceUpdateEvent(new Tuple<String, String, Single>(this.Type, this.Scale, this.Level), this.LastUpdate));
|
this.Update?.Invoke(this, new DeviceUpdateEvent(new Tuple<String, String, Double>(this.Type, this.Scale, this.Level), this.LastUpdate, this));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override String ToString() {
|
public override String ToString() {
|
||||||
return "Meter " + this.Name + ": " + this.Type + " " + this.Level + "" + this.Scale;
|
return "Meter " + this.Name + " [" + this.Id + "]: " + this.Type + " " + this.Level + "" + this.Scale;
|
||||||
|
}
|
||||||
|
|
||||||
|
internal override void Poll() => this.PollNone();
|
||||||
|
|
||||||
|
public override Dictionary<String, Object> ToDictionary() {
|
||||||
|
return new Dictionary<String, Object> {
|
||||||
|
{ "Level", this.Level },
|
||||||
|
{ "Type", this.Type },
|
||||||
|
{ "Scale", this.Scale },
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,51 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
using BlubbFish.IoT.Zway.Events;
|
||||||
|
using BlubbFish.IoT.Zway.Interfaces;
|
||||||
|
using BlubbFish.IoT.Zway.lib;
|
||||||
|
using LitJson;
|
||||||
|
|
||||||
|
namespace BlubbFish.IoT.Zway.Devices.CommandClasses.CommandClassSubs {
|
||||||
|
public class Scenecontrollerconfsub : ACommandClass {
|
||||||
|
public override event UpdatedValue Update;
|
||||||
|
|
||||||
|
public Int32 Scene { get; private set; }
|
||||||
|
public Int32 Duration { get; private set; }
|
||||||
|
public Scenecontrollerconfsub(JsonData json, Tuple<Int32, Int32, Classes, Int32> id, HttpConnection http, Boolean polling) : base(json, id, http, polling) {
|
||||||
|
this.IsSub = true;
|
||||||
|
InitComplex(json);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void InitComplex(JsonData json) {
|
||||||
|
if (json.Keys.Contains("scene") && json["scene"].Keys.Contains("value") &&
|
||||||
|
json.Keys.Contains("duration") && json["duration"].Keys.Contains("value")) {
|
||||||
|
this.Scene = Int32.Parse(json["scene"]["value"].ToString());
|
||||||
|
this.Duration = Int32.Parse(json["duration"]["value"].ToString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
internal override void SetUpdate(JsonData json, Match match) {
|
||||||
|
if (json.Keys.Contains("scene") && json["scene"].Keys.Contains("value") &&
|
||||||
|
json.Keys.Contains("duration") && json["duration"].Keys.Contains("value") &&
|
||||||
|
this.CheckSetUpdateTime(json)) {
|
||||||
|
this.Scene = Int32.Parse(json["scene"]["value"].ToString());
|
||||||
|
this.Duration = Int32.Parse(json["duration"]["value"].ToString());
|
||||||
|
this.Update?.Invoke(this, new DeviceUpdateEvent(new Tuple<Int32, Int32>(this.Scene, this.Duration), this.LastUpdate, this));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public override String ToString() {
|
||||||
|
return "SceneControllerConf " + this.Name + " [" + this.Id + "]: " + this.Scene + " " + this.Duration;
|
||||||
|
}
|
||||||
|
|
||||||
|
internal override void Poll() => this.PollSub();
|
||||||
|
|
||||||
|
public override Dictionary<String, Object> ToDictionary() {
|
||||||
|
return new Dictionary<String, Object> {
|
||||||
|
{ "Scene", this.Scene },
|
||||||
|
{ "Duration", this.Duration }
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
using BlubbFish.IoT.Zway.Events;
|
||||||
|
using BlubbFish.IoT.Zway.Interfaces;
|
||||||
|
using BlubbFish.IoT.Zway.lib;
|
||||||
|
using LitJson;
|
||||||
|
|
||||||
|
namespace BlubbFish.IoT.Zway.Devices.CommandClasses.CommandClassSubs {
|
||||||
|
public class Sensorbinarysub : ACommandClass {
|
||||||
|
public override event UpdatedValue Update;
|
||||||
|
|
||||||
|
public String Type { get; private set; }
|
||||||
|
public Boolean State { get; private set; }
|
||||||
|
public Int32 Level {
|
||||||
|
get {
|
||||||
|
return (this.State) ? 1 : 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Sensorbinarysub(JsonData json, Tuple<Int32, Int32, Classes, Int32> id, HttpConnection http, Boolean polling) : base(json, id, http, polling) {
|
||||||
|
this.IsSub = true;
|
||||||
|
InitComplex(json);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void InitComplex(JsonData json) {
|
||||||
|
if (json.Keys.Contains("sensorTypeString") &&
|
||||||
|
json["sensorTypeString"].Keys.Contains("value") &&
|
||||||
|
json.Keys.Contains("level") &&
|
||||||
|
json["level"].Keys.Contains("value")) {
|
||||||
|
this.Type = json["sensorTypeString"]["value"].ToString();
|
||||||
|
this.State = (Boolean)json["level"]["value"];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
internal override void SetUpdate(JsonData json, Match match) {
|
||||||
|
if (json.Keys.Contains("level") && json["level"].Keys.Contains("value") &&
|
||||||
|
json.Keys.Contains("sensorTypeString") && json["sensorTypeString"].Keys.Contains("value") &&
|
||||||
|
this.CheckSetUpdateTime(json)) {
|
||||||
|
this.State = (Boolean)json["level"]["value"];
|
||||||
|
this.Type = json["sensorTypeString"]["value"].ToString();
|
||||||
|
this.Update?.Invoke(this, new DeviceUpdateEvent(new Tuple<String, Boolean>(this.Type, this.State), this.LastUpdate, this));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public override String ToString() {
|
||||||
|
return "SensorBinary " + this.Name + " [" + this.Id + "]: " + this.Type + " " + this.State.ToString();
|
||||||
|
}
|
||||||
|
|
||||||
|
internal override void Poll() => this.PollNone();
|
||||||
|
|
||||||
|
public override Dictionary<String, Object> ToDictionary() {
|
||||||
|
return new Dictionary<String, Object> {
|
||||||
|
{ "State", this.State },
|
||||||
|
{ "Type", this.Type },
|
||||||
|
{ "Level", this.Level }
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,23 +1,25 @@
|
|||||||
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.lib;
|
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 Double 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) : base(json, id, http) {
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void InitComplex(JsonData json) {
|
||||||
|
|
||||||
protected override void InitComplex(JsonData json) {
|
|
||||||
if (json.Keys.Contains("sensorTypeString") &&
|
if (json.Keys.Contains("sensorTypeString") &&
|
||||||
json["sensorTypeString"].Keys.Contains("value") &&
|
json["sensorTypeString"].Keys.Contains("value") &&
|
||||||
json.Keys.Contains("val") &&
|
json.Keys.Contains("val") &&
|
||||||
@@ -25,25 +27,43 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses.CommandClassSubs {
|
|||||||
json.Keys.Contains("scaleString") &&
|
json.Keys.Contains("scaleString") &&
|
||||||
json["scaleString"].Keys.Contains("value")) {
|
json["scaleString"].Keys.Contains("value")) {
|
||||||
this.Type = json["sensorTypeString"]["value"].ToString();
|
this.Type = json["sensorTypeString"]["value"].ToString();
|
||||||
this.Level = Single.Parse(json["val"]["value"].ToString());
|
this.Level = Double.Parse(json["val"]["value"].ToString());
|
||||||
this.Scale = json["scaleString"]["value"].ToString();
|
this.Scale = json["scaleString"]["value"].ToString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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.Keys.Contains("sensorTypeString") && json["sensorTypeString"].Keys.Contains("value")) {
|
||||||
|
String t = json["sensorTypeString"]["value"].ToString();
|
||||||
|
Double l = Double.Parse(json["val"]["value"].ToString());
|
||||||
|
if (t == "Power" && (l > 3660 || l < 0) ||
|
||||||
|
t == "Temperature" && (l > 50 || l < -20)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
if(json.Keys.Contains("val") && json["val"].Keys.Contains("value") &&
|
if(json.Keys.Contains("val") && json["val"].Keys.Contains("value") &&
|
||||||
json.Keys.Contains("sensorTypeString") && json["sensorTypeString"].Keys.Contains("value") &&
|
json.Keys.Contains("sensorTypeString") && json["sensorTypeString"].Keys.Contains("value") &&
|
||||||
json.Keys.Contains("scaleString") && json["scaleString"].Keys.Contains("value") &&
|
json.Keys.Contains("scaleString") && json["scaleString"].Keys.Contains("value") &&
|
||||||
this.CheckSetUpdateTime(json)) {
|
this.CheckSetUpdateTime(json)) {
|
||||||
this.Level = Single.Parse(json["val"]["value"].ToString());
|
this.Level = Double.Parse(json["val"]["value"].ToString());
|
||||||
this.Type = json["sensorTypeString"]["value"].ToString();
|
this.Type = json["sensorTypeString"]["value"].ToString();
|
||||||
this.Scale = json["scaleString"]["value"].ToString();
|
this.Scale = json["scaleString"]["value"].ToString();
|
||||||
this.Update?.Invoke(this, new DeviceUpdateEvent(new Tuple<String, String, Single>(this.Type, this.Scale, this.Level), this.LastUpdate));
|
this.Update?.Invoke(this, new DeviceUpdateEvent(new Tuple<String, String, Double>(this.Type, this.Scale, this.Level), this.LastUpdate, this));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override String ToString() {
|
public override String ToString() {
|
||||||
return "SensorMultilevel " + this.Name + ": " + this.Type + " " + this.Level + "" + this.Scale;
|
return "SensorMultilevel " + this.Name + " [" + this.Id + "]: " + this.Type + " " + this.Level + "" + this.Scale;
|
||||||
|
}
|
||||||
|
|
||||||
|
internal override void Poll() => this.PollNone();
|
||||||
|
|
||||||
|
public override Dictionary<String, Object> ToDictionary() {
|
||||||
|
return new Dictionary<String, Object> {
|
||||||
|
{ "Level", this.Level },
|
||||||
|
{ "Type", this.Type },
|
||||||
|
{ "Scale", this.Scale },
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,48 +1,49 @@
|
|||||||
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.lib;
|
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;
|
||||||
|
|
||||||
public Single Level {
|
private Double _level;
|
||||||
|
public Double 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, (Double)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 + ")");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public String Scale { get; private set; }
|
public String Scale { get; private set; }
|
||||||
public Single TempMax { get; private set; }
|
public Double TempMax { get; private set; }
|
||||||
public Single TempMin { get; private set; }
|
public Double TempMin { get; private set; }
|
||||||
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) : base(json, id, http) {
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void InitComplex(JsonData json) {
|
private void InitComplex(JsonData json) {
|
||||||
if (json.Keys.Contains("modeName") && json["modeName"].Keys.Contains("value") &&
|
if (json.Keys.Contains("modeName") && json["modeName"].Keys.Contains("value") &&
|
||||||
json.Keys.Contains("val") && json["val"].Keys.Contains("value") &&
|
json.Keys.Contains("val") && json["val"].Keys.Contains("value") &&
|
||||||
json.Keys.Contains("deviceScaleString") && json["deviceScaleString"].Keys.Contains("value")) {
|
json.Keys.Contains("deviceScaleString") && json["deviceScaleString"].Keys.Contains("value")) {
|
||||||
this.Type = json["modeName"]["value"].ToString();
|
this.Type = json["modeName"]["value"].ToString();
|
||||||
this._level = Single.Parse(json["val"]["value"].ToString());
|
this._level = Double.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 = Double.Parse(json["min"]["value"].ToString());
|
||||||
this.TempMax = Single.Parse(json["max"]["value"].ToString());
|
this.TempMax = Double.Parse(json["max"]["value"].ToString());
|
||||||
this.HasMinMax = true;
|
this.HasMinMax = true;
|
||||||
} else {
|
} else {
|
||||||
this.HasMinMax = false;
|
this.HasMinMax = false;
|
||||||
@@ -54,27 +55,40 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses.CommandClassSubs {
|
|||||||
if (json.Keys.Contains("val") && json["val"].Keys.Contains("value") &&
|
if (json.Keys.Contains("val") && json["val"].Keys.Contains("value") &&
|
||||||
json.Keys.Contains("deviceScaleString") && json["deviceScaleString"].Keys.Contains("value") &&
|
json.Keys.Contains("deviceScaleString") && json["deviceScaleString"].Keys.Contains("value") &&
|
||||||
json.Keys.Contains("modeName") && json["modeName"].Keys.Contains("value")) {
|
json.Keys.Contains("modeName") && json["modeName"].Keys.Contains("value")) {
|
||||||
this._level = Single.Parse(json["val"]["value"].ToString());
|
this._level = Double.Parse(json["val"]["value"].ToString());
|
||||||
this.Scale = json["deviceScaleString"]["value"].ToString();
|
this.Scale = json["deviceScaleString"]["value"].ToString();
|
||||||
this.Type = json["modeName"]["value"].ToString();
|
this.Type = json["modeName"]["value"].ToString();
|
||||||
ret = true;
|
ret = true;
|
||||||
}
|
}
|
||||||
if (json.Keys.Contains("min") && json["val"].Keys.Contains("value") &&
|
if (json.Keys.Contains("min") && json["val"].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 = Double.Parse(json["min"]["value"].ToString());
|
||||||
this.TempMax = Single.Parse(json["max"]["value"].ToString());
|
this.TempMax = Double.Parse(json["max"]["value"].ToString());
|
||||||
this.HasMinMax = true;
|
this.HasMinMax = true;
|
||||||
ret = true;
|
ret = true;
|
||||||
} else {
|
} else {
|
||||||
this.HasMinMax = false;
|
this.HasMinMax = false;
|
||||||
}
|
}
|
||||||
if (ret && this.CheckSetUpdateTime(json)) {
|
if (ret && this.CheckSetUpdateTime(json)) {
|
||||||
this.Update?.Invoke(this, new DeviceUpdateEvent(new Tuple<String, String, Single, Single, Single, Boolean>(this.Type, this.Scale, this.Level, this.TempMin, this.TempMax, this.HasMinMax), this.LastUpdate));
|
this.Update?.Invoke(this, new DeviceUpdateEvent(new Tuple<String, String, Double, Double, Double, Boolean>(this.Type, this.Scale, this.Level, this.TempMin, this.TempMax, this.HasMinMax), this.LastUpdate, this));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override String ToString() {
|
public override String ToString() {
|
||||||
return "ThermostatSetPoint " + this.Name + ": " + 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() => this.PollSub();
|
||||||
|
|
||||||
|
public override Dictionary<String, Object> ToDictionary() {
|
||||||
|
return new Dictionary<String, Object> {
|
||||||
|
{ "Level", this.Level },
|
||||||
|
{ "Type", this.Type },
|
||||||
|
{ "Scale", this.Scale },
|
||||||
|
{ "TempMax", this.TempMax },
|
||||||
|
{ "TempMin", this.TempMin },
|
||||||
|
{ "HasMinMax", this.HasMinMax },
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,62 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Collections.ObjectModel;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
using BlubbFish.IoT.Zway.Devices.CommandClasses.CommandClassSubs;
|
||||||
|
using BlubbFish.IoT.Zway.Events;
|
||||||
|
using BlubbFish.IoT.Zway.Interfaces;
|
||||||
|
using BlubbFish.IoT.Zway.lib;
|
||||||
|
using LitJson;
|
||||||
|
|
||||||
|
namespace BlubbFish.IoT.Zway.Devices.CommandClasses {
|
||||||
|
/// <summary>
|
||||||
|
/// 112 = Configuration
|
||||||
|
/// </summary>
|
||||||
|
class Configuration : ACommandClass {
|
||||||
|
public override event UpdatedValue Update;
|
||||||
|
|
||||||
|
public Configuration(JsonData json, Tuple<Int32, Int32, Classes> id, HttpConnection http, Boolean polling) : base(json, id, http, polling) {
|
||||||
|
this.HasSub = true;
|
||||||
|
this.InitComplex(json);
|
||||||
|
foreach (KeyValuePair<Int32, ACommandClass> item in this.Sub) {
|
||||||
|
item.Value.Update += this.DeviceUpdate;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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"];
|
||||||
|
Dictionary<Int32, ACommandClass> subs = new Dictionary<Int32, ACommandClass>();
|
||||||
|
foreach (String item in data.Keys) {
|
||||||
|
if (Int32.TryParse(item, out Int32 subid) &&
|
||||||
|
data[item].Keys.Contains("size") &&
|
||||||
|
data[item].Keys.Contains("val") &&
|
||||||
|
data[item]["val"].Keys.Contains("value") &&
|
||||||
|
data[item]["val"]["value"] != null) {
|
||||||
|
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, ACommandClass>(subs);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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<String, Object> ToDictionary() => this.ToDictionarySub();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,46 +1,67 @@
|
|||||||
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.lib;
|
using BlubbFish.IoT.Zway.lib;
|
||||||
using LitJson;
|
using LitJson;
|
||||||
|
|
||||||
namespace BlubbFish.IoT.Zway.Devices.CommandClasses {
|
namespace BlubbFish.IoT.Zway.Devices.CommandClasses {
|
||||||
class Indicator : CommandClass {
|
/// <summary>
|
||||||
private Boolean _level;
|
/// 135 = Indicator
|
||||||
|
/// </summary>
|
||||||
|
class Indicator : ACommandClass {
|
||||||
|
private Boolean _state;
|
||||||
|
|
||||||
public override event UpdatedValue Update;
|
public override event UpdatedValue Update;
|
||||||
public Boolean Level {
|
public Boolean State {
|
||||||
get {
|
get {
|
||||||
return this._level;
|
return this._state;
|
||||||
}
|
}
|
||||||
set {
|
set {
|
||||||
this.SetInt(value ? 255 : 0);
|
this.SetInt(value ? 255 : 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Indicator(JsonData json, HttpConnection http, Tuple<Int32, Int32, Int32> id) : base(json, http, id) {
|
public Int32 Level {
|
||||||
|
get {
|
||||||
|
return (this.State) ? 1 : 0;
|
||||||
|
}
|
||||||
|
set {
|
||||||
|
this.State = (value == 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Indicator(JsonData json, Tuple<Int32, Int32, Classes> id, HttpConnection http, Boolean polling) : base(json, id, http, polling) {
|
||||||
this.InitComplex(json);
|
this.InitComplex(json);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void InitComplex(JsonData json) {
|
private void InitComplex(JsonData json) {
|
||||||
if(json.Keys.Contains("data") && json["data"].Keys.Contains("stat") && json["data"]["stat"].Keys.Contains("value")) {
|
if (json.Keys.Contains("data") && json["data"].Keys.Contains("stat") && json["data"]["stat"].Keys.Contains("value")) {
|
||||||
this._level = Int32.Parse(json["data"]["stat"]["value"].ToString()) == 255;
|
this._state = Int32.Parse(json["data"]["stat"]["value"].ToString()) == 255;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal override void SetUpdate(JsonData json, Match match) {
|
internal override void SetUpdate(JsonData json, Match match) {
|
||||||
if(match.Groups[4].Value == ".data.stat") {
|
if(match.Groups[4].Value == ".data.stat") {
|
||||||
if (json.Keys.Contains("value") && this.CheckSetUpdateTime(json)) {
|
if (json.Keys.Contains("value") && this.CheckSetUpdateTime(json)) {
|
||||||
this._level = Int32.Parse(json["value"].ToString()) == 255;
|
this._state = Int32.Parse(json["value"].ToString()) == 255;
|
||||||
this.Update?.Invoke(this, new DeviceUpdateEvent(this.Level, this.LastUpdate));
|
this.Update?.Invoke(this, new DeviceUpdateEvent(this.State, this.LastUpdate, this));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new NotImplementedException();
|
Helper.WriteError("Kenne in " + this.Name + " [" + this.Id + "] " + match.Groups[4].Value + " nicht!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override String ToString() {
|
public override String ToString() {
|
||||||
return "Indicator " + this.Name + ": " + this.Level;
|
return "Indicator " + this.Name + " [" + this.Id + "]: " + this.State;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override Dictionary<String, Object> ToDictionary() {
|
||||||
|
return new Dictionary<String, Object> {
|
||||||
|
{ "State", this.State },
|
||||||
|
{ "Level", this.Level }
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,25 +4,27 @@ using System.Collections.ObjectModel;
|
|||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using BlubbFish.IoT.Zway.Devices.CommandClasses.CommandClassSubs;
|
using BlubbFish.IoT.Zway.Devices.CommandClasses.CommandClassSubs;
|
||||||
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;
|
||||||
|
|
||||||
namespace BlubbFish.IoT.Zway.Devices.CommandClasses {
|
namespace BlubbFish.IoT.Zway.Devices.CommandClasses {
|
||||||
public class Meter : CommandClass {
|
/// <summary>
|
||||||
|
/// 50 = Meter
|
||||||
|
/// </summary>
|
||||||
|
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) : base(json, http, id) {
|
|
||||||
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void DeviceUpdate(Object sender, DeviceUpdateEvent e) {
|
private void DeviceUpdate(Object sender, DeviceUpdateEvent e) {
|
||||||
this.Update?.Invoke(sender, e);
|
this.Update?.Invoke(this, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal override void SetUpdate(JsonData json, Match match) {
|
internal override void SetUpdate(JsonData json, Match match) {
|
||||||
@@ -32,24 +34,28 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses {
|
|||||||
this.Sub[subid].SetUpdate(json, match);
|
this.Sub[subid].SetUpdate(json, match);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new NotImplementedException();
|
Helper.WriteError("Kenne in " + this.Name + " [" + this.Id + "] " + match.Groups[4].Value + " nicht!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override 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));
|
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() => this.PollSubGlobal();
|
||||||
|
|
||||||
|
public override Dictionary<String, Object> ToDictionary() => this.ToDictionarySub();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,60 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Collections.ObjectModel;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
using BlubbFish.IoT.Zway.Devices.CommandClasses.CommandClassSubs;
|
||||||
|
using BlubbFish.IoT.Zway.Events;
|
||||||
|
using BlubbFish.IoT.Zway.Interfaces;
|
||||||
|
using BlubbFish.IoT.Zway.lib;
|
||||||
|
using LitJson;
|
||||||
|
|
||||||
|
namespace BlubbFish.IoT.Zway.Devices.CommandClasses {
|
||||||
|
/// <summary>
|
||||||
|
/// 50 = Meter
|
||||||
|
/// </summary>
|
||||||
|
public class Scenecontrollerconf : ACommandClass {
|
||||||
|
public override event UpdatedValue Update;
|
||||||
|
|
||||||
|
public Scenecontrollerconf(JsonData json, Tuple<Int32, Int32, Classes> id, HttpConnection http, Boolean polling) : base(json, id, http, polling) {
|
||||||
|
this.HasSub = true;
|
||||||
|
this.InitComplex(json);
|
||||||
|
foreach (KeyValuePair<Int32, ACommandClass> item in this.Sub) {
|
||||||
|
item.Value.Update += this.DeviceUpdate;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void DeviceUpdate(Object sender, DeviceUpdateEvent e) {
|
||||||
|
this.Update?.Invoke(this, e);
|
||||||
|
}
|
||||||
|
|
||||||
|
internal override void SetUpdate(JsonData json, Match match) {
|
||||||
|
if (match.Groups[4].Value.StartsWith(".data.")) {
|
||||||
|
Int32 subid = Int32.Parse(match.Groups[5].Value);
|
||||||
|
if (this.Sub.ContainsKey(subid)) {
|
||||||
|
this.Sub[subid].SetUpdate(json, match);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Helper.WriteError("Kenne in " + this.Name + " [" + this.Id + "] " + match.Groups[4].Value + " nicht!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void InitComplex(JsonData json) {
|
||||||
|
if (json.Keys.Contains("data")) {
|
||||||
|
JsonData data = json["data"];
|
||||||
|
Dictionary<Int32, ACommandClass> subs = new Dictionary<Int32, ACommandClass>();
|
||||||
|
foreach (String item in data.Keys) {
|
||||||
|
if (Int32.TryParse(item, out Int32 subid) &&
|
||||||
|
data[item].Keys.Contains("scene") &&
|
||||||
|
data[item].Keys.Contains("duration")) {
|
||||||
|
subs.Add(subid, new Scenecontrollerconfsub(data[item], new Tuple<Int32, Int32, Classes, Int32>(this.DeviceId, this.Instance, this.Commandclass, subid), this.http, this.Polling));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.Sub = new ReadOnlyDictionary<Int32, ACommandClass>(subs);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
internal override void Poll() => this.PollPerSub();
|
||||||
|
|
||||||
|
public override Dictionary<String, Object> ToDictionary() => this.ToDictionarySub();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Collections.ObjectModel;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
using BlubbFish.IoT.Zway.Devices.CommandClasses.CommandClassSubs;
|
||||||
|
using BlubbFish.IoT.Zway.Events;
|
||||||
|
using BlubbFish.IoT.Zway.Interfaces;
|
||||||
|
using BlubbFish.IoT.Zway.lib;
|
||||||
|
using LitJson;
|
||||||
|
|
||||||
|
namespace BlubbFish.IoT.Zway.Devices.CommandClasses {
|
||||||
|
/// <summary>
|
||||||
|
/// 48 = SensorBinary
|
||||||
|
/// </summary>
|
||||||
|
public class Sensorbinary : ACommandClass {
|
||||||
|
public override event UpdatedValue Update;
|
||||||
|
|
||||||
|
public Sensorbinary(JsonData json, Tuple<Int32, Int32, Classes> id, HttpConnection http, Boolean polling) : base(json, id, http, polling) {
|
||||||
|
this.HasSub = true;
|
||||||
|
this.InitComplex(json);
|
||||||
|
foreach (KeyValuePair<Int32, ACommandClass> item in this.Sub) {
|
||||||
|
item.Value.Update += this.DeviceUpdate;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void DeviceUpdate(Object sender, DeviceUpdateEvent e) {
|
||||||
|
this.Update?.Invoke(this, e);
|
||||||
|
}
|
||||||
|
|
||||||
|
internal override void SetUpdate(JsonData json, Match match) {
|
||||||
|
if (match.Groups[4].Value.StartsWith(".data.")) {
|
||||||
|
Int32 subid = Int32.Parse(match.Groups[5].Value);
|
||||||
|
if (this.Sub.ContainsKey(subid)) {
|
||||||
|
this.Sub[subid].SetUpdate(json, match);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Helper.WriteError("Kenne in " + this.Name + " [" + this.Id + "] " + match.Groups[4].Value + " nicht!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void InitComplex(JsonData json) {
|
||||||
|
if (json.Keys.Contains("data")) {
|
||||||
|
JsonData data = json["data"];
|
||||||
|
Dictionary<Int32, ACommandClass> subs = new Dictionary<Int32, ACommandClass>();
|
||||||
|
foreach (String item in data.Keys) {
|
||||||
|
if (Int32.TryParse(item, out Int32 subid) &&
|
||||||
|
data[item].Keys.Contains("sensorTypeString") &&
|
||||||
|
data[item].Keys.Contains("level")) {
|
||||||
|
subs.Add(subid, new Sensorbinarysub(data[item], new Tuple<Int32, Int32, Classes, Int32>(this.DeviceId, this.Instance, this.Commandclass, subid), this.http, this.Polling));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.Sub = new ReadOnlyDictionary<Int32, ACommandClass>(subs);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
internal override void Poll() => this.PollSubGlobal();
|
||||||
|
|
||||||
|
public override Dictionary<String, Object> ToDictionary() => this.ToDictionarySub();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,25 +4,27 @@ using System.Collections.ObjectModel;
|
|||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using BlubbFish.IoT.Zway.Devices.CommandClasses.CommandClassSubs;
|
using BlubbFish.IoT.Zway.Devices.CommandClasses.CommandClassSubs;
|
||||||
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;
|
||||||
|
|
||||||
namespace BlubbFish.IoT.Zway.Devices.CommandClasses {
|
namespace BlubbFish.IoT.Zway.Devices.CommandClasses {
|
||||||
public class Sensormultilevel : CommandClass {
|
/// <summary>
|
||||||
|
/// 49 = SensorMultilevel
|
||||||
|
/// </summary>
|
||||||
|
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) : base(json, http, id) {
|
|
||||||
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void DeviceUpdate(Object sender, DeviceUpdateEvent e) {
|
private void DeviceUpdate(Object sender, DeviceUpdateEvent e) {
|
||||||
this.Update?.Invoke(sender, e);
|
this.Update?.Invoke(this, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal override void SetUpdate(JsonData json, Match match) {
|
internal override void SetUpdate(JsonData json, Match match) {
|
||||||
@@ -32,24 +34,28 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses {
|
|||||||
this.Sub[subid].SetUpdate(json, match);
|
this.Sub[subid].SetUpdate(json, match);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new NotImplementedException();
|
Helper.WriteError("Kenne in " + this.Name + " [" + this.Id + "] " + match.Groups[4].Value + " nicht!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override 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));
|
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() => this.PollSubGlobal();
|
||||||
|
|
||||||
|
public override Dictionary<String, Object> ToDictionary() => this.ToDictionarySub();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,47 +1,68 @@
|
|||||||
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.lib;
|
using BlubbFish.IoT.Zway.lib;
|
||||||
using LitJson;
|
using LitJson;
|
||||||
|
|
||||||
namespace BlubbFish.IoT.Zway.Devices.CommandClasses {
|
namespace BlubbFish.IoT.Zway.Devices.CommandClasses {
|
||||||
public class Switchbinary : CommandClass {
|
/// <summary>
|
||||||
private Boolean _level;
|
/// 37 = SwitchBinary
|
||||||
|
/// </summary>
|
||||||
|
public class Switchbinary : ACommandClass {
|
||||||
|
private Boolean _state;
|
||||||
|
|
||||||
public override event UpdatedValue Update;
|
public override event UpdatedValue Update;
|
||||||
|
|
||||||
public Boolean Level {
|
public Int32 Level {
|
||||||
get {
|
get {
|
||||||
return this._level;
|
return (this.State) ? 1 : 0;
|
||||||
|
}
|
||||||
|
set {
|
||||||
|
this.State = (value == 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Boolean State {
|
||||||
|
get {
|
||||||
|
return this._state;
|
||||||
}
|
}
|
||||||
set {
|
set {
|
||||||
this.SetInt(value ? 255 : 0);
|
this.SetInt(value ? 255 : 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Switchbinary(JsonData json, HttpConnection http, Tuple<Int32, Int32, Int32> id) : base(json, http, id) {
|
public Switchbinary(JsonData json, Tuple<Int32, Int32, Classes> id, HttpConnection http, Boolean polling) : base(json, id, http, polling) {
|
||||||
this.InitComplex(json);
|
this.InitComplex(json);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal override void SetUpdate(JsonData json, Match match) {
|
internal override void SetUpdate(JsonData json, Match match) {
|
||||||
if(match.Groups[4].Value == ".data.level") {
|
if(match.Groups[4].Value == ".data.level") {
|
||||||
if (json.Keys.Contains("value") && json["value"].IsBoolean && this.CheckSetUpdateTime(json)) {
|
if (json.Keys.Contains("value") && json["value"].IsBoolean && this.CheckSetUpdateTime(json)) {
|
||||||
this._level = (Boolean)json["value"];
|
this._state = (Boolean)json["value"];
|
||||||
this.Update?.Invoke(this, new DeviceUpdateEvent(this.Level, this.LastUpdate));
|
this.Update?.Invoke(this, new DeviceUpdateEvent(this.State, this.LastUpdate, this));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new NotImplementedException();
|
Helper.WriteError("Kenne in " + this.Name + " [" + this.Id + "] " + match.Groups[4].Value + " nicht!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void InitComplex(JsonData 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) {
|
if (json.Keys.Contains("data") && json["data"].Keys.Contains("level") && json["data"]["level"].Keys.Contains("value") && json["data"]["level"]["value"].IsBoolean) {
|
||||||
this._level = (Boolean)json["data"]["level"]["value"];
|
this._state = (Boolean)json["data"]["level"]["value"];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override String ToString() {
|
public override String ToString() {
|
||||||
return "SwitchBinary " + this.Name + ": " + this.Level;
|
return "SwitchBinary " + this.Name + " [" + this.Id + "]: " + this.State;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override Dictionary<String, Object> ToDictionary() {
|
||||||
|
return new Dictionary<String, Object> {
|
||||||
|
{ "State", this.State },
|
||||||
|
{ "Level", this.Level }
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,16 @@
|
|||||||
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.lib;
|
using BlubbFish.IoT.Zway.lib;
|
||||||
using LitJson;
|
using LitJson;
|
||||||
|
|
||||||
namespace BlubbFish.IoT.Zway.Devices.CommandClasses {
|
namespace BlubbFish.IoT.Zway.Devices.CommandClasses {
|
||||||
public class Switchmultilevel : CommandClass {
|
/// <summary>
|
||||||
|
/// 38 = SwitchMultilevel
|
||||||
|
/// </summary>
|
||||||
|
public class Switchmultilevel : ACommandClass {
|
||||||
private Int32 _level;
|
private Int32 _level;
|
||||||
|
|
||||||
public override event UpdatedValue Update;
|
public override event UpdatedValue Update;
|
||||||
@@ -16,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) : base(json, http, id) {
|
public Switchmultilevel(JsonData json, Tuple<Int32, Int32, Classes> id, HttpConnection http, Boolean polling) : base(json, id, http, polling) {
|
||||||
this.InitComplex(json);
|
this.InitComplex(json);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -29,22 +34,28 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses {
|
|||||||
if(match.Groups[4].Value == ".data.level") {
|
if(match.Groups[4].Value == ".data.level") {
|
||||||
if(json.Keys.Contains("value") && this.CheckSetUpdateTime(json)) {
|
if(json.Keys.Contains("value") && this.CheckSetUpdateTime(json)) {
|
||||||
this._level = Int32.Parse(json["value"].ToString());
|
this._level = Int32.Parse(json["value"].ToString());
|
||||||
this.Update?.Invoke(this, new DeviceUpdateEvent(this.Level, this.LastUpdate));
|
this.Update?.Invoke(this, new DeviceUpdateEvent(this.Level, this.LastUpdate, this));
|
||||||
}
|
}
|
||||||
} else if (match.Groups[4].Value == ".data.prevLevel") {
|
} else if (match.Groups[4].Value == ".data.prevLevel") {
|
||||||
} else {
|
} else {
|
||||||
throw new NotImplementedException();
|
Helper.WriteError("Kenne in " + this.Name + " [" + this.Id + "] " + match.Groups[4].Value + " nicht!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void InitComplex(JsonData json) {
|
private void InitComplex(JsonData json) {
|
||||||
if(json.Keys.Contains("data") && json["data"].Keys.Contains("level") && json["data"]["level"].Keys.Contains("value")) {
|
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());
|
this._level = Int32.Parse(json["data"]["level"]["value"].ToString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override String ToString() {
|
public override String ToString() {
|
||||||
return "SwitchMultilevel " + this.Name + ": " + this.Level;
|
return "SwitchMultilevel " + this.Name + " [" + this.Id + "]: " + this.Level;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override Dictionary<String, Object> ToDictionary() {
|
||||||
|
return new Dictionary<String, Object> {
|
||||||
|
{ "Level", this.Level }
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,11 +3,15 @@ using System.Collections.Generic;
|
|||||||
using System.Collections.ObjectModel;
|
using System.Collections.ObjectModel;
|
||||||
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.lib;
|
using BlubbFish.IoT.Zway.lib;
|
||||||
using LitJson;
|
using LitJson;
|
||||||
|
|
||||||
namespace BlubbFish.IoT.Zway.Devices.CommandClasses {
|
namespace BlubbFish.IoT.Zway.Devices.CommandClasses {
|
||||||
public class Thermostatmode : CommandClass {
|
/// <summary>
|
||||||
|
/// 64 = ThermostatMode
|
||||||
|
/// </summary>
|
||||||
|
public class Thermostatmode : ACommandClass {
|
||||||
private Int32 _level;
|
private Int32 _level;
|
||||||
|
|
||||||
public override event UpdatedValue Update;
|
public override event UpdatedValue Update;
|
||||||
@@ -22,7 +26,7 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Thermostatmode(JsonData json, HttpConnection http, Tuple<Int32, Int32, Int32> id) : base(json, http, id) {
|
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);
|
||||||
}
|
}
|
||||||
@@ -31,14 +35,14 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses {
|
|||||||
if(match.Groups[4].Value == ".data.mode") {
|
if(match.Groups[4].Value == ".data.mode") {
|
||||||
if(json.Keys.Contains("value") && this.CheckSetUpdateTime(json)) {
|
if(json.Keys.Contains("value") && this.CheckSetUpdateTime(json)) {
|
||||||
this._level = Int32.Parse(json["value"].ToString());
|
this._level = Int32.Parse(json["value"].ToString());
|
||||||
this.Update?.Invoke(this, new DeviceUpdateEvent(this.Level, this.LastUpdate));
|
this.Update?.Invoke(this, new DeviceUpdateEvent(this.Level, this.LastUpdate, this));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new NotImplementedException();
|
Helper.WriteError("Kenne in " + this.Name + " [" + this.Id + "] " + match.Groups[4].Value + " nicht!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override 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, String> modes = new Dictionary<Int32, String>();
|
Dictionary<Int32, String> modes = new Dictionary<Int32, String>();
|
||||||
@@ -58,7 +62,19 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public override String ToString() {
|
public override String ToString() {
|
||||||
return "ThermostatMode " + this.Name + ": " + 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 },
|
||||||
|
{ "ValidModes", modes }
|
||||||
|
};
|
||||||
|
return json;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,24 +4,27 @@ using System.Collections.ObjectModel;
|
|||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using BlubbFish.IoT.Zway.Devices.CommandClasses.CommandClassSubs;
|
using BlubbFish.IoT.Zway.Devices.CommandClasses.CommandClassSubs;
|
||||||
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;
|
||||||
|
|
||||||
namespace BlubbFish.IoT.Zway.Devices.CommandClasses {
|
namespace BlubbFish.IoT.Zway.Devices.CommandClasses {
|
||||||
public class Thermostatsetpoint : CommandClass {
|
/// <summary>
|
||||||
|
/// 67 = ThermostatSetPoint
|
||||||
|
/// </summary>
|
||||||
|
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) : base(json, http, id) {
|
|
||||||
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void DeviceUpdate(Object sender, DeviceUpdateEvent e) {
|
private void DeviceUpdate(Object sender, DeviceUpdateEvent e) {
|
||||||
this.Update?.Invoke(sender, e);
|
this.Update?.Invoke(this, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal override void SetUpdate(JsonData json, Match match) {
|
internal override void SetUpdate(JsonData json, Match match) {
|
||||||
@@ -31,30 +34,28 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses {
|
|||||||
this.Sub[subid].SetUpdate(json, match);
|
this.Sub[subid].SetUpdate(json, match);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new NotImplementedException();
|
Helper.WriteError("Kenne in " + this.Name + " [" + this.Id + "] " + match.Groups[4].Value + " nicht!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override 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));
|
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) {
|
|
||||||
this.http.GetVoid("ZWave.zway/Run/devices[" + this.DeviceId + "].instances[" + this.Instance + "].commandClasses[" + this.Commandclass + "].Get(" + item.Key + ")");
|
public override Dictionary<String, Object> ToDictionary() => this.ToDictionarySub();
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,15 +1,16 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using System.Threading.Tasks;
|
|
||||||
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;
|
||||||
|
|
||||||
namespace BlubbFish.IoT.Zway.Devices.CommandClasses {
|
namespace BlubbFish.IoT.Zway.Devices.CommandClasses {
|
||||||
class Wakeup : CommandClass {
|
/// <summary>
|
||||||
|
/// 132 = Wakeup
|
||||||
|
/// </summary>
|
||||||
|
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,21 +29,25 @@ 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; }
|
||||||
public Int32 WakeupMax { get; private set; }
|
public Int32 WakeupMax { get; private set; }
|
||||||
|
public Boolean HasMinMaxState { get; private set; }
|
||||||
|
public Int32 HasMinMaxLevel { get { return (this.HasMinMaxState) ? 1 : 0; } }
|
||||||
public Int32 WakeupDefault { get; private set; }
|
public Int32 WakeupDefault { get; private set; }
|
||||||
|
public Boolean HasDefaultState { get; private set; }
|
||||||
|
public Int32 HasDefaultLevel { get { return (this.HasDefaultState) ? 1 : 0; } }
|
||||||
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) : base(json, http, id) {
|
public Wakeup(JsonData json, Tuple<Int32, Int32, Classes> id, HttpConnection http, Boolean polling) : base(json, id, http, polling) {
|
||||||
this.InitComplex(json);
|
this.InitComplex(json);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override 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"];
|
||||||
if(data.Keys.Contains("interval") && data["interval"].Keys.Contains("value")) {
|
if(data.Keys.Contains("interval") && data["interval"].Keys.Contains("value")) {
|
||||||
this._interval = Int32.Parse(data["interval"]["value"].ToString());
|
this._interval = Int32.Parse(data["interval"]["value"].ToString());
|
||||||
@@ -50,19 +55,24 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses {
|
|||||||
if (data.Keys.Contains("nodeId") && data["nodeId"].Keys.Contains("value")) {
|
if (data.Keys.Contains("nodeId") && data["nodeId"].Keys.Contains("value")) {
|
||||||
this._againstNode = Int32.Parse(data["nodeId"]["value"].ToString());
|
this._againstNode = Int32.Parse(data["nodeId"]["value"].ToString());
|
||||||
}
|
}
|
||||||
if (data.Keys.Contains("min") && data["min"].Keys.Contains("value")) {
|
this.HasMinMaxState = false;
|
||||||
|
if (data.Keys.Contains("min") && data["min"].Keys.Contains("value") && data["min"]["value"] != null) {
|
||||||
this.WakeupMin = Int32.Parse(data["min"]["value"].ToString());
|
this.WakeupMin = Int32.Parse(data["min"]["value"].ToString());
|
||||||
|
this.HasMinMaxState = true;
|
||||||
}
|
}
|
||||||
if (data.Keys.Contains("max") && data["max"].Keys.Contains("value")) {
|
if (data.Keys.Contains("max") && data["max"].Keys.Contains("value") && data["max"]["value"] != null) {
|
||||||
this.WakeupMax = Int32.Parse(data["max"]["value"].ToString());
|
this.WakeupMax = Int32.Parse(data["max"]["value"].ToString());
|
||||||
|
this.HasMinMaxState = true;
|
||||||
}
|
}
|
||||||
if (data.Keys.Contains("default") && data["default"].Keys.Contains("value")) {
|
this.HasDefaultState = false;
|
||||||
|
if (data.Keys.Contains("default") && data["default"].Keys.Contains("value") && data["default"]["value"] != null) {
|
||||||
this.WakeupDefault = Int32.Parse(data["default"]["value"].ToString());
|
this.WakeupDefault = Int32.Parse(data["default"]["value"].ToString());
|
||||||
|
this.HasDefaultState = true;
|
||||||
}
|
}
|
||||||
if (data.Keys.Contains("lastWakeup") && data["lastWakeup"].Keys.Contains("value")) {
|
if (data.Keys.Contains("lastWakeup") && data["lastWakeup"].Keys.Contains("value") && data["lastWakeup"]["value"] != null) {
|
||||||
this.LastWakeup = DateTimeOffset.FromUnixTimeSeconds(Int64.Parse(data["lastWakeup"]["value"].ToString())).DateTime.ToLocalTime();
|
this.LastWakeup = DateTimeOffset.FromUnixTimeSeconds(Int64.Parse(data["lastWakeup"]["value"].ToString())).DateTime.ToLocalTime();
|
||||||
}
|
}
|
||||||
if (data.Keys.Contains("lastSleep") && data["lastSleep"].Keys.Contains("value")) {
|
if (data.Keys.Contains("lastSleep") && data["lastSleep"].Keys.Contains("value") && data["lastSleep"]["value"] != null) {
|
||||||
this.LastSleep = DateTimeOffset.FromUnixTimeSeconds(Int64.Parse(data["lastSleep"]["value"].ToString())).DateTime.ToLocalTime();
|
this.LastSleep = DateTimeOffset.FromUnixTimeSeconds(Int64.Parse(data["lastSleep"]["value"].ToString())).DateTime.ToLocalTime();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -89,36 +99,57 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses {
|
|||||||
this._againstNode = Int32.Parse(json["nodeId"]["value"].ToString());
|
this._againstNode = Int32.Parse(json["nodeId"]["value"].ToString());
|
||||||
success = true;
|
success = true;
|
||||||
}
|
}
|
||||||
if (json.Keys.Contains("min") && json["min"].Keys.Contains("value")) {
|
this.HasMinMaxState = false;
|
||||||
|
if (json.Keys.Contains("min") && json["min"].Keys.Contains("value") && json["min"]["value"] != null) {
|
||||||
this.WakeupMin = Int32.Parse(json["min"]["value"].ToString());
|
this.WakeupMin = Int32.Parse(json["min"]["value"].ToString());
|
||||||
success = true;
|
success = true;
|
||||||
|
this.HasMinMaxState = true;
|
||||||
}
|
}
|
||||||
if (json.Keys.Contains("max") && json["max"].Keys.Contains("value")) {
|
if (json.Keys.Contains("max") && json["max"].Keys.Contains("value") && json["max"]["value"] != null) {
|
||||||
this.WakeupMax = Int32.Parse(json["max"]["value"].ToString());
|
this.WakeupMax = Int32.Parse(json["max"]["value"].ToString());
|
||||||
success = true;
|
success = true;
|
||||||
|
this.HasMinMaxState = true;
|
||||||
}
|
}
|
||||||
if (json.Keys.Contains("default") && json["default"].Keys.Contains("value")) {
|
this.HasDefaultState = false;
|
||||||
|
if (json.Keys.Contains("default") && json["default"].Keys.Contains("value") && json["default"]["value"] != null) {
|
||||||
this.WakeupDefault = Int32.Parse(json["default"]["value"].ToString());
|
this.WakeupDefault = Int32.Parse(json["default"]["value"].ToString());
|
||||||
success = true;
|
success = true;
|
||||||
|
this.HasDefaultState = true;
|
||||||
}
|
}
|
||||||
if (json.Keys.Contains("lastWakeup") && json["lastWakeup"].Keys.Contains("value")) {
|
if (json.Keys.Contains("lastWakeup") && json["lastWakeup"].Keys.Contains("value") && json["lastWakeup"]["value"] != null) {
|
||||||
this.LastWakeup = DateTimeOffset.FromUnixTimeSeconds(Int64.Parse(json["lastWakeup"]["value"].ToString())).DateTime.ToLocalTime();
|
this.LastWakeup = DateTimeOffset.FromUnixTimeSeconds(Int64.Parse(json["lastWakeup"]["value"].ToString())).DateTime.ToLocalTime();
|
||||||
success = true;
|
success = true;
|
||||||
}
|
}
|
||||||
if (json.Keys.Contains("lastSleep") && json["lastSleep"].Keys.Contains("value")) {
|
if (json.Keys.Contains("lastSleep") && json["lastSleep"].Keys.Contains("value") && json["lastSleep"]["value"] != null) {
|
||||||
this.LastSleep = DateTimeOffset.FromUnixTimeSeconds(Int64.Parse(json["lastSleep"]["value"].ToString())).DateTime.ToLocalTime();
|
this.LastSleep = DateTimeOffset.FromUnixTimeSeconds(Int64.Parse(json["lastSleep"]["value"].ToString())).DateTime.ToLocalTime();
|
||||||
success = true;
|
success = true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new NotImplementedException();
|
Helper.WriteError("Kenne in " + this.Name + " [" + this.Id + "] " + match.Groups[4].Value + " nicht!");
|
||||||
}
|
}
|
||||||
if (success && this.CheckSetUpdateTime(json)) {
|
if (success && this.CheckSetUpdateTime(json)) {
|
||||||
this.Update?.Invoke(this, new DeviceUpdateEvent(0, this.LastUpdate));
|
this.Update?.Invoke(this, new DeviceUpdateEvent(0, this.LastUpdate, this));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override String ToString() {
|
public override String ToString() {
|
||||||
return "Wakeup " + this.Name + ": " + 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> {
|
||||||
|
{ "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() }
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+19
-18
@@ -1,30 +1,27 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Collections.ObjectModel;
|
||||||
using System.Text;
|
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using System.Threading.Tasks;
|
|
||||||
using BlubbFish.IoT.Zway.Events;
|
using BlubbFish.IoT.Zway.Events;
|
||||||
using BlubbFish.IoT.Zway.lib;
|
using BlubbFish.IoT.Zway.lib;
|
||||||
using LitJson;
|
using LitJson;
|
||||||
|
|
||||||
namespace BlubbFish.IoT.Zway.Devices {
|
namespace BlubbFish.IoT.Zway.Devices {
|
||||||
class Device {
|
public class Device {
|
||||||
private Dictionary<Int32, Instance> _instances = new Dictionary<Int32, Instance>();
|
private Boolean polling;
|
||||||
|
|
||||||
public delegate void UpdatedDevice(Object sender, DeviceUpdateEvent e);
|
public delegate void UpdatedDevice(Object sender, DeviceUpdateEvent e);
|
||||||
public event UpdatedDevice Update;
|
public event UpdatedDevice Update;
|
||||||
|
|
||||||
public String Name { get; }
|
public String Name { get; }
|
||||||
public Int32 Id { get; }
|
public Int32 Id { get; }
|
||||||
public Dictionary<Int32, Instance> Instances { get { return this._instances; } }
|
public ReadOnlyDictionary<Int32, Instance> Instances { get; private set; }
|
||||||
public DateTime LastUpdate { get; private set; }
|
public DateTime LastUpdate { get; private set; }
|
||||||
|
|
||||||
private Device(JsonData json, Tuple<Int32> id, HttpConnection http) {
|
private Device(JsonData json, Tuple<Int32> id, HttpConnection http, Boolean polling) {
|
||||||
this.Id = id.Item1;
|
this.Id = id.Item1;
|
||||||
foreach (String instanceid in json["instances"].Keys) {
|
this.polling = polling;
|
||||||
this.CreateInstances(Int32.Parse(instanceid), json["instances"][instanceid], http);
|
this.CreateInstances(json["instances"], http);
|
||||||
}
|
|
||||||
if (json["data"].Keys.Contains("givenName") && json["data"]["givenName"].Keys.Contains("value")) {
|
if (json["data"].Keys.Contains("givenName") && json["data"]["givenName"].Keys.Contains("value")) {
|
||||||
this.Name = json["data"]["givenName"]["value"].ToString();
|
this.Name = json["data"]["givenName"]["value"].ToString();
|
||||||
} else {
|
} else {
|
||||||
@@ -50,33 +47,37 @@ namespace BlubbFish.IoT.Zway.Devices {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void InstanceUpdate(Object sender, DeviceUpdateEvent e) {
|
private void InstanceUpdate(Object sender, DeviceUpdateEvent e) {
|
||||||
this.Update?.Invoke(sender, e);
|
this.Update?.Invoke(this, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void CreateInstances(Int32 instanceid, JsonData json, HttpConnection http) {
|
private void CreateInstances(JsonData json, HttpConnection http) {
|
||||||
Instance i = Instance.CreateInstance(json, new Tuple<Int32, Int32>(this.Id, instanceid), http);
|
Dictionary<Int32, Instance> instances = new Dictionary<Int32, Instance>();
|
||||||
|
foreach (String instanceid in json.Keys) {
|
||||||
|
Instance i = Instance.CreateInstance(json[instanceid], new Tuple<Int32, Int32>(this.Id, Int32.Parse(instanceid)), http, this.polling);
|
||||||
if (i != null) {
|
if (i != null) {
|
||||||
this._instances.Add(instanceid, i);
|
instances.Add(Int32.Parse(instanceid), i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
this.Instances = new ReadOnlyDictionary<Int32, Instance>(instances);
|
||||||
|
}
|
||||||
|
|
||||||
internal static Device CreateDevice(JsonData json, Tuple<Int32> id, HttpConnection http) {
|
internal static Device CreateDevice(JsonData json, Tuple<Int32> id, HttpConnection http, Boolean polling) {
|
||||||
if(json.Keys.Contains("instances") &&
|
if(json.Keys.Contains("instances") &&
|
||||||
json["instances"].Count > 0 &&
|
json["instances"].Count > 0 &&
|
||||||
json.Keys.Contains("data") && id.Item1 != 1) {
|
json.Keys.Contains("data") && id.Item1 != 1) {
|
||||||
return new Device(json, id, http);
|
return new Device(json, id, http, polling);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override String ToString() {
|
public override String ToString() {
|
||||||
return this.Name+"_"+this.Id+" ["+this._instances.Count+"]";
|
return this.Name+"_"+this.Id+" ["+this.Instances.Count+"]";
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void SetUpdate(JsonData json, Match match) {
|
internal void SetUpdate(JsonData json, Match match) {
|
||||||
if (match.Groups[2].Value == "data.lastReceived") {
|
if (match.Groups[2].Value == "data.lastReceived") {
|
||||||
if (this.CheckSetUpdateTime(json)) {
|
if (this.CheckSetUpdateTime(json)) {
|
||||||
this.Update?.Invoke(this, new DeviceUpdateEvent(this.LastUpdate, this.LastUpdate));
|
//this.Update?.Invoke(this, new DeviceUpdateEvent(this.LastUpdate, this.LastUpdate));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+27
-23
@@ -1,71 +1,75 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
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;
|
||||||
|
|
||||||
namespace BlubbFish.IoT.Zway.Devices {
|
namespace BlubbFish.IoT.Zway.Devices {
|
||||||
class Instance {
|
public class Instance {
|
||||||
private Dictionary<Int32, CommandClass> _commands = new Dictionary<Int32, CommandClass>();
|
|
||||||
private DateTime nextwakeup;
|
private DateTime nextwakeup;
|
||||||
|
private Boolean polling;
|
||||||
|
|
||||||
public delegate void UpdatedInstance(Object sender, DeviceUpdateEvent e);
|
public delegate void UpdatedInstance(Object sender, DeviceUpdateEvent e);
|
||||||
public event UpdatedInstance Update;
|
public event UpdatedInstance Update;
|
||||||
|
|
||||||
public Dictionary<Int32, CommandClass> CommandClasses { get { return this._commands; } }
|
public Int32 DeviceId { get; }
|
||||||
|
public Int32 InstanceId { get; }
|
||||||
|
public ReadOnlyDictionary<ACommandClass.Classes, ACommandClass> CommandClasses { get; private set; }
|
||||||
|
|
||||||
private Instance(JsonData json, Tuple<Int32, Int32> id, HttpConnection http) {
|
private Instance(JsonData json, Tuple<Int32, Int32> id, HttpConnection http, Boolean polling) {
|
||||||
this.Id = id.Item1;
|
this.DeviceId = id.Item1;
|
||||||
this.Instanceid = id.Item2;
|
this.InstanceId = id.Item2;
|
||||||
foreach (String commandid in json["commandClasses"].Keys) {
|
this.polling = polling;
|
||||||
this.CreateInstances(Int32.Parse(commandid), json["commandClasses"][commandid], http);
|
this.CreateInstances(json["commandClasses"], http);
|
||||||
}
|
foreach (KeyValuePair<ACommandClass.Classes, ACommandClass> item in this.CommandClasses) {
|
||||||
foreach (KeyValuePair<Int32, CommandClass> 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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ClassUpdate(Object sender, DeviceUpdateEvent e) {
|
private void ClassUpdate(Object sender, DeviceUpdateEvent e) {
|
||||||
this.Update?.Invoke(sender, e);
|
this.Update?.Invoke(this, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void CreateInstances(Int32 commandid, JsonData json, HttpConnection http) {
|
private void CreateInstances(JsonData json, HttpConnection http) {
|
||||||
CommandClass c = CommandClass.CreateInstance(json, new Tuple<Int32, Int32, Int32>(this.Id, this.Instanceid, commandid), http);
|
Dictionary<ACommandClass.Classes, ACommandClass> commands = new Dictionary<ACommandClass.Classes, ACommandClass>();
|
||||||
|
foreach (String commandid in json.Keys) {
|
||||||
|
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) {
|
||||||
this._commands.Add(commandid, c);
|
commands.Add((ACommandClass.Classes)Int32.Parse(commandid), c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
this.CommandClasses = new ReadOnlyDictionary<ACommandClass.Classes, ACommandClass>(commands);
|
||||||
|
}
|
||||||
|
|
||||||
public Int32 Id { get; }
|
internal static Instance CreateInstance(JsonData json, Tuple<Int32, Int32> id, HttpConnection http, Boolean polling) {
|
||||||
public Int32 Instanceid { get; }
|
|
||||||
|
|
||||||
internal static Instance CreateInstance(JsonData json, Tuple<Int32, Int32> id, HttpConnection http) {
|
|
||||||
if (json.Keys.Contains("commandClasses") &&
|
if (json.Keys.Contains("commandClasses") &&
|
||||||
json["commandClasses"].Count > 0 &&
|
json["commandClasses"].Count > 0 &&
|
||||||
json.Keys.Contains("data")) {
|
json.Keys.Contains("data")) {
|
||||||
return new Instance(json, id, http);
|
return new Instance(json, id, http, polling);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override String ToString() {
|
public override String ToString() {
|
||||||
return "Instance: " + this.Id + "-" + this.Instanceid + " [" + this._commands.Count + "]";
|
return "Instance: " + this.DeviceId + "-" + this.InstanceId + " [" + this.CommandClasses.Count + "]";
|
||||||
}
|
}
|
||||||
|
|
||||||
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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,41 +10,14 @@ namespace BlubbFish.IoT.Zway.Events {
|
|||||||
public DeviceUpdateEvent() {
|
public DeviceUpdateEvent() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public DeviceUpdateEvent(Single value, DateTime time) {
|
public DeviceUpdateEvent(Object value, DateTime time, Object parent) {
|
||||||
this.GetSingle = value;
|
this.GetValue = value;
|
||||||
this.UpdateTime = time;
|
this.UpdateTime = time;
|
||||||
|
this.Parent = parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DeviceUpdateEvent(Boolean level, DateTime time) {
|
public Object GetValue { get; }
|
||||||
this.GetBoolean = level;
|
|
||||||
this.UpdateTime = time;
|
|
||||||
}
|
|
||||||
|
|
||||||
public DeviceUpdateEvent(DateTime value, DateTime time) {
|
|
||||||
this.GetDate = value;
|
|
||||||
this.UpdateTime = time;
|
|
||||||
}
|
|
||||||
|
|
||||||
public DeviceUpdateEvent(Tuple<String, String, Single> value, DateTime time) {
|
|
||||||
this.GetStringStringSingleTuple = value;
|
|
||||||
this.UpdateTime = time;
|
|
||||||
}
|
|
||||||
public DeviceUpdateEvent(Tuple<String, String, Single, Single, Single, Boolean> value, DateTime time) {
|
|
||||||
this.GetStringStringSingleSingleSingleSingleBooleanTuple = value;
|
|
||||||
this.UpdateTime = time;
|
|
||||||
}
|
|
||||||
|
|
||||||
public DeviceUpdateEvent(Tuple<Int32, Int32> value, DateTime time) {
|
|
||||||
this.GetIntegerTuple = value;
|
|
||||||
this.UpdateTime = time;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Single GetSingle { get; }
|
|
||||||
public DateTime GetDate { get; }
|
|
||||||
public Tuple<String, String, Single> GetStringStringSingleTuple { get; }
|
|
||||||
public Tuple<String, String, Single, Single, Single, Boolean> GetStringStringSingleSingleSingleSingleBooleanTuple { get; }
|
|
||||||
public DateTime UpdateTime { get; }
|
public DateTime UpdateTime { get; }
|
||||||
public Boolean GetBoolean { get; }
|
public Object Parent { get; private set; }
|
||||||
public Tuple<Int32,Int32> GetIntegerTuple { get; }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,11 +1,8 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Runtime.Serialization;
|
using System.Runtime.Serialization;
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace BlubbFish.IoT.Zway.Exceptions {
|
namespace BlubbFish.IoT.Zway.Exceptions {
|
||||||
|
[Serializable]
|
||||||
public class ConnectionException : Exception {
|
public class ConnectionException : Exception {
|
||||||
public ConnectionException() { }
|
public ConnectionException() { }
|
||||||
public ConnectionException(String message) : base(message) { }
|
public ConnectionException(String message) : base(message) { }
|
||||||
|
|||||||
@@ -0,0 +1,247 @@
|
|||||||
|
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,
|
||||||
|
SwitchAll = 39,
|
||||||
|
SceneActivation = 43,
|
||||||
|
SwitchColor = 51,
|
||||||
|
MeterPulse = 53,
|
||||||
|
CRC16 = 86,
|
||||||
|
AssociationGroupInformation = 89,
|
||||||
|
DeviceResetLocally = 90,
|
||||||
|
ZWavePlusInfo = 94,
|
||||||
|
MultiChannel = 96,
|
||||||
|
DoorLock = 98,
|
||||||
|
ManufacturerSpecific = 114,
|
||||||
|
PowerLevel = 115,
|
||||||
|
Protection = 117,
|
||||||
|
NodeNaming = 119,
|
||||||
|
FirmwareUpdate = 122,
|
||||||
|
Association = 133,
|
||||||
|
Version = 134,
|
||||||
|
Proprietary = 136,
|
||||||
|
MultiChannelAssociation = 142,
|
||||||
|
MultiCmd = 143,
|
||||||
|
Security = 152,
|
||||||
|
AlarmSensor = 156 //
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum Classes : Int32 {
|
||||||
|
SwitchBinary = 37,
|
||||||
|
SwitchMultilevel = 38,
|
||||||
|
SceneControllerConf = 45,
|
||||||
|
SensorBinary = 48,
|
||||||
|
SensorMultilevel = 49,
|
||||||
|
Meter = 50,
|
||||||
|
ThermostatMode = 64,
|
||||||
|
ThermostatSetPoint = 67,
|
||||||
|
CentralScene = 91,
|
||||||
|
Configuration = 112,
|
||||||
|
Alarm = 113,
|
||||||
|
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;
|
||||||
|
Boolean pollonce = false;
|
||||||
|
foreach (KeyValuePair<Int32, ACommandClass> item in this.Sub) {
|
||||||
|
if (item.Value.Polling) {
|
||||||
|
poll = true;
|
||||||
|
}
|
||||||
|
if(item.Value.PollOnce) {
|
||||||
|
pollonce = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (poll || pollonce) {
|
||||||
|
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(Double value1, Double value2) {
|
||||||
|
this.http.GetVoid("ZWave.zway/Run/devices[" + this.DeviceId + "].instances[" + this.Instance + "].commandClasses[" + ((Int32)this.Commandclass).ToString() + "].Set(" + value1 + "," + value2 + ")");
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void SetTriple(Double v1, Double v2, Double v3) {
|
||||||
|
this.http.GetVoid("ZWave.zway/Run/devices[" + this.DeviceId + "].instances[" + this.Instance + "].commandClasses[" + ((Int32)this.Commandclass).ToString() + "].Set(" + v1 + "," + v2 + "," + v3 + ")");
|
||||||
|
}
|
||||||
|
|
||||||
|
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("LastUpdate", this.LastUpdate.ToString());
|
||||||
|
json.Add("Name", this.Name);
|
||||||
|
json.Add("Commandclass", 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -10,7 +10,7 @@ using System.Runtime.InteropServices;
|
|||||||
[assembly: AssemblyConfiguration("")]
|
[assembly: AssemblyConfiguration("")]
|
||||||
[assembly: AssemblyCompany("")]
|
[assembly: AssemblyCompany("")]
|
||||||
[assembly: AssemblyProduct("Zway")]
|
[assembly: AssemblyProduct("Zway")]
|
||||||
[assembly: AssemblyCopyright("Copyright © 2017")]
|
[assembly: AssemblyCopyright("Copyright © 2017 - 25.12.2017")]
|
||||||
[assembly: AssemblyTrademark("")]
|
[assembly: AssemblyTrademark("")]
|
||||||
[assembly: AssemblyCulture("")]
|
[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,
|
// 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.5.3")]
|
||||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
[assembly: AssemblyFileVersion("1.3.5.3")]
|
||||||
|
|||||||
+9
-2
@@ -43,16 +43,22 @@
|
|||||||
<Reference Include="System.Xml" />
|
<Reference Include="System.Xml" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Compile Include="Devices\CommandClasses\Alarm.cs" />
|
||||||
<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\SceneControllerConfSub.cs" />
|
||||||
|
<Compile Include="Devices\CommandClasses\CommandClassSubs\SensorBinarySub.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\Indicator.cs" />
|
<Compile Include="Devices\CommandClasses\Indicator.cs" />
|
||||||
<Compile Include="Devices\CommandClasses\Meter.cs" />
|
<Compile Include="Devices\CommandClasses\Meter.cs" />
|
||||||
<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\SceneControllerConf.cs" />
|
||||||
|
<Compile Include="Devices\CommandClasses\SensorBinary.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\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" />
|
||||||
@@ -62,6 +68,7 @@
|
|||||||
<Compile Include="Devices\CommandClasses\ThermostatSetPoint.cs" />
|
<Compile Include="Devices\CommandClasses\ThermostatSetPoint.cs" />
|
||||||
<Compile Include="Events\DeviceUpdateEvent.cs" />
|
<Compile Include="Events\DeviceUpdateEvent.cs" />
|
||||||
<Compile Include="Exceptions\ZwayExceptions.cs" />
|
<Compile Include="Exceptions\ZwayExceptions.cs" />
|
||||||
|
<Compile Include="lib\Helper.cs" />
|
||||||
<Compile Include="lib\HttpClient.cs" />
|
<Compile Include="lib\HttpClient.cs" />
|
||||||
<Compile Include="ZwayController.cs" />
|
<Compile Include="ZwayController.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
|
|||||||
+61
-28
@@ -1,28 +1,38 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Collections.ObjectModel;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
|
using System.Reflection;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using BlubbFish.IoT.Zway.Devices;
|
using BlubbFish.IoT.Zway.Devices;
|
||||||
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;
|
||||||
|
|
||||||
namespace BlubbFish.IoT.Zway {
|
namespace BlubbFish.IoT.Zway {
|
||||||
public class ZwayController : IDisposable {
|
public class ZwayController : IDisposable {
|
||||||
private HttpConnection http;
|
private HttpConnection http;
|
||||||
private Dictionary<Int32, Device> devices = new Dictionary<Int32, Device>();
|
|
||||||
private Thread updatethread;
|
private Thread updatethread;
|
||||||
private Thread pollthread;
|
private Thread pollthread;
|
||||||
|
public static ReadOnlyDictionary<String, String> namelist;
|
||||||
|
private Boolean polling;
|
||||||
|
|
||||||
public delegate void DataUpdate(Object sender, DeviceUpdateEvent e);
|
public delegate void DataUpdate(Object sender, DeviceUpdateEvent e);
|
||||||
public event DataUpdate Update;
|
public event DataUpdate Update;
|
||||||
|
|
||||||
public ZwayController(String server, String user, String pass) {
|
public ReadOnlyDictionary<Int32, Device> Devices { get; private set; }
|
||||||
|
|
||||||
|
public ZwayController(String server, String user, String pass, Dictionary<String, String> names, Boolean enablePoll = true) {
|
||||||
|
namelist = new ReadOnlyDictionary<String, String>(names);
|
||||||
|
this.polling = enablePoll;
|
||||||
this.Connect(server, user, pass);
|
this.Connect(server, user, pass);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ZwayController(Dictionary<String, String> settings) {
|
public ZwayController(Dictionary<String, String> settings, Dictionary<String, String> names, Boolean enablePoll = true) {
|
||||||
|
namelist = new ReadOnlyDictionary<String, String>(names);
|
||||||
|
this.polling = enablePoll;
|
||||||
this.Connect(settings["server"], settings["user"], settings["pass"]);
|
this.Connect(settings["server"], settings["user"], settings["pass"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -34,12 +44,12 @@ namespace BlubbFish.IoT.Zway {
|
|||||||
CultureInfo.DefaultThreadCurrentUICulture = info;
|
CultureInfo.DefaultThreadCurrentUICulture = info;
|
||||||
Thread.CurrentThread.CurrentCulture = info;
|
Thread.CurrentThread.CurrentCulture = info;
|
||||||
Thread.CurrentThread.CurrentUICulture = info;
|
Thread.CurrentThread.CurrentUICulture = info;
|
||||||
this.ParseNamespace(this.http.GetJson("ZWaveAPI/Run/devices"));
|
this.CreateDevices(this.http.GetJson("ZWaveAPI/Run/devices"));
|
||||||
this.updatethread = new Thread(this.Updater);
|
this.updatethread = new Thread(this.Updater);
|
||||||
this.updatethread.Start();
|
this.updatethread.Start();
|
||||||
this.pollthread = new Thread(this.Poll);
|
this.pollthread = new Thread(this.Poll);
|
||||||
this.pollthread.Start();
|
this.pollthread.Start();
|
||||||
foreach (KeyValuePair<Int32, Device> item in this.devices) {
|
foreach (KeyValuePair<Int32, Device> item in this.Devices) {
|
||||||
item.Value.Update += this.DeviceUpdate;
|
item.Value.Update += this.DeviceUpdate;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -56,13 +66,38 @@ namespace BlubbFish.IoT.Zway {
|
|||||||
Thread.CurrentThread.CurrentCulture = info;
|
Thread.CurrentThread.CurrentCulture = info;
|
||||||
Thread.CurrentThread.CurrentUICulture = info;
|
Thread.CurrentThread.CurrentUICulture = info;
|
||||||
while(true) {
|
while(true) {
|
||||||
foreach (KeyValuePair<Int32, Device> item in this.devices) {
|
foreach (KeyValuePair<Int32, Device> item in this.Devices) {
|
||||||
item.Value.Poll();
|
item.Value.Poll();
|
||||||
}
|
}
|
||||||
Thread.Sleep(1000);
|
Thread.Sleep(1000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ACommandClass GetCommandClass(String id) {
|
||||||
|
String[] addr = id.Split('-');
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ACommandClass GetCommandClass(Int32 deviceid, Int32 instanceid, ACommandClass.Classes classid, Int32 subcid = -1) {
|
||||||
|
if(this.Devices.ContainsKey(deviceid) && this.Devices[deviceid].Instances.ContainsKey(instanceid) && this.Devices[deviceid].Instances[instanceid].CommandClasses.ContainsKey(classid)) {
|
||||||
|
ACommandClass commandclass = this.Devices[deviceid].Instances[instanceid].CommandClasses[classid];
|
||||||
|
if(subcid == -1) {
|
||||||
|
return commandclass;
|
||||||
|
}
|
||||||
|
if (commandclass != null) {
|
||||||
|
if(commandclass.HasSub) {
|
||||||
|
if(commandclass.Sub.ContainsKey(subcid)) {
|
||||||
|
return commandclass.Sub[subcid];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
private void Updater() {
|
private void Updater() {
|
||||||
CultureInfo info = new CultureInfo("de-DE");
|
CultureInfo info = new CultureInfo("de-DE");
|
||||||
info.NumberFormat.NumberDecimalSeparator = ".";
|
info.NumberFormat.NumberDecimalSeparator = ".";
|
||||||
@@ -78,9 +113,9 @@ 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);
|
||||||
}
|
}
|
||||||
} /*else {
|
} /*else {
|
||||||
if(item.StartsWith("controller.")) { }
|
if(item.StartsWith("controller.")) { }
|
||||||
@@ -95,8 +130,8 @@ namespace BlubbFish.IoT.Zway {
|
|||||||
match = new Regex("^devices\\.([0-9]+)\\.(data.*)", RegexOptions.IgnoreCase).Match(item);
|
match = new Regex("^devices\\.([0-9]+)\\.(data.*)", RegexOptions.IgnoreCase).Match(item);
|
||||||
if(match.Success) {
|
if(match.Success) {
|
||||||
Int32 deviceid = Int32.Parse(match.Groups[1].Value);
|
Int32 deviceid = Int32.Parse(match.Groups[1].Value);
|
||||||
if (this.devices.ContainsKey(deviceid)) {
|
if (this.Devices.ContainsKey(deviceid)) {
|
||||||
this.devices[deviceid].SetUpdate(notifications[item], match);
|
this.Devices[deviceid].SetUpdate(notifications[item], match);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -104,26 +139,24 @@ namespace BlubbFish.IoT.Zway {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ParseNamespace(JsonData json) {
|
private void CreateDevices(JsonData json) {
|
||||||
|
Dictionary<Int32, Device> devices = new Dictionary<Int32, Device>();
|
||||||
foreach (String deviceid in json.Keys) {
|
foreach (String deviceid in json.Keys) {
|
||||||
this.CreateDevices(Int32.Parse(deviceid), json[deviceid]);
|
Device d = Device.CreateDevice(json[deviceid], new Tuple<Int32>(Int32.Parse(deviceid)), this.http, this.polling);
|
||||||
|
if (d != null) {
|
||||||
|
devices.Add(Int32.Parse(deviceid), d);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
this.Devices = new ReadOnlyDictionary<Int32, Device>(devices);
|
||||||
|
}
|
||||||
|
|
||||||
private void CreateDevices(Int32 deviceid, JsonData json) {
|
public Dictionary<String, ACommandClass> GetCommandClasses(ACommandClass.Classes classes) {
|
||||||
Device d = Device.CreateDevice(json, new Tuple<Int32>(deviceid), this.http);
|
Dictionary<String, ACommandClass> ret = new Dictionary<String, ACommandClass>();
|
||||||
if(d != null) {
|
foreach (KeyValuePair<Int32, Device> device in this.Devices) {
|
||||||
this.devices.Add(deviceid, d);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<T> GetCommandClasses<T>() {
|
|
||||||
List<T> ret = new List<T>();
|
|
||||||
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -142,7 +175,7 @@ namespace BlubbFish.IoT.Zway {
|
|||||||
}
|
}
|
||||||
this.updatethread = null;
|
this.updatethread = null;
|
||||||
this.pollthread = null;
|
this.pollthread = null;
|
||||||
this.devices.Clear();
|
this.Devices = null;
|
||||||
this.disposedValue = true;
|
this.disposedValue = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -151,7 +184,7 @@ namespace BlubbFish.IoT.Zway {
|
|||||||
Dispose(false);
|
Dispose(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void IDisposable.Dispose() {
|
public void Dispose() {
|
||||||
Dispose(true);
|
Dispose(true);
|
||||||
GC.SuppressFinalize(this);
|
GC.SuppressFinalize(this);
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,15 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace BlubbFish.IoT.Zway.lib {
|
||||||
|
class Helper {
|
||||||
|
internal static void WriteError(String text) {
|
||||||
|
Console.ForegroundColor = ConsoleColor.Red;
|
||||||
|
Console.Error.WriteLine("ERROR: "+text);
|
||||||
|
Console.ResetColor();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,11 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Runtime.CompilerServices;
|
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
|
||||||
using LitJson;
|
using LitJson;
|
||||||
|
|
||||||
namespace BlubbFish.IoT.Zway.lib {
|
namespace BlubbFish.IoT.Zway.lib {
|
||||||
@@ -26,6 +22,9 @@ namespace BlubbFish.IoT.Zway.lib {
|
|||||||
|
|
||||||
internal JsonData GetJson(String v) {
|
internal JsonData GetJson(String v) {
|
||||||
String text = this.GetString(v);
|
String text = this.GetString(v);
|
||||||
|
if(text == null) {
|
||||||
|
return new JsonData();
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
return JsonMapper.ToObject(text);
|
return JsonMapper.ToObject(text);
|
||||||
} catch(Exception) {
|
} catch(Exception) {
|
||||||
@@ -55,8 +54,9 @@ namespace BlubbFish.IoT.Zway.lib {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Console.Error.WriteLine("Konnte keine Verbindung zum Razzbery Server herstellen: " + e.Message);
|
Helper.WriteError("Konnte keine Verbindung zum Razzbery Server herstellen. Resource: \"" + this.server + v + "\" Fehler: " + e.Message);
|
||||||
throw new Exceptions.ConnectionException("Konnte keine Verbindung zum Razzbery Server herstellen: " + e.Message);
|
return null;
|
||||||
|
//throw new Exceptions.ConnectionException("Konnte keine Verbindung zum Razzbery Server herstellen: " + e.Message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
|
|||||||
Reference in New Issue
Block a user