[NF] Create Senml Messages for Linksmart

This commit is contained in:
2018-05-03 14:35:02 +00:00
parent b5e0c70b1e
commit 317ae9b682
29 changed files with 748 additions and 341 deletions
+63 -41
View File
@@ -5,6 +5,7 @@ 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 {
@@ -14,15 +15,72 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses {
public class Centralscene : ACommandClass {
public override event UpdatedValue Update;
#region Properties
/// <summary>
/// Combination of Scenes and Modes
/// </summary>
public ReadOnlyDictionary<Int32, ReadOnlyCollection<Int32>> ValidScenesModes { get; private set; }
/// <summary>
/// Current active Senes
/// </summary>
public Int32 Scene { get; private set; }
/// <summary>
/// Current active mode
/// </summary>
public Int32 Key { get; private set; }
#endregion
#region Constructor
public Centralscene(JsonData json, Tuple<Int32, Int32, Classes> id, HttpConnection http, Boolean polling) : base(json, id, http, polling) {
this.ValidScenesModes = new ReadOnlyDictionary<Int32, ReadOnlyCollection<Int32>>(new Dictionary<Int32, ReadOnlyCollection<Int32>>());
this.InitComplex(json);
}
private void InitComplex(JsonData json) {
if (json.Keys.Contains("data")) {
JsonData data = json["data"];
if (data.Keys.Contains("sceneSupportedKeyAttributesMask")) {
Dictionary<Int32, ReadOnlyCollection<Int32>> scenes = new Dictionary<Int32, ReadOnlyCollection<Int32>>();
foreach (String item in data["sceneSupportedKeyAttributesMask"].Keys) {
if (Int32.TryParse(item, out Int32 mode) &&
data["sceneSupportedKeyAttributesMask"][item].Keys.Contains("value") &&
data["sceneSupportedKeyAttributesMask"][item]["value"].IsArray) {
JsonData values = data["sceneSupportedKeyAttributesMask"][item]["value"];
List<Int32> modes = new List<Int32>();
foreach (JsonData value in values) {
modes.Add(Int32.Parse(value.ToString()));
}
scenes.Add(mode, new ReadOnlyCollection<Int32>(modes));
}
}
this.ValidScenesModes = new ReadOnlyDictionary<Int32, ReadOnlyCollection<Int32>>(scenes);
if (data.Keys.Contains("currentScene") &&
data["currentScene"].Keys.Contains("value") &&
data["currentScene"]["value"] != null) {
this.Scene = Int32.Parse(data["currentScene"]["value"].ToString());
}
if (data.Keys.Contains("keyAttribute") &&
data["keyAttribute"].Keys.Contains("value") &&
data["keyAttribute"]["value"] != null) {
this.Key = Int32.Parse(data["keyAttribute"]["value"].ToString());
}
}
}
}
#endregion
#region ACommandClass
public override String ToString() {
return "CentralScene " + this.Name + " [" + this.Id + "]: " + this.Scene + "-" + this.Key;
}
public override Dictionary<String, Object> ToDictionary() {
return new Dictionary<String, Object> {
{ "Scene", this.Scene },
{ "Key", this.Key },
};
}
internal override void SetUpdate(JsonData json, Match match) {
if (match.Groups[4].Value == ".data.currentScene") {
if (json.Keys.Contains("value")) {
@@ -38,49 +96,13 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses {
}
}
private void InitComplex(JsonData json) {
if (json.Keys.Contains("data")) {
JsonData data = json["data"];
if(data.Keys.Contains("sceneSupportedKeyAttributesMask")) {
Dictionary<Int32, ReadOnlyCollection<Int32>> scenes = new Dictionary<Int32, ReadOnlyCollection<Int32>>();
foreach (String item in data["sceneSupportedKeyAttributesMask"].Keys) {
if (Int32.TryParse(item, out Int32 mode) &&
data["sceneSupportedKeyAttributesMask"][item].Keys.Contains("value") &&
data["sceneSupportedKeyAttributesMask"][item]["value"].IsArray) {
JsonData values = data["sceneSupportedKeyAttributesMask"][item]["value"];
List<Int32> modes = new List<Int32>();
foreach (JsonData value in values) {
modes.Add(Int32.Parse(value.ToString()));
}
scenes.Add(mode, new ReadOnlyCollection<Int32>(modes));
}
}
this.ValidScenesModes = new ReadOnlyDictionary<Int32, ReadOnlyCollection<Int32>>(scenes);
if (data.Keys.Contains("currentScene") &&
data["currentScene"].Keys.Contains("value") &&
data["currentScene"]["value"] != null) {
this.Scene = Int32.Parse(data["currentScene"]["value"].ToString());
}
if (data.Keys.Contains("keyAttribute") &&
data["keyAttribute"].Keys.Contains("value") &&
data["keyAttribute"]["value"] != null) {
this.Key = Int32.Parse(data["keyAttribute"]["value"].ToString());
}
}
}
}
public override String ToString() {
return "CentralScene " + this.Name + " [" + this.Id + "]: " + this.Scene+"-"+this.Key;
}
internal override void Poll() => this.PollNone();
#endregion
public override Dictionary<String, Object> ToDictionary() {
return new Dictionary<String, Object> {
{ "Scene", this.Scene },
{ "Key", this.Key },
};
#region ISenml
protected override List<Senml> ToSenmlList() {
return new List<Senml>() { new SenmlDouble("scene", Senml.Units.CounterValue, this.Scene), new SenmlDouble("key", Senml.Units.CounterValue, this.Key) };
}
#endregion
}
}