[DW] Sensorbinary hinzugefügt

This commit is contained in:
BlubbFish 2017-12-21 15:52:05 +00:00
parent 0834e09178
commit f406b09ffa
2 changed files with 114 additions and 0 deletions

View File

@ -0,0 +1,54 @@
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 Level { get; private set; }
public Sensorbinarysub(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);
}
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.Level = (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.Level = (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));
}
}
public override String ToString() {
return "SensorBinary " + this.Name + " [" + this.Id + "]: " + this.Type + " " + this.Level.ToString();
}
internal override void Poll() => this.PollNone();
public override Dictionary<String, Object> ToDictionary() {
return new Dictionary<String, Object> {
{ "Level", this.Level },
{ "Type", this.Type }
};
}
}
}

View File

@ -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();
}
}