[BF] v1.3.5.3 Change Level to numeric and create State for Bollean values, because telegraf only parse numeric

This commit is contained in:
BlubbFish 2017-12-25 18:11:01 +00:00
parent 1082ee0d2a
commit beea6c1ee0
6 changed files with 70 additions and 39 deletions

View File

@ -11,7 +11,13 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses.CommandClassSubs {
public override event UpdatedValue Update;
public String Type { get; private set; }
public Boolean Level { 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);
@ -23,7 +29,7 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses.CommandClassSubs {
json.Keys.Contains("level") &&
json["level"].Keys.Contains("value")) {
this.Type = json["sensorTypeString"]["value"].ToString();
this.Level = (Boolean)json["level"]["value"];
this.State = (Boolean)json["level"]["value"];
}
}
@ -31,22 +37,23 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses.CommandClassSubs {
if (json.Keys.Contains("level") && json["level"].Keys.Contains("value") &&
json.Keys.Contains("sensorTypeString") && json["sensorTypeString"].Keys.Contains("value") &&
this.CheckSetUpdateTime(json)) {
this.Level = (Boolean)json["level"]["value"];
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.Level), this.LastUpdate, this));
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.Level.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> {
{ "Level", this.Level },
{ "Type", this.Type }
{ "State", this.State },
{ "Type", this.Type },
{ "Level", this.Level }
};
}
}

View File

@ -11,33 +11,42 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses {
/// 135 = Indicator
/// </summary>
class Indicator : ACommandClass {
private Boolean _level;
private Boolean _state;
public override event UpdatedValue Update;
public Boolean Level {
public Boolean State {
get {
return this._level;
return this._state;
}
set {
this.SetInt(value ? 255 : 0);
}
}
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);
}
private void InitComplex(JsonData json) {
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) {
if(match.Groups[4].Value == ".data.stat") {
if (json.Keys.Contains("value") && this.CheckSetUpdateTime(json)) {
this._level = Int32.Parse(json["value"].ToString()) == 255;
this.Update?.Invoke(this, new DeviceUpdateEvent(this.Level, this.LastUpdate, this));
this._state = Int32.Parse(json["value"].ToString()) == 255;
this.Update?.Invoke(this, new DeviceUpdateEvent(this.State, this.LastUpdate, this));
}
} else {
Helper.WriteError("Kenne in " + this.Name + " [" + this.Id + "] " + match.Groups[4].Value + " nicht!");
@ -45,12 +54,13 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses {
}
public override String ToString() {
return "Indicator " + this.Name + " [" + this.Id + "]: " + this.Level;
return "Indicator " + this.Name + " [" + this.Id + "]: " + this.State;
}
public override Dictionary<String, Object> ToDictionary() {
return new Dictionary<String, Object> {
{ "Level", this.Level },
{ "State", this.State },
{ "Level", this.Level }
};
}
}

View File

@ -11,13 +11,22 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses {
/// 37 = SwitchBinary
/// </summary>
public class Switchbinary : ACommandClass {
private Boolean _level;
private Boolean _state;
public override event UpdatedValue Update;
public Boolean Level {
public Int32 Level {
get {
return this._level;
return (this.State) ? 1 : 0;
}
set {
this.State = (value == 1);
}
}
public Boolean State {
get {
return this._state;
}
set {
this.SetInt(value ? 255 : 0);
@ -31,8 +40,8 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses {
internal override void SetUpdate(JsonData json, Match match) {
if(match.Groups[4].Value == ".data.level") {
if (json.Keys.Contains("value") && json["value"].IsBoolean && this.CheckSetUpdateTime(json)) {
this._level = (Boolean)json["value"];
this.Update?.Invoke(this, new DeviceUpdateEvent(this.Level, this.LastUpdate, this));
this._state = (Boolean)json["value"];
this.Update?.Invoke(this, new DeviceUpdateEvent(this.State, this.LastUpdate, this));
}
} else {
Helper.WriteError("Kenne in " + this.Name + " [" + this.Id + "] " + match.Groups[4].Value + " nicht!");
@ -41,16 +50,17 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses {
private void InitComplex(JsonData json) {
if (json.Keys.Contains("data") && json["data"].Keys.Contains("level") && json["data"]["level"].Keys.Contains("value") && json["data"]["level"]["value"].IsBoolean) {
this._level = (Boolean)json["data"]["level"]["value"];
this._state = (Boolean)json["data"]["level"]["value"];
}
}
public override String ToString() {
return "SwitchBinary " + this.Name + " [" + this.Id + "]: " + 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 }
};
}

View File

@ -34,9 +34,11 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses {
}
public Int32 WakeupMin { get; private set; }
public Int32 WakeupMax { get; private set; }
public Boolean HasMinMax { 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 Boolean HasDefault { 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 LastSleep { get; private set; }
@ -53,19 +55,19 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses {
if (data.Keys.Contains("nodeId") && data["nodeId"].Keys.Contains("value")) {
this._againstNode = Int32.Parse(data["nodeId"]["value"].ToString());
}
this.HasMinMax = false;
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.HasMinMax = true;
this.HasMinMaxState = true;
}
if (data.Keys.Contains("max") && data["max"].Keys.Contains("value") && data["max"]["value"] != null) {
this.WakeupMax = Int32.Parse(data["max"]["value"].ToString());
this.HasMinMax = true;
this.HasMinMaxState = true;
}
this.HasDefault = false;
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.HasDefault = true;
this.HasDefaultState = true;
}
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();
@ -97,22 +99,22 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses {
this._againstNode = Int32.Parse(json["nodeId"]["value"].ToString());
success = true;
}
this.HasMinMax = false;
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());
success = true;
this.HasMinMax = true;
this.HasMinMaxState = true;
}
if (json.Keys.Contains("max") && json["max"].Keys.Contains("value") && json["max"]["value"] != null) {
this.WakeupMax = Int32.Parse(json["max"]["value"].ToString());
success = true;
this.HasMinMax = true;
this.HasMinMaxState = true;
}
this.HasDefault = false;
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());
success = true;
this.HasDefault = true;
this.HasDefaultState = true;
}
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();
@ -140,9 +142,11 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses {
{ "AgainstNode", this.AgainstNode },
{ "WakeupMin", this.WakeupMin },
{ "WakeupMax", this.WakeupMax },
{ "HasMinMax", this.HasMinMax },
{ "HasMinMaxState", this.HasMinMaxState },
{ "HasMinMaxLevel", this.HasMinMaxLevel },
{ "WakeupDefault", this.WakeupDefault },
{ "HasDefault", this.HasDefault },
{ "HasDefaultState", this.HasDefaultState },
{ "HasDefaultLevel", this.HasDefaultLevel },
{ "LastWakeup", this.LastWakeup.ToString() },
{ "LastSleep", this.LastSleep.ToString() }
};

View File

@ -10,7 +10,7 @@ using System.Runtime.InteropServices;
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Zway")]
[assembly: AssemblyCopyright("Copyright © 2017 - 24.12.2017")]
[assembly: AssemblyCopyright("Copyright © 2017 - 25.12.2017")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
// Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden,
// indem Sie "*" wie unten gezeigt eingeben:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.3.5.2")]
[assembly: AssemblyFileVersion("1.3.5.2")]
[assembly: AssemblyVersion("1.3.5.3")]
[assembly: AssemblyFileVersion("1.3.5.3")]

Binary file not shown.