public void Initialize() { Dictionary <int, Scheduler.Classes.DeviceClass> device_map = new Dictionary <int, Scheduler.Classes.DeviceClass>(); Dictionary <int, bool> processed = new Dictionary <int, bool>(); Scheduler.Classes.clsDeviceEnumeration devenum = HS.GetDeviceEnumerator() as Scheduler.Classes.clsDeviceEnumeration; while (!devenum.Finished) { Scheduler.Classes.DeviceClass dev = devenum.GetNext(); if (dev.get_Interface(null) != Constants.PLUGIN_STRING_NAME) { continue; // Not ours! } var extraData = dev.get_PlugExtraData_Get(HS); if (extraData == null) { extraData = new PlugExtraData.clsPlugExtraData(); } var typeStr = (string)extraData.GetNamed("EnOcean Type"); if (typeStr == null) { continue; // No type - continue } if (typeStr != "Controller") { continue; // Not a controller } var dataStr = (string)extraData.GetNamed("EnOcean Cfg"); if (dataStr == null) { Console.WriteLine("No json data on device - skipping"); // extraData.AddNamed("EnOcean Cfg", config.ToString()); // rootDev.set_PlugExtraData_Set(HS, extraData); continue; // Skip interface } else { var config = JObject.Parse(dataStr); Console.WriteLine("Loaded config: {0}", config.ToString()); var ctrlInstance = new EnOceanController(HS, HSCB, hspiInst, config); ctrlInstance.Initialize(); AddInterface(ctrlInstance); } } }
private List <SiidDevice> GetDevices(InstanceHolder Instance) { List <SiidDevice> AssociatedDevices = new List <SiidDevice>(); Scheduler.Classes.clsDeviceEnumeration DevNum = (Scheduler.Classes.clsDeviceEnumeration)Instance.host.GetDeviceEnumerator(); var Dev = DevNum.GetNext(); while (Dev != null) { if ((Dev.get_Interface(Instance.host).ToString() == Util.IFACE_NAME.ToString()) && (Dev.get_InterfaceInstance(Instance.host) == Instance.name)) { AssociatedDevices.Add(new SiidDevice(Instance, Dev)); } Dev = DevNum.GetNext(); } return(AssociatedDevices); }
public Scheduler.Classes.DeviceClass getHSDevice(EnOceanDeviceType type, string id = "") { Scheduler.Classes.clsDeviceEnumeration devenum = HS.GetDeviceEnumerator() as Scheduler.Classes.clsDeviceEnumeration; while (!devenum.Finished) { Scheduler.Classes.DeviceClass dev = devenum.GetNext(); if (dev.get_Interface(null) != Constants.PLUGIN_STRING_NAME) { continue; // Not ours! } if (dev.get_Device_Type_String(null) == "EnOcean " + type.ToString()) { string hsAddr = dev.get_Address(null); //FIXME: Should probably not use address but a plugin value! if (id == hsAddr) { return(dev); } } } return(null); }
/// <summary> /// Initialize the plugin and associated hardware/software, start any threads /// </summary> /// <param name="port">The COM port for the plugin if required.</param> /// <returns>Warning message or empty for success.</returns> public override string InitIO(string port) { // initialize everything here, return a blank string only if successful, or an error message try { Scheduler.Classes.clsDeviceEnumeration EN = (Scheduler.Classes.clsDeviceEnumeration)hs.GetDeviceEnumerator(); if (EN == null) { throw new Exception(IFACE_NAME + " failed to get a device enumerator from HomeSeer."); } do { Scheduler.Classes.DeviceClass dv = EN.GetNext(); if ((dv != null) && (dv.get_Interface(hs) != null) && (dv.get_Interface(hs).Trim() == IFACE_NAME)) { //Console.WriteLine("Found device: refId = {0}", dv.get_Ref(hs)); int refId = dv.get_Ref(hs); string ipAddress = hs.GetINISetting("Camera" + refId, "IpAddress", "", INI_File); string username = hs.GetINISetting("Camera" + refId, "Username", "", INI_File); string password = hs.GetINISetting("Camera" + refId, "Password", "", INI_File); Console.WriteLine("Camera: RefId: {0}, IpAddress: {1}, Username: {2}, Password: {3}", refId, ipAddress, username, password); HikAlarmThreadManager.AddDevice(this, refId, ipAddress, username, password); } } while (!EN.Finished); } catch (Exception ex) { hs.WriteLog(IFACE_NAME + " Error", "Exception in Find_Create_Devices/Enumerator: " + ex.Message); } // Create and register the web pages - only need one for configuration configPage = new HikAlarmConfig(this); RegisterWebPage(configPage.Name); return(""); }
void LoadChildDevices() { Scheduler.Classes.clsDeviceEnumeration devenum = HS.GetDeviceEnumerator() as Scheduler.Classes.clsDeviceEnumeration; while (!devenum.Finished) { Scheduler.Classes.DeviceClass hsDev = devenum.GetNext(); if (hsDev.get_Interface(null) != Constants.PLUGIN_STRING_NAME) { continue; // Not ours! } var extraData = hsDev.get_PlugExtraData_Get(HS); if (extraData == null) { extraData = new PlugExtraData.clsPlugExtraData(); } var typeStr = (string)extraData.GetNamed("EnOcean Type"); // if (typeStr == null) // Console.WriteLine("Warning: No device type set on child device"); var dataStr = (string)extraData.GetNamed("EnOcean Cfg"); var childConfig = new JObject(); if (dataStr != null) { childConfig = JObject.Parse(dataStr); } if (hsDev.get_Address(null).StartsWith(ControllerId)) { // Console.WriteLine("DT : {0} vs {1}", hsDev.get_Device_Type_String(null), EnOceanDeviceType.SimpleDevice.ToString()); if (hsDev.get_Device_Type_String(null) != "EnOcean " + EnOceanDeviceType.SimpleDevice.ToString()) { continue; } DeviceTypes.CreateDeviceInstance(HS, this, hsDev.get_Address(null), (string)childConfig["device_type"], childConfig); Console.WriteLine("Found child device: {0}", hsDev.get_Address(null)); } } }