69 lines
2.9 KiB
C#
69 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 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.http.GetVoid("ZWave.zway/Run/devices[" + this.DeviceId + "].instances[" + this.Instance + "].commandClasses[" + this.Commandclass + "].Set(" + this.SensorId + "," + value16 + ",1)");
|
|
} else if(this.Size == 2 && Int32.TryParse(value.ToString(), out Int32 value32)) {
|
|
this.http.GetVoid("ZWave.zway/Run/devices[" + this.DeviceId + "].instances[" + this.Instance + "].commandClasses[" + this.Commandclass + "].Set(" + this.SensorId + "," + value32 + ",2)");
|
|
} else if(this.Size == 4) {
|
|
this.http.GetVoid("ZWave.zway/Run/devices[" + this.DeviceId + "].instances[" + this.Instance + "].commandClasses[" + this.Commandclass + "].Set(" + 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 },
|
|
};
|
|
}
|
|
}
|
|
} |