private void cacheDeviceList() { Program.WriteLog(LogType.Debug, "Caching device list"); List <DeviceData> devices = new List <DeviceData>(); clsDeviceEnumeration enumerator = (clsDeviceEnumeration)hs.GetDeviceEnumerator(); do { DeviceClass device = enumerator.GetNext(); if (device != null) { devices.Add(new DeviceData { DevRef = device.get_Ref(hs), Name = device.get_Location2(hs) + " " + device.get_Location(hs) + " " + device.get_Name(hs), }); } } while (!enumerator.Finished); Program.WriteLog(LogType.Debug, "Device list cached successfully"); this.devices = devices.OrderBy(d => d.Name).ToList(); }
public override string InitIO(string port) { Program.WriteLog(LogType.Verbose, "InitIO"); dimmersByRef = new Dictionary <int, DimmerDevice>(); haveDoneInitialUpdate = false; Dictionary <byte, DimmerDevice> dict = new Dictionary <byte, DimmerDevice>(); clsDeviceEnumeration enumerator = (clsDeviceEnumeration)hs.GetDeviceEnumerator(); do { DeviceClass device = enumerator.GetNext(); if (device != null) { if (device.get_Interface(hs) != "Z-Wave") { continue; } // It's a Z-Wave device PlugExtraData.clsPlugExtraData extraData = device.get_PlugExtraData_Get(hs); string[] addressParts = device.get_Address(hs).Split('-'); byte nodeId = byte.Parse(addressParts[1]); if (dict.ContainsKey(nodeId)) { continue; } if (DeviceIsDimmer(extraData)) { DimmerDevice dimmerDevice = new DimmerDevice { HomeID = addressParts[0], NodeID = nodeId, SwitchMultiLevelDeviceRef = device.get_Ref(hs) }; dict[nodeId] = dimmerDevice; dimmersByRef[dimmerDevice.SwitchMultiLevelDeviceRef] = dimmerDevice; } } } while (!enumerator.Finished); callbacks.RegisterEventCB(HomeSeerAPI.Enums.HSEvent.VALUE_SET, Name, InstanceFriendlyName()); callbacks.RegisterEventCB(HomeSeerAPI.Enums.HSEvent.VALUE_CHANGE, Name, InstanceFriendlyName()); hs.RegisterPage("IdleLightColorsSettings", Name, InstanceFriendlyName()); WebPageDesc configLink = new WebPageDesc { plugInName = Name, link = "IdleLightColorsSettings", linktext = "Settings", order = 1, page_title = "HS-WD200+ Idle Light Colors Settings", plugInInstance = InstanceFriendlyName() }; callbacks.RegisterConfigLink(configLink); callbacks.RegisterLink(configLink); offColor = (WD200NormalModeColor)int.Parse(hs.GetINISetting("Colors", "idle_color", ((int)WD200NormalModeColor.Blue).ToString(), IniFilename)); onColor = (WD200NormalModeColor)int.Parse(hs.GetINISetting("Colors", "active_color", ((int)WD200NormalModeColor.White).ToString(), IniFilename)); Program.WriteLog(LogType.Info, string.Format( "Init complete. Active color: {0}. Idle color: {1}. Found {2} dimmers with node IDs: {3}", onColor, offColor, dimmersByRef.Keys.Count, string.Join(", ", dimmersByRef.Values.Select(dimmerDevice => dimmerDevice.NodeID)) )); return(""); }