58 lines
2.4 KiB
C#
58 lines
2.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Collections.ObjectModel;
|
|
using System.IO;
|
|
|
|
using BlubbFish.IoT.Zway.Devices;
|
|
using BlubbFish.IoT.Zway.Events;
|
|
using BlubbFish.IoT.Zway.Interfaces;
|
|
using BlubbFish.Utils;
|
|
|
|
namespace BlubbFish.IoT.Zway.lib {
|
|
public abstract class ZwayBoard : IDisposable {
|
|
protected Dictionary<String, String> config;
|
|
protected Boolean polling;
|
|
protected ReadOnlyDictionary<String, ReadOnlyDictionary<String, String>> names;
|
|
|
|
public delegate void DataUpdate(Object sender, DeviceUpdateEvent e);
|
|
public event DataUpdate Update;
|
|
|
|
public ReadOnlyDictionary<Int32, Device> Devices {
|
|
get; protected set;
|
|
}
|
|
|
|
#region Constructor and deconstructor
|
|
protected ZwayBoard(Dictionary<String, String> settings, ReadOnlyDictionary<String, ReadOnlyDictionary<String, String>> names, Boolean enablePoll) {
|
|
this.config = settings;
|
|
this.names = names;
|
|
this.polling = enablePoll;
|
|
}
|
|
public static ZwayBoard GetInstance(Dictionary<String, String> settings, ReadOnlyDictionary<String, ReadOnlyDictionary<String, String>> names, Boolean enablePoll) {
|
|
if(settings.Count == 0) {
|
|
throw new ArgumentException("Missing block [zway] in settingsfile");
|
|
} else if(!settings.ContainsKey("type")) {
|
|
throw new ArgumentException("Missing type for [zway] in settingsfile");
|
|
}
|
|
String object_sensor = "BlubbFish.IoT.Zway.lib." + settings["type"].ToUpperLower() + "." + settings["type"].ToUpperLower();
|
|
try {
|
|
Type t = Type.GetType(object_sensor, true);
|
|
return (ZwayBoard)t.GetConstructor(new Type[] { typeof(Dictionary<String, String>), typeof(ReadOnlyDictionary<String, ReadOnlyDictionary<String, String>>), typeof(Boolean) }).Invoke(new Object[] { settings, names, enablePoll });
|
|
} catch(TypeLoadException) {
|
|
throw new ArgumentException("Configuration: " + settings["type"] + " is not a ZwayBoard");
|
|
} catch(FileNotFoundException) {
|
|
throw new Exception("Driver " + object_sensor + " could not load!");
|
|
}
|
|
|
|
}
|
|
public abstract void Dispose();
|
|
#endregion
|
|
|
|
#region External
|
|
public abstract void Connect();
|
|
public abstract ACommandClass GetCommandClass(String id);
|
|
#endregion
|
|
|
|
protected void DeviceUpdate(Object sender, DeviceUpdateEvent e) => this.Update?.Invoke(sender, e);
|
|
}
|
|
}
|