Files
Zway/Zway/Devices/CommandClasses/CommandClassSubs/MeterSub.cs
T
2017-12-17 21:53:16 +00:00

61 lines
2.5 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 Metersub : ACommandClass {
public override event UpdatedValue Update;
public String Type { get; private set; }
public Double Level { get; private set; }
public String Scale { get; private set; }
public Metersub(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("val") &&
json["val"].Keys.Contains("value") &&
json.Keys.Contains("scaleString") &&
json["scaleString"].Keys.Contains("value")) {
this.Type = json["sensorTypeString"]["value"].ToString();
this.Level = Double.Parse(json["val"]["value"].ToString());
this.Scale = json["scaleString"]["value"].ToString();
}
}
internal override void SetUpdate(JsonData json, Match match) {
if (json.Keys.Contains("val") && json["val"].Keys.Contains("value") &&
json.Keys.Contains("sensorTypeString") && json["sensorTypeString"].Keys.Contains("value") &&
json.Keys.Contains("scaleString") && json["scaleString"].Keys.Contains("value") &&
this.CheckSetUpdateTime(json)) {
this.Level = Double.Parse(json["val"]["value"].ToString());
this.Type = json["sensorTypeString"]["value"].ToString();
this.Scale = json["scaleString"]["value"].ToString();
this.Update?.Invoke(this, new DeviceUpdateEvent(new Tuple<String, String, Double>(this.Type, this.Scale, this.Level), this.LastUpdate, this));
}
}
public override String ToString() {
return "Meter " + this.Name + " [" + this.Id + "]: " + this.Type + " " + this.Level + "" + this.Scale;
}
internal override void Poll() => this.PollNone();
public override Dictionary<String, Object> ToDictionary() {
return new Dictionary<String, Object> {
{ "level", this.Level },
{ "type", this.Type },
{ "scale", this.Scale },
};
}
}
}