[NF] Able to force loading modules, so dependencys are ok [NF] Cleanup because its now easyer to implement Zway
59 lines
2.2 KiB
C#
59 lines
2.2 KiB
C#
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.ini != null) {
|
|
foreach (String section in this.ini.GetSections()) {
|
|
if (this.ini.GetValue(section, "cron") != null && this.ini.GetValue(section, "devices") != null) {
|
|
item.Value.SetInterconnection(this.ini.GetValue(section, "cron"), new Action<Object>(this.PollSpecific), this.ini.GetValue(section, "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"));
|
|
}
|
|
|
|
public override void Dispose() {}
|
|
}
|
|
}
|