54 lines
2.1 KiB
C#
54 lines
2.1 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 {
|
|
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 }
|
|
};
|
|
}
|
|
}
|
|
} |