79 lines
2.8 KiB
C#
79 lines
2.8 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 {
|
|
/// <summary>
|
|
/// 135 = Indicator
|
|
/// </summary>
|
|
class Alarm : ACommandClass {
|
|
public override event UpdatedValue Update;
|
|
|
|
#region Properties
|
|
/// <summary>
|
|
/// Unklar
|
|
/// </summary>
|
|
public Int32 Level { get; private set; }
|
|
/// <summary>
|
|
/// unklar
|
|
/// </summary>
|
|
public Int32 AlarmType { get; private set; }
|
|
#endregion
|
|
|
|
#region Constructor
|
|
public Alarm(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("V1event") &&
|
|
json["data"]["V1event"].Keys.Contains("alarmType") && json["data"]["V1event"]["alarmType"].Keys.Contains("value") &&
|
|
json["data"]["V1event"].Keys.Contains("level") && json["data"]["V1event"]["level"].Keys.Contains("value")) {
|
|
this.AlarmType = Int32.Parse(json["data"]["V1event"]["alarmType"]["value"].ToString());
|
|
this.Level = Int32.Parse(json["data"]["V1event"]["level"]["value"].ToString());
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region ACommandClass
|
|
public override String ToString() {
|
|
return "Alarm " + this.Name + " [" + this.Id + "]: " + this.AlarmType + " " + this.Level;
|
|
}
|
|
|
|
public override Dictionary<String, Object> ToDictionary() {
|
|
return new Dictionary<String, Object> {
|
|
{ "AlarmType", this.AlarmType },
|
|
{ "Level", this.Level },
|
|
};
|
|
}
|
|
|
|
internal override void SetUpdate(JsonData json, Match match) {
|
|
if (match.Groups[4].Value == ".data.V1event") {
|
|
if (json.Keys.Contains("alarmType") && json["alarmType"].Keys.Contains("value") &&
|
|
json.Keys.Contains("level") && json["level"].Keys.Contains("value") &&
|
|
this.CheckSetUpdateTime(json)) {
|
|
this.AlarmType = Int32.Parse(json["alarmType"]["value"].ToString());
|
|
this.Level = Int32.Parse(json["level"]["value"].ToString());
|
|
this.Update?.Invoke(this, new DeviceUpdateEvent(new Tuple<Int32, Int32>(this.AlarmType, this.Level), this.LastUpdate, this));
|
|
}
|
|
} else {
|
|
Helper.WriteError("Kenne in " + this.Name + " [" + this.Id + "] " + match.Groups[4].Value + " nicht!");
|
|
}
|
|
}
|
|
|
|
internal override void Poll() => this.PollNone();
|
|
#endregion
|
|
|
|
#region ISenml
|
|
protected override List<Senml> ToSenmlList() {
|
|
return new List<Senml>() { };
|
|
}
|
|
#endregion
|
|
}
|
|
}
|