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 moduls) { foreach (KeyValuePair item in moduls) { if (item.Value is CronJob) { item.Value.SetInterconnection("0 0 * * *", new Action(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(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 device in this.zw.Devices) { foreach (KeyValuePair instance in device.Value.Instances) { foreach (KeyValuePair commandclass in instance.Value.CommandClasses) { commandclass.Value.PollOnce = true; if(commandclass.Value.HasSub) { foreach (KeyValuePair subclass in commandclass.Value.Sub) { subclass.Value.PollOnce = true; } } } } } this.Update?.Invoke(this, new StatusPollingEvent("Polling", "all nodes")); } public override void Dispose() {} } }