Files
Zway/Zway/Devices/CommandClasses/CommandClassSubs/Configurationsub.cs
T

88 lines
2.9 KiB
C#

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 BlubbFish.Utils.IoT.Interfaces.Language;
using LitJson;
namespace BlubbFish.IoT.Zway.Devices.CommandClasses.CommandClassSubs {
class Configurationsub : ACommandClass {
public override event UpdatedValue Update;
#region Properties
private Int64 _level;
/// <summary>
/// Value of the Configuration Item
/// </summary>
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);
}
}
}
/// <summary>
/// Size of the Configuration slot
/// </summary>
public Int32 Size { get; private set; }
#endregion
#region Constructor
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());
}
}
#endregion
#region ACommandClass
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 },
};
}
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));
}
}
internal override void Poll() => this.PollSub();
#endregion
#region ISenml
protected override List<Senml> ToSenmlList() {
return new List<Senml>() { };
}
#endregion
}
}