71 lines
2.7 KiB
C#
71 lines
2.7 KiB
C#
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.Zway;
|
|
using BlubbFish.Utils;
|
|
using BlubbFish.Utils.IoT.Interfaces.Language;
|
|
|
|
using LitJson;
|
|
|
|
namespace BlubbFish.IoT.Zway.Devices.CommandClasses {
|
|
/// <summary>
|
|
/// 48 = SensorBinary
|
|
/// </summary>
|
|
public class Sensorbinary : ACommandClass {
|
|
public override event UpdatedValue Update;
|
|
|
|
#region Constructor
|
|
public Sensorbinary(JsonData json, (Int32 device, Int32 instance, Classes commandclass) id, HttpConnection http, Boolean polling, (String device, ReadOnlyDictionary<String, String> descriptions) name) : base(id, http, polling, name) {
|
|
this.HasSub = true;
|
|
this.InitComplex(json, name);
|
|
foreach (KeyValuePair<Int32, ACommandClass> item in this.Sub) {
|
|
item.Value.Update += this.DeviceUpdate;
|
|
}
|
|
}
|
|
|
|
private void InitComplex(JsonData json, (String device, ReadOnlyDictionary<String, String> descriptions) name) {
|
|
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], (this.DeviceId, this.Instance, this.Commandclass, subid), this.http, this.Polling, name));
|
|
}
|
|
}
|
|
this.Sub = new ReadOnlyDictionary<Int32, ACommandClass>(subs);
|
|
}
|
|
}
|
|
|
|
private void DeviceUpdate(Object sender, DeviceUpdateEvent e) => this.Update?.Invoke(this, e);
|
|
#endregion
|
|
|
|
#region ACommandClass
|
|
internal override void SetUpdate(JsonData json, Match match) {
|
|
if (match.Groups[4].Value.StartsWith(".data.")) {
|
|
Int32 subid = Int32.Parse(match.Groups[5].Value);
|
|
if (this.Sub.ContainsKey(subid)) {
|
|
this.Sub[subid].SetUpdate(json, match);
|
|
}
|
|
} else {
|
|
Helper.WriteError("Kenne in " + this.Name + " [" + this.Id + "] " + match.Groups[4].Value + " nicht!");
|
|
}
|
|
}
|
|
|
|
internal override void Poll() => this.PollSubGlobal();
|
|
|
|
public override Dictionary<String, Object> ToDictionary() => this.ToDictionarySub();
|
|
#endregion
|
|
|
|
#region ISenml
|
|
protected override List<Senml> ToSenmlList() => this.ToSenmlListSub();
|
|
#endregion
|
|
}
|
|
}
|