Exemple #1
0
        public override string PostBackProc(string page, string data, string user, int userRights)
        {
            Program.WriteLog(LogType.Debug, $"PostBackProc page name {page} by user {user} with rights {userRights}");
            if (page != "IdleLightColorsSettings")
            {
                return("Unknown page " + page);
            }

            if ((userRights & 2) != 2)
            {
                return("Access denied: you are not an administrative user.");
            }

            NameValueCollection postData = HttpUtility.ParseQueryString(data);

            string activeColor = postData.Get("ActiveColor");
            string idleColor   = postData.Get("IdleColor");

            hs.SaveINISetting("Colors", "active_color", activeColor, IniFilename);
            hs.SaveINISetting("Colors", "idle_color", idleColor, IniFilename);
            onColor  = (WD200NormalModeColor)int.Parse(activeColor);
            offColor = (WD200NormalModeColor)int.Parse(idleColor);

            if (haveDoneInitialUpdate)
            {
                UpdateAllDimmers();
            }

            return("");
        }
Exemple #2
0
        private void UpdateDimmerForStatus(DimmerDevice dimmerDevice, double value)
        {
            WD200NormalModeColor newColor = Math.Abs(value) < 0.1 ? offColor : onColor;

            HSPI_ZWave.HSPI.ConfigResult result = SetDeviceNormalModeColor(dimmerDevice.HomeID, dimmerDevice.NodeID, newColor);
            Program.WriteLog(LogType.Info, string.Format(
                                 "Setting normal mode color for device {0} (node ID {1}) to {2}; result: {3}",
                                 dimmerDevice.SwitchMultiLevelDeviceRef,
                                 dimmerDevice.NodeID,
                                 newColor,
                                 result
                                 ));
        }
Exemple #3
0
        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("");
        }
Exemple #4
0
 private HSPI_ZWave.HSPI.ConfigResult SetDeviceNormalModeColor(string homeID, byte nodeID, WD200NormalModeColor color)
 {
     return((HSPI_ZWave.HSPI.ConfigResult)hs.PluginFunction("Z-Wave", "", "Configuration_Set", new object[] {
         homeID,
         nodeID,
         (byte)WD200ConfigParam.NormalModeLedColor,
         (byte)1,                  // length of value in bytes, I assume
         (int)color
     }));
 }
Exemple #5
0
 private static void BuildColorDropdown(string pageName, clsJQuery.jqDropList dropdown, WD200NormalModeColor selectedColor)
 {
     foreach (int i in Enum.GetValues(typeof(WD200NormalModeColor)))
     {
         dropdown.AddItem(((WD200NormalModeColor)i).ToString(), i.ToString(), (int)selectedColor == i);
     }
 }