53 lines
1.8 KiB
C#
53 lines
1.8 KiB
C#
using System;
|
|
using System.Text.RegularExpressions;
|
|
using BlubbFish.IoT.Zway.Interfaces;
|
|
using BlubbFish.IoT.Zway.lib;
|
|
using LitJson;
|
|
|
|
namespace BlubbFish.IoT.Zway.Devices {
|
|
public abstract class CommandClassSub : ICommandClass {
|
|
protected HttpConnection http;
|
|
|
|
public abstract event UpdatedValue Update;
|
|
public String Id { get; }
|
|
public Int32 DeviceId { get; }
|
|
public Int32 Instance { get; }
|
|
public Int32 Commandclass { get; }
|
|
public Int32 SensorId { get; }
|
|
public String Name { get; }
|
|
public DateTime LastUpdate { get; private set; }
|
|
public Boolean Polling { get; set; }
|
|
|
|
protected CommandClassSub(JsonData json, Tuple<Int32, Int32, Int32, Int32> id, HttpConnection http, Boolean polling) {
|
|
this.DeviceId = id.Item1;
|
|
this.Instance = id.Item2;
|
|
this.Commandclass = id.Item3;
|
|
this.SensorId = id.Item4;
|
|
this.http = http;
|
|
this.LastUpdate = DateTime.Now;
|
|
this.Polling = polling;
|
|
this.Id = this.DeviceId + "-" + this.Instance + "-" + this.Commandclass + "-" + this.SensorId;
|
|
if (ZwayController.namelist.ContainsKey(this.Id)) {
|
|
this.Name = ZwayController.namelist[this.Id];
|
|
}
|
|
}
|
|
|
|
protected Boolean CheckSetUpdateTime(JsonData json) {
|
|
if (json.Keys.Contains("updateTime") && (json["updateTime"].IsInt || json["updateTime"].IsLong)) {
|
|
DateTime newdate = DateTimeOffset.FromUnixTimeSeconds(Int64.Parse(json["updateTime"].ToString())).ToLocalTime().DateTime;
|
|
if (newdate > this.LastUpdate) {
|
|
this.LastUpdate = newdate;
|
|
return true;
|
|
} else {
|
|
return false;
|
|
}
|
|
} else {
|
|
return true;
|
|
}
|
|
}
|
|
internal abstract void SetUpdate(JsonData json, Match match);
|
|
|
|
internal abstract void Poll();
|
|
}
|
|
}
|