[NF] v1.3.0.0 Remove Interface ICommandClass.cs and dublicated classes CommandClass.cs and CommandClassSub.cs, put them into the abstracted class ACommandClass.cs
[NF] v1.2.0.0 Change classid to enum, so its more readable [NF] v1.1.0.0 Rename a lot of internal functions
This commit is contained in:
+20
-19
@@ -73,23 +73,24 @@ namespace BlubbFish.IoT.Zway {
|
||||
}
|
||||
}
|
||||
|
||||
public ICommandClass GetCommandClass(Int32 deviceid, Int32 instanceid, Int32 classid) {
|
||||
if(this.Devices.ContainsKey(deviceid) && this.Devices[deviceid].Instances.ContainsKey(instanceid) && this.Devices[deviceid].Instances[instanceid].CommandClasses.ContainsKey(classid)) {
|
||||
return this.Devices[deviceid].Instances[instanceid].CommandClasses[classid];
|
||||
public ACommandClass GetCommandClass(String id) {
|
||||
String[] addr = id.Split('-');
|
||||
if (addr.Length == 3 || addr.Length == 4) {
|
||||
return this.GetCommandClass(Int32.Parse(addr[0]), Int32.Parse(addr[1]), (ACommandClass.Classes)Int32.Parse(addr[2]), (addr.Length == 4 ? Int32.Parse(addr[3]) : -1));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public ICommandClass GetCommandClassSub(Int32 deviceid, Int32 instanceid, Int32 classid, Int32 subcid) {
|
||||
ICommandClass comandclass = this.GetCommandClass(deviceid, instanceid, classid);
|
||||
if (comandclass != null) {
|
||||
foreach (PropertyInfo item in comandclass.GetType().GetProperties()) {
|
||||
if (item.Name == "Sub") {
|
||||
if (comandclass.GetType().GetProperty("Sub").PropertyType == typeof(ReadOnlyDictionary<Int32, CommandClassSub>)) {
|
||||
ReadOnlyDictionary<Int32, CommandClassSub> commandclasssub = (ReadOnlyDictionary<Int32, CommandClassSub>)comandclass.GetType().GetProperty("Sub").GetValue(comandclass);
|
||||
if (commandclasssub.ContainsKey(subcid)) {
|
||||
return commandclasssub[subcid];
|
||||
}
|
||||
public ACommandClass GetCommandClass(Int32 deviceid, Int32 instanceid, ACommandClass.Classes classid, Int32 subcid = -1) {
|
||||
if(this.Devices.ContainsKey(deviceid) && this.Devices[deviceid].Instances.ContainsKey(instanceid) && this.Devices[deviceid].Instances[instanceid].CommandClasses.ContainsKey(classid)) {
|
||||
ACommandClass commandclass = this.Devices[deviceid].Instances[instanceid].CommandClasses[classid];
|
||||
if(subcid == -1) {
|
||||
return commandclass;
|
||||
}
|
||||
if (commandclass != null) {
|
||||
if(commandclass.HasSub) {
|
||||
if(commandclass.Sub.ContainsKey(subcid)) {
|
||||
return commandclass.Sub[subcid];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -112,7 +113,7 @@ namespace BlubbFish.IoT.Zway {
|
||||
if(match.Success) {
|
||||
Int32 deviceid = Int32.Parse(match.Groups[1].Value);
|
||||
Int32 instanceid = Int32.Parse(match.Groups[2].Value);
|
||||
Int32 commandid = Int32.Parse(match.Groups[3].Value);
|
||||
ACommandClass.Classes commandid = (ACommandClass.Classes)Int32.Parse(match.Groups[3].Value);
|
||||
if (this.Devices.ContainsKey(deviceid) && this.Devices[deviceid].Instances.ContainsKey(instanceid) && this.Devices[deviceid].Instances[instanceid].CommandClasses.ContainsKey(commandid)) {
|
||||
this.Devices[deviceid].Instances[instanceid].CommandClasses[commandid].SetUpdate(notifications[item], match);
|
||||
}
|
||||
@@ -149,13 +150,13 @@ namespace BlubbFish.IoT.Zway {
|
||||
this.Devices = new ReadOnlyDictionary<Int32, Device>(devices);
|
||||
}
|
||||
|
||||
public List<T> GetCommandClasses<T>() {
|
||||
List<T> ret = new List<T>();
|
||||
public Dictionary<String, ACommandClass> GetCommandClasses(ACommandClass.Classes classes) {
|
||||
Dictionary<String, ACommandClass> ret = new Dictionary<String, ACommandClass>();
|
||||
foreach (KeyValuePair<Int32, Device> device in this.Devices) {
|
||||
foreach (KeyValuePair<Int32, Instance> instance in device.Value.Instances) {
|
||||
foreach (KeyValuePair<Int32, CommandClass> commandclass in instance.Value.CommandClasses) {
|
||||
if (commandclass.Value is T) {
|
||||
ret.Add((T)Convert.ChangeType(commandclass.Value, typeof(T)));
|
||||
foreach (KeyValuePair<ACommandClass.Classes, ACommandClass> commandclass in instance.Value.CommandClasses) {
|
||||
if (commandclass.Key == classes) {
|
||||
ret.Add(commandclass.Value.Id, commandclass.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user