protected void UpdateFirstNodeAsNumber(IHSApplication HS, DeviceClass device, [AllowNull] XPathNodeIterator value) { double?data = null; if ((value != null) && (value.MoveNext())) { string text = value.Current.ToString().Trim(new char[] { '%', ' ' }); if (double.TryParse(text, NumberStyles.Any, CultureInfo.InvariantCulture, out double doubleValue)) { if (!inValidValues.Contains(doubleValue)) { data = doubleValue; } else { Trace.WriteLine(Invariant($"Device {Name} Address [{device.get_Address(null)}] has invalid Value {doubleValue}")); } } else { Trace.WriteLine(Invariant($"Device {Name} Address [{device.get_Address(null)}] has Non-Double Value:[{text}]")); } } else { Trace.WriteLine(Invariant($"No node value found for {Name} Address [{device.get_Address(null)}]")); } UpdateDeviceData(HS, device, data); }
public void TryFindChildren() { if (Root == 0) { return; } IHSApplication hs = _plugin.hs; DeviceClass root = (DeviceClass)hs.GetDeviceByRef(Root); foreach (int childRef in root.get_AssociatedDevices(hs)) { DeviceClass child = (DeviceClass)hs.GetDeviceByRef(childRef); SubDeviceType subType = (SubDeviceType)int.Parse(child.get_Address(hs).Split('-')[1]); switch (subType) { case SubDeviceType.Brightness: Brightness = childRef; break; case SubDeviceType.Color: Color = childRef; break; case SubDeviceType.Temperature: Temperature = childRef; break; } } }
private NameValueCollection GetCurrentDeviceImportDevices() { HSHelper hsHelper = new HSHelper(HS); var deviceEnumerator = HS.GetDeviceEnumerator() as clsDeviceEnumeration; var currentDevices = new NameValueCollection(); var importDevicesData = pluginConfig.ImportDevicesData; do { DeviceClass device = deviceEnumerator.GetNext(); if ((device != null) && (device.get_Interface(HS) != null) && (device.get_Interface(HS).Trim() == PlugInData.PlugInName)) { string address = device.get_Address(HS); var childDeviceData = DeviceIdentifier.Identify(device); if (childDeviceData != null) { if (pluginConfig.ImportDevicesData.TryGetValue(childDeviceData.DeviceId, out var importDeviceData)) { currentDevices.Add(device.get_Ref(HS).ToString(CultureInfo.CurrentCulture), hsHelper.GetName(device)); } } } } while (!deviceEnumerator.Finished); return(currentDevices); }
/// <summary> /// Gets the current devices for plugin from Homeseer /// </summary> /// <returns>Current devices for plugin</returns> /// <exception cref="HspiException"></exception> private IDictionary <string, DeviceClass> GetCurrentDevices() { var deviceEnumerator = HS.GetDeviceEnumerator() as clsDeviceEnumeration; if (deviceEnumerator == null) { throw new HspiException(Invariant($"{Name} failed to get a device enumerator from HomeSeer.")); } var currentDevices = new Dictionary <string, DeviceClass>(); do { CancellationToken.ThrowIfCancellationRequested(); DeviceClass device = deviceEnumerator.GetNext(); if ((device != null) && (device.get_Interface(HS) != null) && (device.get_Interface(HS).Trim() == Name)) { string address = device.get_Address(HS); currentDevices.Add(address, device); } } while (!deviceEnumerator.Finished); return(currentDevices); }
private void GetCurrentDevices() { if (!(HS.GetDeviceEnumerator() is clsDeviceEnumeration deviceEnumerator)) { throw new HspiException(Invariant($"{PluginData.PlugInName} failed to get a device enumerator from HomeSeer.")); } string baseAddress = DeviceIdentifier.CreateDeviceIdSpecficAddress(CameraSettings.Id); do { DeviceClass device = deviceEnumerator.GetNext(); if ((device != null) && (device.get_Interface(HS) != null) && string.Equals(device.get_Interface(HS).Trim(), PluginData.PlugInName, StringComparison.Ordinal)) { string address = device.get_Address(HS); if (address.StartsWith(baseAddress, StringComparison.Ordinal)) { var deviceData = GetDeviceData(device); if (deviceData != null) { devices.Add(address, deviceData); deviceData.OnPlugInLoad(HS, CameraSettings); if (deviceData.IsRootDevice) { parentRefId = device.get_Ref(HS); } } } } } while (!deviceEnumerator.Finished); }
private void GetCurrentDevices() { var deviceEnumerator = HS.GetDeviceEnumerator() as clsDeviceEnumeration; if (deviceEnumerator == null) { throw new HspiException(Invariant($"{PluginData.PlugInName} failed to get a device enumerator from HomeSeer.")); } string parentAddress = DeviceIdentifier.CreateRootAddress(rootDeviceId); do { DeviceClass device = deviceEnumerator.GetNext(); if ((device != null) && (device.get_Interface(HS) != null) && (device.get_Interface(HS).Trim() == PluginData.PlugInName)) { string address = device.get_Address(HS); if (address == parentAddress) { parentRefId = device.get_Ref(HS); } else if (address.StartsWith(parentAddress, StringComparison.Ordinal)) { DeviceData childDeviceData = GetDeviceData(device); if (childDeviceData != null) { currentChildDevices.Add(address, childDeviceData); } } } } while (!deviceEnumerator.Finished); }
public static DeviceIdentifier Identify(DeviceClass hsDevice) { var childAddress = hsDevice.get_Address(null); var parts = childAddress.Split(AddressSeparator); if (parts.Length != 4) { return(null); } DeviceType?deviceType = ParseDeviceType(parts[2]); if (deviceType == null) { return(null); } string deviceTypeData = parts[3]; if (deviceTypeData == null) { return(null); } return(new DeviceIdentifier(parts[1], deviceType.Value, deviceTypeData)); }
/// <summary> /// Updates the device data from number data /// </summary> /// <param name="HS">Homeseer application.</param> /// <param name="device">The device to update.</param> /// <param name="data">Number data.</param> protected void UpdateDeviceData(IHSApplication HS, DeviceClass device, double?data) { int refId = device.get_Ref(HS); if (data.HasValue) { Trace.WriteLine(Invariant($"Updating {Name} Address [{device.get_Address(null)}] to [{data.Value}]")); HS.set_DeviceInvalidValue(refId, false); HS.SetDeviceValueByRef(refId, data.Value, true); } else { // do not update double value on no value. Trace.WriteLine(Invariant($"Updating {Name} Address [{device.get_Address(null)}] to Invalid Value")); HS.set_DeviceInvalidValue(refId, true); } }
/// <summary> /// Updates the device data from string data /// </summary> /// <param name="HS">Homeseer application.</param> /// <param name="device">The device to update.</param> /// <param name="data">string data.</param> protected void UpdateDeviceData(IHSApplication HS, DeviceClass device, [AllowNull] string data) { Trace.WriteLine(Invariant($"Updating {Name} Address [{device.get_Address(null)}] to [{data ?? "<NULL>"}]")); int refId = device.get_Ref(HS); HS.set_DeviceInvalidValue(refId, false); HS.SetDeviceString(refId, data, true); }
public static DeviceIdentifier Identify(DeviceClass hsDevice) { var childAddress = hsDevice.get_Address(null); var parts = childAddress.Split(AddressSeparator); if (parts.Length != 2) { return(null); } return(new DeviceIdentifier(parts[1])); }
protected void UpdateFirstNodeAsText(IHSApplication HS, DeviceClass device, [AllowNull] XPathNodeIterator value) { string stringValue = null; if ((value != null) && (value.MoveNext())) { stringValue = value.Current.ToString(); } else { Trace.WriteLine(Invariant($"No node value found for {Name} Address [{device.get_Address(null)}]")); } UpdateDeviceData(HS, device, stringValue); }
private HSDevices GetCurrentDevices() { var deviceEnumerator = HS.GetDeviceEnumerator() as clsDeviceEnumeration; if (deviceEnumerator == null) { throw new HspiException(Invariant($"{PlugInData.PlugInName} failed to get a device enumerator from HomeSeer.")); } int?parentRefId = null; var currentChildDevices = new Dictionary <int, DeviceData>(); string parentAddress = DeviceIdentifier.CreateRootAddress(); do { DeviceClass device = deviceEnumerator.GetNext(); if ((device != null) && (device.get_Interface(HS) != null) && (device.get_Interface(HS).Trim() == PlugInData.PlugInName)) { string address = device.get_Address(HS); if (address == parentAddress) { parentRefId = device.get_Ref(HS); } else { var childDeviceData = DeviceIdentifier.Identify(device); if (childDeviceData != null) { if (importDevicesData.TryGetValue(childDeviceData.DeviceId, out var importDeviceData)) { device.set_Status_Support(HS, true); currentChildDevices.Add(device.get_Ref(HS), new NumberDeviceData(importDeviceData)); } } } } } while (!deviceEnumerator.Finished); return(new HSDevices() { ParentRefId = parentRefId, Children = currentChildDevices, }); }
public static DeviceIdentifier Identify(DeviceClass hsDevice) { var childAddress = hsDevice.get_Address(null); var parts = childAddress.Split(AddressSeparator); if (parts.Length != 3) { return(null); } if (!Enum.TryParse(parts[2], out DeviceType deviceType)) { return(null); } return(new DeviceIdentifier(parts[1], deviceType)); }
public static DeviceIdentifier Identify(DeviceClass hsDevice) { var childAddress = hsDevice.get_Address(null); var parts = childAddress.Split(AddressSeparator); if (parts.Length != 4) { return(null); } if (!int.TryParse(parts[2], NumberStyles.Any, CultureInfo.InvariantCulture, out int port)) { return(null); } if (!Enum.TryParse(parts[3], out DeviceType deviceType)) { return(null); } return(new DeviceIdentifier(parts[1], port, deviceType)); }
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(""); }