Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
80baca45e5 | ||
|
|
75eac65510 | ||
|
|
44b8daa325 | ||
|
|
2cd2c7c02e | ||
|
|
33b1b6527c | ||
|
|
9e60264d7d | ||
|
|
c96b2393d3 | ||
|
|
5fa97ea82b | ||
|
|
74027d705d |
@@ -13,6 +13,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Utils-IoT", "..\Utils\IoT\U
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConnectorDataMosquitto", "..\Utils\IoT\Connector\Data\Mosquitto\ConnectorDataMosquitto.csproj", "{39235FAD-BA9D-4B51-82FC-6969967BEAE9}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConnectorDataMosquitto", "..\Utils\IoT\Connector\Data\Mosquitto\ConnectorDataMosquitto.csproj", "{39235FAD-BA9D-4B51-82FC-6969967BEAE9}"
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConnectorDataMqtt", "..\Utils\IoT\Connector\Data\Mqtt\ConnectorDataMqtt.csproj", "{EE6C8F68-ED46-4C1C-ABDD-CFCDF75104F2}"
|
||||||
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
Debug|Any CPU = Debug|Any CPU
|
||||||
@@ -39,6 +41,10 @@ Global
|
|||||||
{39235FAD-BA9D-4B51-82FC-6969967BEAE9}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{39235FAD-BA9D-4B51-82FC-6969967BEAE9}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{39235FAD-BA9D-4B51-82FC-6969967BEAE9}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{39235FAD-BA9D-4B51-82FC-6969967BEAE9}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{39235FAD-BA9D-4B51-82FC-6969967BEAE9}.Release|Any CPU.Build.0 = Release|Any CPU
|
{39235FAD-BA9D-4B51-82FC-6969967BEAE9}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{EE6C8F68-ED46-4C1C-ABDD-CFCDF75104F2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{EE6C8F68-ED46-4C1C-ABDD-CFCDF75104F2}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{EE6C8F68-ED46-4C1C-ABDD-CFCDF75104F2}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{EE6C8F68-ED46-4C1C-ABDD-CFCDF75104F2}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
|||||||
@@ -39,6 +39,34 @@ namespace ZwayBot {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class MqttEvent : ModulEventArgs {
|
||||||
|
public MqttEvent() {
|
||||||
|
}
|
||||||
|
public MqttEvent(String topic, String text) {
|
||||||
|
this.Address = topic;
|
||||||
|
this.Value = text;
|
||||||
|
this.Source = "MQTT";
|
||||||
|
}
|
||||||
|
public override String ToString() {
|
||||||
|
return this.Source + ": on " + this.Address + " set " + this.Value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class StatusPollingEvent : ModulEventArgs {
|
||||||
|
public StatusPollingEvent() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public StatusPollingEvent(String text, String node) {
|
||||||
|
this.Value = text;
|
||||||
|
this.Address = node;
|
||||||
|
this.Source = "POLLING";
|
||||||
|
}
|
||||||
|
|
||||||
|
public override String ToString() {
|
||||||
|
return this.Source + ": " + this.Value + " on " + this.Address;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public class ModulEventArgs : EventArgs {
|
public class ModulEventArgs : EventArgs {
|
||||||
public ModulEventArgs() {
|
public ModulEventArgs() {
|
||||||
}
|
}
|
||||||
|
|||||||
+26
-7
@@ -2,8 +2,8 @@
|
|||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
|
||||||
namespace ZwayBot {
|
namespace ZwayBot {
|
||||||
class Helper {
|
static class Helper {
|
||||||
public static void SetProperty(Object o, String name, String value) {
|
public static void SetProperty(this Object o, String name, String value) {
|
||||||
PropertyInfo prop = o.GetType().GetProperty(name);
|
PropertyInfo prop = o.GetType().GetProperty(name);
|
||||||
if (prop.CanWrite) {
|
if (prop.CanWrite) {
|
||||||
if (prop.PropertyType == typeof(Boolean) && Boolean.TryParse(value, out Boolean vb)) {
|
if (prop.PropertyType == typeof(Boolean) && Boolean.TryParse(value, out Boolean vb)) {
|
||||||
@@ -12,12 +12,15 @@ namespace ZwayBot {
|
|||||||
prop.SetValue(o, v32);
|
prop.SetValue(o, v32);
|
||||||
} else if (prop.PropertyType == typeof(Single) && Single.TryParse(value, out Single vs)) {
|
} else if (prop.PropertyType == typeof(Single) && Single.TryParse(value, out Single vs)) {
|
||||||
prop.SetValue(o, vs);
|
prop.SetValue(o, vs);
|
||||||
|
} else if (prop.PropertyType == typeof(Double) && Double.TryParse(value, out Double vd)) {
|
||||||
|
prop.SetValue(o, vd);
|
||||||
} else if (prop.PropertyType == typeof(Int64) && Int64.TryParse(value, out Int64 v64)) {
|
} else if (prop.PropertyType == typeof(Int64) && Int64.TryParse(value, out Int64 v64)) {
|
||||||
prop.SetValue(o, v64);
|
prop.SetValue(o, v64);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public static Boolean HasProperty(Object o, String type) {
|
|
||||||
|
internal static Boolean HasProperty(this Object o, String type) {
|
||||||
Type t = o.GetType();
|
Type t = o.GetType();
|
||||||
foreach (PropertyInfo item in t.GetProperties()) {
|
foreach (PropertyInfo item in t.GetProperties()) {
|
||||||
if (item.Name == type) {
|
if (item.Name == type) {
|
||||||
@@ -27,7 +30,7 @@ namespace ZwayBot {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static Object GetProperty(Object o, String name) {
|
internal static Object GetProperty(this Object o, String name) {
|
||||||
PropertyInfo prop = o.GetType().GetProperty(name);
|
PropertyInfo prop = o.GetType().GetProperty(name);
|
||||||
if(prop.CanRead) {
|
if(prop.CanRead) {
|
||||||
return prop.GetValue(o);
|
return prop.GetValue(o);
|
||||||
@@ -35,9 +38,15 @@ namespace ZwayBot {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static Boolean HasInterface(Object o, String type) {
|
internal static Boolean HasAbstract(this Object o, Type type) {
|
||||||
Type t = o.GetType();
|
if(o.GetType().BaseType == type) {
|
||||||
foreach (Type item in t.GetInterfaces()) {
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static Boolean HasInterface(this Type o, String type) {
|
||||||
|
foreach (Type item in o.GetInterfaces()) {
|
||||||
if(item.Name == type) {
|
if(item.Name == type) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -50,5 +59,15 @@ namespace ZwayBot {
|
|||||||
Console.Error.WriteLine("ERROR: " + text);
|
Console.Error.WriteLine("ERROR: " + text);
|
||||||
Console.ResetColor();
|
Console.ResetColor();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal static String ToUpperLower(this String s) {
|
||||||
|
if(s.Length == 0) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
if(s.Length == 1) {
|
||||||
|
return s.ToUpper();
|
||||||
|
}
|
||||||
|
return s[0].ToString().ToUpper() + s.Substring(1).ToLower();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
namespace ZwayBot.Interfaces {
|
||||||
|
interface IForceLoad {
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,20 +1,71 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using BlubbFish.IoT.Zway;
|
using BlubbFish.IoT.Zway;
|
||||||
using BlubbFish.Utils;
|
using BlubbFish.Utils;
|
||||||
|
|
||||||
namespace ZwayBot {
|
namespace ZwayBot {
|
||||||
abstract class AModul {
|
abstract class AModul {
|
||||||
protected ZwayController zw;
|
protected ZwayController zw;
|
||||||
protected InIReader ini;
|
private InIReader settings;
|
||||||
|
protected Dictionary<String, Dictionary<String, String>> config = new Dictionary<String, Dictionary<String, String>>();
|
||||||
|
|
||||||
public AModul(ZwayController zway, InIReader settings) {
|
public Boolean HasConfig { get; private set; }
|
||||||
this.zw = zway;
|
public Boolean ConfigPublic { get; private set; }
|
||||||
this.ini = settings;
|
|
||||||
}
|
|
||||||
|
|
||||||
public delegate void ModulEvent(Object sender, ModulEventArgs e);
|
public delegate void ModulEvent(Object sender, ModulEventArgs e);
|
||||||
public abstract event ModulEvent Update;
|
public abstract event ModulEvent Update;
|
||||||
|
|
||||||
|
public AModul(ZwayController zway, InIReader settings) {
|
||||||
|
this.HasConfig = false;
|
||||||
|
this.ConfigPublic = false;
|
||||||
|
this.zw = zway;
|
||||||
|
this.settings = settings;
|
||||||
|
this.ParseConfig();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ParseConfig() {
|
||||||
|
if (this.settings != null) {
|
||||||
|
this.HasConfig = true;
|
||||||
|
foreach (String item in this.settings.GetSections(false)) {
|
||||||
|
this.config.Add(item, this.settings.GetSection(item));
|
||||||
|
}
|
||||||
|
if(this.config.ContainsKey("modul")) {
|
||||||
|
this.ConfigPublic = this.config["modul"].ContainsKey("config") && this.config["modul"]["config"].ToLower() == "public";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Dictionary<String, Dictionary<String, String>> GetConfig() {
|
||||||
|
if (this.HasConfig && this.ConfigPublic) {
|
||||||
|
Dictionary<String, Dictionary<String, String>> ret = new Dictionary<String, Dictionary<String, String>>(this.config);
|
||||||
|
if(ret.ContainsKey("modul")) {
|
||||||
|
ret.Remove("modul");
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
return new Dictionary<String, Dictionary<String, String>>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual void Interconnect(Dictionary<String, AModul> moduls) { }
|
||||||
|
|
||||||
|
public virtual void SetInterconnection(String param, Action<Object> hook, Object data) { }
|
||||||
|
|
||||||
public abstract void Dispose();
|
public abstract void Dispose();
|
||||||
|
|
||||||
|
internal void SetConfig(Dictionary<String, Dictionary<String, String>> newconf) {
|
||||||
|
if (this.HasConfig && this.ConfigPublic) {
|
||||||
|
if (newconf.ContainsKey("modul")) {
|
||||||
|
newconf.Remove("modul");
|
||||||
|
}
|
||||||
|
if (this.config.ContainsKey("modul")) {
|
||||||
|
newconf.Add("modul", this.config["modul"]);
|
||||||
|
}
|
||||||
|
this.config = newconf;
|
||||||
|
this.settings.SetSections(this.config);
|
||||||
|
this.UpdateConfig();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract void UpdateConfig();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+23
-20
@@ -6,11 +6,13 @@ using System.Threading;
|
|||||||
using BlubbFish.IoT.Zway;
|
using BlubbFish.IoT.Zway;
|
||||||
using BlubbFish.IoT.Zway.Interfaces;
|
using BlubbFish.IoT.Zway.Interfaces;
|
||||||
using BlubbFish.Utils;
|
using BlubbFish.Utils;
|
||||||
|
using ZwayBot.Interfaces;
|
||||||
|
|
||||||
namespace ZwayBot.Moduls {
|
namespace ZwayBot.Moduls {
|
||||||
internal class CronJob : AModul, IDisposable {
|
internal class CronJob : AModul, IDisposable, IForceLoad {
|
||||||
private DateTime crontime;
|
private DateTime crontime;
|
||||||
private Thread thread;
|
private Thread thread;
|
||||||
|
private List<Tuple<String, Action<Object>, Object>> internalCron = new List<Tuple<String, Action<Object>, Object>>();
|
||||||
|
|
||||||
public override event ModulEvent Update;
|
public override event ModulEvent Update;
|
||||||
|
|
||||||
@@ -34,9 +36,16 @@ namespace ZwayBot.Moduls {
|
|||||||
while (true) {
|
while (true) {
|
||||||
if(this.crontime.Minute != DateTime.Now.Minute) {
|
if(this.crontime.Minute != DateTime.Now.Minute) {
|
||||||
this.crontime = DateTime.Now;
|
this.crontime = DateTime.Now;
|
||||||
foreach (String item in this.ini.GetSections()) {
|
if (this.config.Count != 0) {
|
||||||
if(ParseCronString(this.ini.GetValue(item, "cron"))) {
|
foreach (KeyValuePair<String, Dictionary<String, String>> item in this.config) {
|
||||||
this.SetValues(this.ini.GetValue(item, "set"));
|
if (item.Value.ContainsKey("cron") && item.Value.ContainsKey("set") && this.ParseCronString(item.Value["cron"])) {
|
||||||
|
this.SetValues(item.Value["set"]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
foreach (Tuple<String, Action<Object>, Object> item in this.internalCron) {
|
||||||
|
if(this.ParseCronString(item.Item1)) {
|
||||||
|
item.Item2?.Invoke(item.Item3);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -48,29 +57,17 @@ namespace ZwayBot.Moduls {
|
|||||||
foreach (String item in value.Split(';')) {
|
foreach (String item in value.Split(';')) {
|
||||||
String[] items = item.Split(':');
|
String[] items = item.Split(':');
|
||||||
if(items.Length == 2) {
|
if(items.Length == 2) {
|
||||||
String[] addr = items[0].Split('-');
|
|
||||||
String[] values = items[1].Split('-');
|
String[] values = items[1].Split('-');
|
||||||
if(addr.Length == 3 || addr.Length == 4) {
|
ACommandClass c = this.zw.GetCommandClass(items[0]);
|
||||||
Int32 deviceid = Int32.Parse(addr[0]);
|
|
||||||
Int32 instanceid = Int32.Parse(addr[1]);
|
|
||||||
Int32 classid = Int32.Parse(addr[2]);
|
|
||||||
ICommandClass c;
|
|
||||||
if(addr.Length == 4) {
|
|
||||||
Int32 subcid = Int32.Parse(addr[3]);
|
|
||||||
c = this.zw.GetCommandClassSub(deviceid, instanceid, classid, subcid);
|
|
||||||
} else {
|
|
||||||
c = this.zw.GetCommandClass(deviceid, instanceid, classid);
|
|
||||||
}
|
|
||||||
if (c != null && values.Length == 2) {
|
if (c != null && values.Length == 2) {
|
||||||
if (Helper.HasProperty(c, values[0])) {
|
if (c.HasProperty(values[0])) {
|
||||||
Helper.SetProperty(c, values[0], values[1]);
|
c.SetProperty(values[0], values[1]);
|
||||||
this.Update?.Invoke(this, new CronEvent(items[0], values[0], values[1]));
|
this.Update?.Invoke(this, new CronEvent(items[0], values[0], values[1]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private Boolean ParseCronString(String str) {
|
private Boolean ParseCronString(String str) {
|
||||||
str = str.Trim();
|
str = str.Trim();
|
||||||
@@ -112,7 +109,7 @@ namespace ZwayBot.Moduls {
|
|||||||
cron = cron.Replace(DateTime.Parse("2015-01-" + (4 + i) + "T00:00:00").ToString("dddd", CultureInfo.CreateSpecificCulture("en-US")), i.ToString());
|
cron = cron.Replace(DateTime.Parse("2015-01-" + (4 + i) + "T00:00:00").ToString("dddd", CultureInfo.CreateSpecificCulture("en-US")), i.ToString());
|
||||||
}
|
}
|
||||||
for (Int32 i = 1; i <= 12; i++) {
|
for (Int32 i = 1; i <= 12; i++) {
|
||||||
cron = cron.Replace(DateTime.Parse("2015-"+i+"-01T00:00:00").ToString("MMM", CultureInfo.CreateSpecificCulture("en-US")), i.ToString());
|
cron = cron.Replace(DateTime.Parse("2015-" + i + "-01T00:00:00").ToString("MMM", CultureInfo.CreateSpecificCulture("en-US")), i.ToString());
|
||||||
cron = cron.Replace(DateTime.Parse("2015-" + i + "-01T00:00:00").ToString("MMMM", CultureInfo.CreateSpecificCulture("en-US")), i.ToString());
|
cron = cron.Replace(DateTime.Parse("2015-" + i + "-01T00:00:00").ToString("MMMM", CultureInfo.CreateSpecificCulture("en-US")), i.ToString());
|
||||||
}
|
}
|
||||||
if (cron.Contains("*")) {
|
if (cron.Contains("*")) {
|
||||||
@@ -156,6 +153,12 @@ namespace ZwayBot.Moduls {
|
|||||||
return ret.ContainsKey(Int32.Parse(date));
|
return ret.ContainsKey(Int32.Parse(date));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override void SetInterconnection(String cron, Action<Object> hook, Object data) {
|
||||||
|
this.internalCron.Add(new Tuple<String, Action<Object>, Object>(cron, hook, data));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void UpdateConfig() { }
|
||||||
|
|
||||||
#region IDisposable Support
|
#region IDisposable Support
|
||||||
private Boolean disposedValue = false;
|
private Boolean disposedValue = false;
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Net;
|
||||||
using BlubbFish.IoT.Zway;
|
using BlubbFish.IoT.Zway;
|
||||||
using BlubbFish.IoT.Zway.Devices;
|
using BlubbFish.IoT.Zway.Devices;
|
||||||
using BlubbFish.IoT.Zway.Devices.CommandClasses;
|
using BlubbFish.IoT.Zway.Devices.CommandClasses;
|
||||||
using BlubbFish.IoT.Zway.Devices.CommandClasses.CommandClassSubs;
|
using BlubbFish.IoT.Zway.Devices.CommandClasses.CommandClassSubs;
|
||||||
using BlubbFish.IoT.Zway.Events;
|
using BlubbFish.IoT.Zway.Events;
|
||||||
|
using BlubbFish.IoT.Zway.Interfaces;
|
||||||
using BlubbFish.Utils;
|
using BlubbFish.Utils;
|
||||||
using BlubbFish.Utils.IoT.Connector;
|
using BlubbFish.Utils.IoT.Connector;
|
||||||
using LitJson;
|
using LitJson;
|
||||||
@@ -13,52 +15,56 @@ namespace ZwayBot.Moduls {
|
|||||||
class Flex4Grid : AModul, IDisposable {
|
class Flex4Grid : AModul, IDisposable {
|
||||||
private ADataBackend mqtt;
|
private ADataBackend mqtt;
|
||||||
private String household = "";
|
private String household = "";
|
||||||
|
private Object requestalivelock = new Object();
|
||||||
|
|
||||||
public override event ModulEvent Update;
|
public override event ModulEvent Update;
|
||||||
|
|
||||||
public Flex4Grid(ZwayController zway, InIReader settings) : base(zway, settings) {
|
public Flex4Grid(ZwayController zway, InIReader settings) : base(zway, settings) {
|
||||||
this.mqtt = ADataBackend.GetInstance(this.ini.GetSection("settings"));
|
if (this.config.ContainsKey("settings")) {
|
||||||
|
this.mqtt = ADataBackend.GetInstance(this.config["settings"]);
|
||||||
this.ParseIni();
|
this.ParseIni();
|
||||||
this.mqtt.MessageIncomming += this.Mqtt_MessageIncomming;
|
this.mqtt.MessageIncomming += this.Mqtt_MessageIncomming;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void ParseIni() {
|
private void ParseIni() {
|
||||||
if (this.ini.GetValue("zway", "devices") != null) {
|
if (this.config.ContainsKey("zway") && this.config["zway"].ContainsKey("devices")) {
|
||||||
foreach (String device in this.ini.GetValue("zway", "devices").Split(',')) {
|
foreach (String device in this.config["zway"]["devices"].Split(',')) {
|
||||||
Int32 deviceid = Int32.Parse(device);
|
Int32 deviceid = Int32.Parse(device);
|
||||||
if (this.zw.Devices.ContainsKey(deviceid) && this.zw.Devices[deviceid].Instances.ContainsKey(0)) {
|
if (this.zw.Devices.ContainsKey(deviceid) && this.zw.Devices[deviceid].Instances.ContainsKey(0)) {
|
||||||
this.zw.Devices[deviceid].Instances[0].Update += this.DeviceUpdate;
|
this.zw.Devices[deviceid].Instances[0].Update += this.DeviceUpdate;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(this.ini.GetValue("f4g", "household") != null) {
|
if(this.config.ContainsKey("f4g") && this.config["f4g"].ContainsKey("household")) {
|
||||||
this.household = this.ini.GetValue("f4g", "household");
|
this.household = this.config["f4g"]["household"];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void DeviceUpdate(Object sender, DeviceUpdateEvent e) {
|
private void DeviceUpdate(Object sender, DeviceUpdateEvent e) {
|
||||||
Instance instance = (Instance)sender;
|
Instance instance = (Instance)sender;
|
||||||
if(e.Parent.GetType() == typeof(Switchbinary)) {
|
if(e.Parent.GetType() == typeof(Switchbinary)) {
|
||||||
if (instance.CommandClasses.ContainsKey(37)) { //SwitchBinary
|
if (instance.CommandClasses.ContainsKey(ACommandClass.Classes.SwitchBinary)) {
|
||||||
String topic = "/flex4grid/v1/households/" + this.household + "/device/state";
|
String topic = "/flex4grid/v1/households/" + this.household + "/device/state";
|
||||||
String text = JsonMapper.ToJson(new Dictionary<String, String>() {
|
String text = JsonMapper.ToJson(new Dictionary<String, String>() {
|
||||||
{ "status", ((Switchbinary)instance.CommandClasses[37]).Level?"active":"idle" },
|
{ "status", ((Switchbinary)instance.CommandClasses[ACommandClass.Classes.SwitchBinary]).Level?"active":"idle" },
|
||||||
{ "timestamp", DateTime.Now.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'ffffff'Z'") },
|
{ "timestamp", DateTime.Now.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'ffffff'Z'") },
|
||||||
{ "type", ((Switchbinary)instance.CommandClasses[37]).Name },
|
{ "type", ((Switchbinary)instance.CommandClasses[ACommandClass.Classes.SwitchBinary]).Name },
|
||||||
{ "id", instance.DeviceId.ToString() }
|
{ "id", instance.DeviceId.ToString() }
|
||||||
}).ToString();
|
}).ToString();
|
||||||
this.mqtt.Send(topic, text);
|
this.mqtt.Send(topic, text);
|
||||||
this.Update?.Invoke(this, new Flex4gridEvent(topic, text));
|
this.Update?.Invoke(this, new Flex4gridEvent(topic, text));
|
||||||
}
|
}
|
||||||
} else if(e.Parent.GetType() == typeof(Sensormultilevelsub) || e.Parent.GetType() == typeof(Metersub)) {
|
} else if(e.Parent.GetType() == typeof(Sensormultilevelsub) || e.Parent.GetType() == typeof(Metersub)) {
|
||||||
if (instance.CommandClasses.ContainsKey(49) && ((Sensormultilevel)instance.CommandClasses[49]).Sub.ContainsKey(4) && //SensorMultilevel
|
if (instance.CommandClasses.ContainsKey(ACommandClass.Classes.SensorMultilevel) &&
|
||||||
instance.CommandClasses.ContainsKey(50) && ((Meter)instance.CommandClasses[50]).Sub.ContainsKey(0)) { //Meter
|
((Sensormultilevel)instance.CommandClasses[ACommandClass.Classes.SensorMultilevel]).Sub.ContainsKey(4) &&
|
||||||
|
instance.CommandClasses.ContainsKey(ACommandClass.Classes.Meter) && ((Meter)instance.CommandClasses[ACommandClass.Classes.Meter]).Sub.ContainsKey(0)) {
|
||||||
String topic = "/flex4grid/v1/households/" + this.household + "/device/consumption";
|
String topic = "/flex4grid/v1/households/" + this.household + "/device/consumption";
|
||||||
String text = JsonMapper.ToJson(new Dictionary<String, String>() {
|
String text = JsonMapper.ToJson(new Dictionary<String, String>() {
|
||||||
{ "timestamp", DateTime.Now.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'ffffff'Z'") },
|
{ "timestamp", DateTime.Now.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'ffffff'Z'") },
|
||||||
{ "id", instance.DeviceId.ToString() },
|
{ "id", instance.DeviceId.ToString() },
|
||||||
{ "power", Math.Round(((Sensormultilevelsub)((Sensormultilevel)instance.CommandClasses[49]).Sub[4]).Level).ToString("F0") },
|
{ "power", Math.Round(((Sensormultilevelsub)((Sensormultilevel)instance.CommandClasses[ACommandClass.Classes.SensorMultilevel]).Sub[4]).Level).ToString("F0") },
|
||||||
{ "energyCumul", ((Metersub)((Meter)instance.CommandClasses[50]).Sub[0]).Level.ToString() }
|
{ "energyCumul", ((Metersub)((Meter)instance.CommandClasses[ACommandClass.Classes.Meter]).Sub[0]).Level.ToString() }
|
||||||
}).ToString();
|
}).ToString();
|
||||||
this.mqtt.Send(topic, text);
|
this.mqtt.Send(topic, text);
|
||||||
this.Update?.Invoke(this, new Flex4gridEvent(topic, text));
|
this.Update?.Invoke(this, new Flex4gridEvent(topic, text));
|
||||||
@@ -81,12 +87,13 @@ namespace ZwayBot.Moduls {
|
|||||||
if(topic == "/flex4grid/v1/households/" + this.household + "/device/actuate") {
|
if(topic == "/flex4grid/v1/households/" + this.household + "/device/actuate") {
|
||||||
if(message.Keys.Contains("deviceId") && message.Keys.Contains("command")) {
|
if(message.Keys.Contains("deviceId") && message.Keys.Contains("command")) {
|
||||||
String device = message["deviceId"].ToString();
|
String device = message["deviceId"].ToString();
|
||||||
if(this.ini.GetValue("zway", "devices") != null) {
|
if(this.config.ContainsKey("zway") && this.config["zway"].ContainsKey("devices")) {
|
||||||
foreach (String item in this.ini.GetValue("zway", "devices").Split(',')) {
|
foreach (String item in this.config["zway"]["devices"].Split(',')) {
|
||||||
if (item == device) {
|
if (item == device) {
|
||||||
Int32 deviceid = Int32.Parse(device);
|
Int32 deviceid = Int32.Parse(device);
|
||||||
if (this.zw.Devices.ContainsKey(deviceid) && this.zw.Devices[deviceid].Instances.ContainsKey(0) && this.zw.Devices[deviceid].Instances[0].CommandClasses.ContainsKey(37)) {
|
if (this.zw.Devices.ContainsKey(deviceid) && this.zw.Devices[deviceid].Instances.ContainsKey(0) &&
|
||||||
((Switchbinary)this.zw.Devices[deviceid].Instances[0].CommandClasses[37]).Level = message["command"].ToString() == "ON";
|
this.zw.Devices[deviceid].Instances[0].CommandClasses.ContainsKey(ACommandClass.Classes.SwitchBinary)) {
|
||||||
|
((Switchbinary)this.zw.Devices[deviceid].Instances[0].CommandClasses[ACommandClass.Classes.SwitchBinary]).Level = message["command"].ToString() == "ON";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -94,13 +101,13 @@ namespace ZwayBot.Moduls {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (topic == "/flex4grid/v1/households/" + this.household + "/devices/state/request") {
|
if (topic == "/flex4grid/v1/households/" + this.household + "/devices/state/request") {
|
||||||
if (this.ini.GetValue("zway", "devices") != null) {
|
if (this.config.ContainsKey("zway") && this.config["zway"].ContainsKey("devices")) {
|
||||||
Dictionary<String, String> response = new Dictionary<String, String>();
|
Dictionary<String, String> response = new Dictionary<String, String>();
|
||||||
foreach (String device in this.ini.GetValue("zway", "devices").Split(',')) {
|
foreach (String device in this.config["zway"]["devices"].Split(',')) {
|
||||||
Int32 deviceid = Int32.Parse(device);
|
Int32 deviceid = Int32.Parse(device);
|
||||||
if (this.zw.Devices.ContainsKey(deviceid) && this.zw.Devices[deviceid].Instances.ContainsKey(0)) {
|
if (this.zw.Devices.ContainsKey(deviceid) && this.zw.Devices[deviceid].Instances.ContainsKey(0)) {
|
||||||
if (this.zw.Devices[deviceid].Instances[0].CommandClasses.ContainsKey(37)) {
|
if (this.zw.Devices[deviceid].Instances[0].CommandClasses.ContainsKey(ACommandClass.Classes.SwitchBinary)) {
|
||||||
Switchbinary sw = ((Switchbinary)this.zw.Devices[deviceid].Instances[0].CommandClasses[37]);
|
Switchbinary sw = ((Switchbinary)this.zw.Devices[deviceid].Instances[0].CommandClasses[ACommandClass.Classes.SwitchBinary]);
|
||||||
response.Add(sw.DeviceId.ToString(), sw.Level ? "active" : "idle");
|
response.Add(sw.DeviceId.ToString(), sw.Level ? "active" : "idle");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -114,6 +121,51 @@ namespace ZwayBot.Moduls {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void RequestAlive(Object o) {
|
||||||
|
if (this.config.ContainsKey("f4g") && this.config["f4g"].ContainsKey("raspi")) {
|
||||||
|
String raspi = this.config["f4g"]["raspi"];
|
||||||
|
lock (this.requestalivelock) {
|
||||||
|
String req = "https://wiki.flex4grid.eu/rupdate/rupdate_general.yml.gpg.asc?gw=" + raspi;
|
||||||
|
HttpWebRequest request = WebRequest.CreateHttp(req);
|
||||||
|
try {
|
||||||
|
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) {
|
||||||
|
this.Update?.Invoke(this, new Flex4gridEvent(req, response.StatusCode.ToString()));
|
||||||
|
}
|
||||||
|
} catch (Exception) { }
|
||||||
|
}
|
||||||
|
lock (this.requestalivelock) {
|
||||||
|
String req = "https://wiki.flex4grid.eu/rupdate/rupdate_general.yml?gw=" + raspi;
|
||||||
|
HttpWebRequest request = WebRequest.CreateHttp(req);
|
||||||
|
try {
|
||||||
|
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) {
|
||||||
|
this.Update?.Invoke(this, new Flex4gridEvent(req, response.StatusCode.ToString()));
|
||||||
|
}
|
||||||
|
} catch (Exception) { }
|
||||||
|
}
|
||||||
|
lock (this.requestalivelock) {
|
||||||
|
String req = "http://swb.pcs.flex4grid.eu/gateway/" + raspi;
|
||||||
|
HttpWebRequest request = WebRequest.CreateHttp(req);
|
||||||
|
try {
|
||||||
|
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) {
|
||||||
|
this.Update?.Invoke(this, new Flex4gridEvent(req, response.StatusCode.ToString()));
|
||||||
|
}
|
||||||
|
} catch (Exception) { }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Interconnect(Dictionary<String, AModul> moduls) {
|
||||||
|
if (this.config.ContainsKey("f4g") && this.config["f4g"].ContainsKey("raspi")) {
|
||||||
|
foreach (KeyValuePair<String, AModul> item in moduls) {
|
||||||
|
if (item.Value is CronJob) {
|
||||||
|
item.Value.SetInterconnection("10,40 * * * *", new Action<Object>(this.RequestAlive), null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void UpdateConfig() { }
|
||||||
|
|
||||||
#region IDisposable Support
|
#region IDisposable Support
|
||||||
private Boolean disposedValue = false;
|
private Boolean disposedValue = false;
|
||||||
|
|
||||||
@@ -134,6 +186,8 @@ namespace ZwayBot.Moduls {
|
|||||||
Dispose(true);
|
Dispose(true);
|
||||||
GC.SuppressFinalize(this);
|
GC.SuppressFinalize(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,137 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
using BlubbFish.IoT.Zway;
|
||||||
|
using BlubbFish.IoT.Zway.Events;
|
||||||
|
using BlubbFish.IoT.Zway.Interfaces;
|
||||||
|
using BlubbFish.Utils;
|
||||||
|
using BlubbFish.Utils.IoT.Connector;
|
||||||
|
using LitJson;
|
||||||
|
|
||||||
|
namespace ZwayBot.Moduls {
|
||||||
|
class Mqtt : AModul, IDisposable {
|
||||||
|
private ADataBackend mqtt;
|
||||||
|
private Dictionary<String, AModul> modules;
|
||||||
|
|
||||||
|
public override event ModulEvent Update;
|
||||||
|
|
||||||
|
public Mqtt(ZwayController zway, InIReader settings) : base(zway, settings) {
|
||||||
|
if (this.config.ContainsKey("settings")) {
|
||||||
|
this.mqtt = ADataBackend.GetInstance(this.config["settings"]);
|
||||||
|
this.mqtt.MessageIncomming += this.Mqtt_MessageIncomming;
|
||||||
|
this.zw.Update += this.ZwayEvent;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ZwayEvent(Object sender, DeviceUpdateEvent e) {
|
||||||
|
String topic = "";
|
||||||
|
String data = "";
|
||||||
|
if(e.Parent.HasAbstract(typeof(ACommandClass))) {
|
||||||
|
ACommandClass sensor = (ACommandClass)e.Parent;
|
||||||
|
topic = "/zwavebot/devices/" + sensor.MqttTopic();
|
||||||
|
data = sensor.ToJson();
|
||||||
|
}
|
||||||
|
if(topic != "" && data != "") {
|
||||||
|
this.mqtt.Send(topic, data);
|
||||||
|
this.Update?.Invoke(this, new MqttEvent(topic, data));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Mqtt_MessageIncomming(Object sender, MqttEventArgs e) {
|
||||||
|
if (e.Topic.StartsWith("/zwavebot/devices/") && (e.Topic.EndsWith("/set") || e.Topic.EndsWith("/get"))) {
|
||||||
|
Match m = new Regex("^/zwavebot/devices/(\\d+)/(\\d+)/(\\d+)/[gs]et$|^/zwavebot/devices/(\\d+)/(\\d+)/(\\d+)/(\\d+)/[gs]et$").Match(e.Topic);
|
||||||
|
String id = "";
|
||||||
|
if(m.Groups[1].Success) {
|
||||||
|
id = m.Groups[1].Value + "-" + m.Groups[2].Value + "-" + m.Groups[3].Value;
|
||||||
|
}
|
||||||
|
if(m.Groups[4].Success) {
|
||||||
|
id = m.Groups[4].Value + "-" + m.Groups[5].Value + "-" + m.Groups[6].Value + "-" + m.Groups[7].Value;
|
||||||
|
}
|
||||||
|
ACommandClass c = this.zw.GetCommandClass(id);
|
||||||
|
if(c == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (e.Topic.EndsWith("/set")) {
|
||||||
|
try {
|
||||||
|
JsonData a = JsonMapper.ToObject(e.Message);
|
||||||
|
foreach (String item in a.Keys) {
|
||||||
|
String key = item.ToUpperLower();
|
||||||
|
if (c.HasProperty(key)) {
|
||||||
|
c.SetProperty(key, a[item].ToString());
|
||||||
|
this.Update?.Invoke(this, new MqttEvent(c.Id, a[item].ToString()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception) { }
|
||||||
|
} else if(e.Topic.EndsWith("/get")) {
|
||||||
|
c.PollOnce = true;
|
||||||
|
this.mqtt.Send("/zwavebot/devices/" + c.MqttTopic(), c.ToJson());
|
||||||
|
this.Update?.Invoke(this, new MqttEvent(e.Topic, "Dataget"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (e.Topic.StartsWith("/zwavebot/config/") && (e.Topic.EndsWith("/set") || e.Topic.EndsWith("/get"))) {
|
||||||
|
Match m = new Regex("^/zwavebot/config/(\\w+)/[gs]et$|").Match(e.Topic);
|
||||||
|
if (!m.Groups[1].Success) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
AModul modul = null;
|
||||||
|
foreach (KeyValuePair<String, AModul> item in this.modules) {
|
||||||
|
if (item.Key.ToLower() == m.Groups[1].Value) {
|
||||||
|
modul = item.Value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (modul == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if(e.Topic.EndsWith("/get") && modul.HasConfig && modul.ConfigPublic) {
|
||||||
|
String topic = "/zwavebot/config/" + m.Groups[1].Value;
|
||||||
|
String data = JsonMapper.ToJson(modul.GetConfig()).ToString();
|
||||||
|
this.mqtt.Send(topic, data);
|
||||||
|
this.Update?.Invoke(this, new MqttEvent(topic, data));
|
||||||
|
}
|
||||||
|
if (e.Topic.EndsWith("/set") && modul.HasConfig && modul.ConfigPublic) {
|
||||||
|
try {
|
||||||
|
JsonData a = JsonMapper.ToObject(e.Message);
|
||||||
|
Dictionary<String, Dictionary<String, String>> newconf = new Dictionary<String, Dictionary<String, String>>();
|
||||||
|
foreach (String section in a.Keys) {
|
||||||
|
Dictionary<String, String> sectiondata = new Dictionary<String, String>();
|
||||||
|
foreach (String item in a[section].Keys) {
|
||||||
|
sectiondata.Add(item, a[section][item].ToString());
|
||||||
|
}
|
||||||
|
newconf.Add(section, sectiondata);
|
||||||
|
}
|
||||||
|
modul.SetConfig(newconf);
|
||||||
|
this.Update?.Invoke(this, new MqttEvent("New Config", "Write"));
|
||||||
|
} catch (Exception) { }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Interconnect(Dictionary<String, AModul> moduls) {
|
||||||
|
this.modules = moduls;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void UpdateConfig() { }
|
||||||
|
|
||||||
|
#region IDisposable Support
|
||||||
|
private Boolean disposedValue = false;
|
||||||
|
|
||||||
|
protected virtual void Dispose(Boolean disposing) {
|
||||||
|
if (!this.disposedValue) {
|
||||||
|
if (disposing) {
|
||||||
|
this.mqtt.Dispose();
|
||||||
|
}
|
||||||
|
this.disposedValue = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
~Mqtt() {
|
||||||
|
Dispose(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Dispose() {
|
||||||
|
Dispose(true);
|
||||||
|
GC.SuppressFinalize(this);
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -16,22 +16,12 @@ namespace ZwayBot.Moduls {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void ParseIni() {
|
private void ParseIni() {
|
||||||
foreach (String item in this.ini.GetSections()) {
|
foreach (KeyValuePair<String, Dictionary<String, String>> item in this.config) {
|
||||||
String from = this.ini.GetValue(item, "from");
|
if (item.Value.ContainsKey("from")) {
|
||||||
|
String from = item.Value["from"];
|
||||||
String[] source = from.Split(':');
|
String[] source = from.Split(':');
|
||||||
this.events.Add(source[0], this.ini.GetSection(item));
|
this.events.Add(source[0], item.Value);
|
||||||
String[] addr = source[0].Split('-');
|
ACommandClass c = this.zw.GetCommandClass(source[0]);
|
||||||
ICommandClass c;
|
|
||||||
if (addr.Length == 3 || addr.Length == 4) {
|
|
||||||
Int32 deviceid = Int32.Parse(addr[0]);
|
|
||||||
Int32 instanceid = Int32.Parse(addr[1]);
|
|
||||||
Int32 classid = Int32.Parse(addr[2]);
|
|
||||||
if (addr.Length == 4) {
|
|
||||||
Int32 subcid = Int32.Parse(addr[3]);
|
|
||||||
c = this.zw.GetCommandClassSub(deviceid, instanceid, classid, subcid);
|
|
||||||
} else {
|
|
||||||
c = this.zw.GetCommandClass(deviceid, instanceid, classid);
|
|
||||||
}
|
|
||||||
if (c != null) {
|
if (c != null) {
|
||||||
c.Polling = true;
|
c.Polling = true;
|
||||||
c.Update += this.ChangedEvent;
|
c.Update += this.ChangedEvent;
|
||||||
@@ -41,9 +31,9 @@ namespace ZwayBot.Moduls {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void ChangedEvent(Object sender, DeviceUpdateEvent e) {
|
private void ChangedEvent(Object sender, DeviceUpdateEvent e) {
|
||||||
if(Helper.HasInterface(sender, "ICommandClass")) {
|
if(sender.HasAbstract(typeof(ACommandClass))) {
|
||||||
if (this.events.ContainsKey(((ICommandClass)sender).Id)) {
|
if (this.events.ContainsKey(((ACommandClass)sender).Id)) {
|
||||||
this.SetValues(sender, ((ICommandClass)sender).Id, this.events[((ICommandClass)sender).Id]);
|
this.SetValues(sender, ((ACommandClass)sender).Id, this.events[((ACommandClass)sender).Id]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -55,8 +45,8 @@ namespace ZwayBot.Moduls {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
String source_value;
|
String source_value;
|
||||||
if (Helper.HasProperty(sender, source[1])) {
|
if (sender.HasProperty(source[1])) {
|
||||||
source_value = Helper.GetProperty(sender, source[1]).ToString();
|
source_value = sender.GetProperty(source[1]).ToString();
|
||||||
} else {
|
} else {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -68,27 +58,15 @@ namespace ZwayBot.Moduls {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (dictionary.ContainsKey("to")) {
|
||||||
foreach (String to in dictionary["to"].Split(';')) {
|
foreach (String to in dictionary["to"].Split(';')) {
|
||||||
String[] target = to.Split(':');
|
String[] target = to.Split(':');
|
||||||
if(target.Length == 2) {
|
if (target.Length == 2) {
|
||||||
String[] addr = target[0].Split('-');
|
ACommandClass c = this.zw.GetCommandClass(target[0]);
|
||||||
if (addr.Length == 3 || addr.Length == 4) {
|
|
||||||
Int32 deviceid = Int32.Parse(addr[0]);
|
|
||||||
Int32 instanceid = Int32.Parse(addr[1]);
|
|
||||||
Int32 classid = Int32.Parse(addr[2]);
|
|
||||||
ICommandClass c;
|
|
||||||
if (addr.Length == 4) {
|
|
||||||
Int32 subcid = Int32.Parse(addr[3]);
|
|
||||||
c = this.zw.GetCommandClassSub(deviceid, instanceid, classid, subcid);
|
|
||||||
} else {
|
|
||||||
c = this.zw.GetCommandClass(deviceid, instanceid, classid);
|
|
||||||
}
|
|
||||||
if (c != null) {
|
if (c != null) {
|
||||||
String target_value;
|
if (c.HasProperty(target[1])) {
|
||||||
if (Helper.HasProperty(c, target[1])) {
|
if (c.GetProperty(target[1]).ToString() != source_value) {
|
||||||
target_value = Helper.GetProperty(c, target[1]).ToString();
|
c.SetProperty(target[1], source_value);
|
||||||
if (target_value != source_value) {
|
|
||||||
Helper.SetProperty(c, target[1], source_value);
|
|
||||||
this.Update?.Invoke(this, new OvertakerEvent(target[0], target[1], source_value));
|
this.Update?.Invoke(this, new OvertakerEvent(target[0], target[1], source_value));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -98,6 +76,8 @@ namespace ZwayBot.Moduls {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected override void UpdateConfig() { }
|
||||||
|
|
||||||
#region IDisposable Support
|
#region IDisposable Support
|
||||||
private Boolean disposedValue = false;
|
private Boolean disposedValue = false;
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,60 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using BlubbFish.IoT.Zway;
|
||||||
|
using BlubbFish.IoT.Zway.Devices;
|
||||||
|
using BlubbFish.IoT.Zway.Interfaces;
|
||||||
|
using BlubbFish.Utils;
|
||||||
|
using ZwayBot.Interfaces;
|
||||||
|
|
||||||
|
namespace ZwayBot.Moduls {
|
||||||
|
class Statuspolling : AModul, IDisposable, IForceLoad {
|
||||||
|
public override event ModulEvent Update;
|
||||||
|
|
||||||
|
public Statuspolling(ZwayController zway, InIReader settings) : base(zway, settings) { }
|
||||||
|
|
||||||
|
|
||||||
|
public override void Interconnect(Dictionary<String, AModul> moduls) {
|
||||||
|
foreach (KeyValuePair<String, AModul> item in moduls) {
|
||||||
|
if (item.Value is CronJob) {
|
||||||
|
item.Value.SetInterconnection("0 0 * * *", new Action<Object>(this.PollAll), null);
|
||||||
|
if (this.config.Count != 0) {
|
||||||
|
foreach (KeyValuePair<String, Dictionary<String, String>> section in this.config) {
|
||||||
|
if (section.Value.ContainsKey("cron") && section.Value.ContainsKey("devices")) {
|
||||||
|
item.Value.SetInterconnection(section.Value["cron"], new Action<Object>(this.PollSpecific), section.Value["devices"]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void PollSpecific(Object obj) {
|
||||||
|
String devices = (String)obj;
|
||||||
|
foreach (String item in devices.Split(',')) {
|
||||||
|
ACommandClass c = this.zw.GetCommandClass(item);
|
||||||
|
c.PollOnce = true;
|
||||||
|
this.Update?.Invoke(this, new StatusPollingEvent("Polling", item));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void PollAll(Object o) {
|
||||||
|
foreach (KeyValuePair<Int32, Device> device in this.zw.Devices) {
|
||||||
|
foreach (KeyValuePair<Int32, Instance> instance in device.Value.Instances) {
|
||||||
|
foreach (KeyValuePair<ACommandClass.Classes, ACommandClass> commandclass in instance.Value.CommandClasses) {
|
||||||
|
commandclass.Value.PollOnce = true;
|
||||||
|
if(commandclass.Value.HasSub) {
|
||||||
|
foreach (KeyValuePair<Int32, ACommandClass> subclass in commandclass.Value.Sub) {
|
||||||
|
subclass.Value.PollOnce = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.Update?.Invoke(this, new StatusPollingEvent("Polling", "all nodes"));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void UpdateConfig() { }
|
||||||
|
|
||||||
|
public override void Dispose() {}
|
||||||
|
}
|
||||||
|
}
|
||||||
+10
-1
@@ -4,7 +4,6 @@ using System.IO;
|
|||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using BlubbFish.IoT.Zway;
|
using BlubbFish.IoT.Zway;
|
||||||
using BlubbFish.Utils;
|
using BlubbFish.Utils;
|
||||||
using ZwayBot.Moduls;
|
|
||||||
|
|
||||||
namespace ZwayBot {
|
namespace ZwayBot {
|
||||||
class Program {
|
class Program {
|
||||||
@@ -27,11 +26,18 @@ namespace ZwayBot {
|
|||||||
this.zw = new ZwayController(InIReader.GetInstance("settings.ini").GetSection("zway"), names, false);
|
this.zw = new ZwayController(InIReader.GetInstance("settings.ini").GetSection("zway"), names, false);
|
||||||
this.zw.Update += this.ZwayDataUpate;
|
this.zw.Update += this.ZwayDataUpate;
|
||||||
this.ModulLoader();
|
this.ModulLoader();
|
||||||
|
this.ModulInterconnect();
|
||||||
this.ModulEvents();
|
this.ModulEvents();
|
||||||
this.WaitForShutdown();
|
this.WaitForShutdown();
|
||||||
this.ModulDispose();
|
this.ModulDispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void ModulInterconnect() {
|
||||||
|
foreach (KeyValuePair<String, AModul> item in this.moduls) {
|
||||||
|
item.Value.Interconnect(this.moduls);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void WaitForShutdown() {
|
private void WaitForShutdown() {
|
||||||
while (true) {
|
while (true) {
|
||||||
System.Threading.Thread.Sleep(100);
|
System.Threading.Thread.Sleep(100);
|
||||||
@@ -71,6 +77,9 @@ namespace ZwayBot {
|
|||||||
if (File.Exists(name.ToLower() + ".ini")) {
|
if (File.Exists(name.ToLower() + ".ini")) {
|
||||||
this.moduls.Add(name, (AModul)t.GetConstructor(new Type[] { typeof(ZwayController), typeof(InIReader) }).Invoke(new Object[] { this.zw, InIReader.GetInstance(name.ToLower() + ".ini") }));
|
this.moduls.Add(name, (AModul)t.GetConstructor(new Type[] { typeof(ZwayController), typeof(InIReader) }).Invoke(new Object[] { this.zw, InIReader.GetInstance(name.ToLower() + ".ini") }));
|
||||||
Console.WriteLine("Load Modul " + name);
|
Console.WriteLine("Load Modul " + name);
|
||||||
|
} else if(t.HasInterface("IForceLoad")) {
|
||||||
|
this.moduls.Add(name, (AModul)t.GetConstructor(new Type[] { typeof(ZwayController), typeof(InIReader) }).Invoke(new Object[] { this.zw, null }));
|
||||||
|
Console.WriteLine("Load Modul Forced " + name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,17 +1,17 @@
|
|||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Resources;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
// Allgemeine Informationen über eine Assembly werden über die folgenden
|
// Allgemeine Informationen über eine Assembly werden über die folgenden
|
||||||
// Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern,
|
// Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern,
|
||||||
// die einer Assembly zugeordnet sind.
|
// die einer Assembly zugeordnet sind.
|
||||||
[assembly: AssemblyTitle("Zway-Bot")]
|
[assembly: AssemblyTitle("Zway-Bot")]
|
||||||
[assembly: AssemblyDescription("")]
|
[assembly: AssemblyDescription("Is a Bot for Zwave Devices")]
|
||||||
[assembly: AssemblyConfiguration("")]
|
[assembly: AssemblyConfiguration("")]
|
||||||
[assembly: AssemblyCompany("")]
|
[assembly: AssemblyCompany("BlubbFish")]
|
||||||
[assembly: AssemblyProduct("Zway-Bot")]
|
[assembly: AssemblyProduct("Zway-Bot")]
|
||||||
[assembly: AssemblyCopyright("Copyright © 2017")]
|
[assembly: AssemblyCopyright("Copyright © 2017 - 22.12.2017")]
|
||||||
[assembly: AssemblyTrademark("")]
|
[assembly: AssemblyTrademark("BlubbFish")]
|
||||||
[assembly: AssemblyCulture("")]
|
[assembly: AssemblyCulture("")]
|
||||||
|
|
||||||
// Durch Festlegen von ComVisible auf FALSE werden die Typen in dieser Assembly
|
// Durch Festlegen von ComVisible auf FALSE werden die Typen in dieser Assembly
|
||||||
@@ -32,7 +32,8 @@ using System.Runtime.InteropServices;
|
|||||||
// Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden,
|
// Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden,
|
||||||
// übernehmen, indem Sie "*" eingeben:
|
// übernehmen, indem Sie "*" eingeben:
|
||||||
// [assembly: AssemblyVersion("1.0.*")]
|
// [assembly: AssemblyVersion("1.0.*")]
|
||||||
[assembly: AssemblyVersion("1.0.0.0")]
|
[assembly: AssemblyVersion("1.3.0.0")]
|
||||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
[assembly: AssemblyFileVersion("1.3.0.0")]
|
||||||
|
[assembly: NeutralResourcesLanguage("de-DE")]
|
||||||
|
|
||||||
// “Internet Of Things” icon by By Michael Wohlwend, US, from thenounproject.com.
|
// “Internet Of Things” icon by By Michael Wohlwend, US, from thenounproject.com.
|
||||||
|
|||||||
@@ -54,11 +54,14 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="Events.cs" />
|
<Compile Include="Events.cs" />
|
||||||
|
<Compile Include="Interfaces\IForceLoad.cs" />
|
||||||
<Compile Include="Moduls\AModul.cs" />
|
<Compile Include="Moduls\AModul.cs" />
|
||||||
<Compile Include="Moduls\CronJob.cs" />
|
<Compile Include="Moduls\CronJob.cs" />
|
||||||
<Compile Include="Helper.cs" />
|
<Compile Include="Helper.cs" />
|
||||||
<Compile Include="Moduls\Flex4Grid.cs" />
|
<Compile Include="Moduls\Flex4Grid.cs" />
|
||||||
|
<Compile Include="Moduls\Mqtt.cs" />
|
||||||
<Compile Include="Moduls\Overtaker.cs" />
|
<Compile Include="Moduls\Overtaker.cs" />
|
||||||
|
<Compile Include="Moduls\StatusPolling.cs" />
|
||||||
<Compile Include="Program.cs" />
|
<Compile Include="Program.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
<Compile Include="Properties\Resources.Designer.cs">
|
<Compile Include="Properties\Resources.Designer.cs">
|
||||||
@@ -72,6 +75,10 @@
|
|||||||
<Project>{39235fad-ba9d-4b51-82fc-6969967beae9}</Project>
|
<Project>{39235fad-ba9d-4b51-82fc-6969967beae9}</Project>
|
||||||
<Name>ConnectorDataMosquitto</Name>
|
<Name>ConnectorDataMosquitto</Name>
|
||||||
</ProjectReference>
|
</ProjectReference>
|
||||||
|
<ProjectReference Include="..\..\Utils\IoT\Connector\Data\Mqtt\ConnectorDataMqtt.csproj">
|
||||||
|
<Project>{ee6c8f68-ed46-4c1c-abdd-cfcdf75104f2}</Project>
|
||||||
|
<Name>ConnectorDataMqtt</Name>
|
||||||
|
</ProjectReference>
|
||||||
<ProjectReference Include="..\..\Utils\IoT\Utils-IoT.csproj">
|
<ProjectReference Include="..\..\Utils\IoT\Utils-IoT.csproj">
|
||||||
<Project>{b870e4d5-6806-4a0b-b233-8907eedc5afc}</Project>
|
<Project>{b870e4d5-6806-4a0b-b233-8907eedc5afc}</Project>
|
||||||
<Name>Utils-IoT</Name>
|
<Name>Utils-IoT</Name>
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user