Zway/Zway/Devices/CommandClasses/CommandClassSubs/SceneControllerConfSub.cs

68 lines
2.5 KiB
C#

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Text.RegularExpressions;
using BlubbFish.IoT.Zway.Events;
using BlubbFish.IoT.Zway.Interfaces;
using BlubbFish.IoT.Zway.lib.Zway;
using BlubbFish.Utils.IoT.Interfaces.Language;
using LitJson;
namespace BlubbFish.IoT.Zway.Devices.CommandClasses.CommandClassSubs {
public class Scenecontrollerconfsub : ACommandClass {
public override event UpdatedValue Update;
#region Properties
/// <summary>
///
/// </summary>
public Int32 Scene { get; private set; }
/// <summary>
///
/// </summary>
public Int32 Duration { get; private set; }
#endregion
#region Constructor
public Scenecontrollerconfsub(JsonData json, (Int32 device, Int32 instance, Classes commandclass, Int32 sensor) id, HttpConnection http, Boolean polling, (String device, ReadOnlyDictionary<String, String> descriptions) name) : base(id, http, polling, name) {
this.IsSub = true;
this.InitComplex(json);
}
private void InitComplex(JsonData json) {
if (json.Keys.Contains("scene") && json["scene"].Keys.Contains("value") &&
json.Keys.Contains("duration") && json["duration"].Keys.Contains("value")) {
this.Scene = Int32.Parse(json["scene"]["value"].ToString());
this.Duration = Int32.Parse(json["duration"]["value"].ToString());
}
}
#endregion
#region ACommandClass
public override String ToString() => "SceneControllerConf " + this.Name + " [" + this.Id + "]: " + this.Scene + " " + this.Duration;
public override Dictionary<String, Object> ToDictionary() => new Dictionary<String, Object> {
{ "Scene", this.Scene },
{ "Duration", this.Duration }
};
internal override void SetUpdate(JsonData json, Match match) {
if (json.Keys.Contains("scene") && json["scene"].Keys.Contains("value") &&
json.Keys.Contains("duration") && json["duration"].Keys.Contains("value") &&
this.CheckSetUpdateTime(json)) {
this.Scene = Int32.Parse(json["scene"]["value"].ToString());
this.Duration = Int32.Parse(json["duration"]["value"].ToString());
this.Update?.Invoke(this, new DeviceUpdateEvent(new Tuple<Int32, Int32>(this.Scene, this.Duration), this.LastUpdate, this));
}
}
internal override void Poll() => this.PollSub();
#endregion
#region ISenml
protected override List<Senml> ToSenmlList() => new List<Senml>() { };
#endregion
}
}