Exemple #1
0
        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;
                }
            }
        }
Exemple #2
0
        public void UpdateName(string label)
        {
            IHSApplication hs = _plugin.hs;

            ((DeviceClass)hs.GetDeviceByRef(Root)).set_Name(hs, label);
            ((DeviceClass)hs.GetDeviceByRef(Brightness)).set_Name(hs, label + " Brightness");
            ((DeviceClass)hs.GetDeviceByRef(Color)).set_Name(hs, label + " Color");
            ((DeviceClass)hs.GetDeviceByRef(Temperature)).set_Name(hs, label + " Color Temperature");
        }
Exemple #3
0
        private void _createColor(string label)
        {
            if (Color != 0)
            {
                return;
            }

            IHSApplication hs = _plugin.hs;

            int         hsRef  = hs.NewDeviceRef(label + " Color");
            DeviceClass device = (DeviceClass)hs.GetDeviceByRef(hsRef);

            device.set_Address(hs, GetSubDeviceAddress(SubDeviceType.Color));
            device.set_Interface(hs, _plugin.Name);
            device.set_InterfaceInstance(hs, _plugin.InstanceFriendlyName());
            device.set_Device_Type_String(hs, "LIFX Device Color");
            device.set_DeviceType_Set(hs, new DeviceTypeInfo_m.DeviceTypeInfo {
                Device_API = DeviceTypeInfo_m.DeviceTypeInfo.eDeviceAPI.Plug_In
            });

            // Create the buttons and slider
            VSVGPairs.VSPair colorPicker = new VSVGPairs.VSPair(ePairStatusControl.Both);
            colorPicker.PairType   = VSVGPairs.VSVGPairType.SingleValue;
            colorPicker.Render     = Enums.CAPIControlType.Color_Picker;
            colorPicker.ControlUse = ePairControlUse._ColorControl;

            hs.DeviceVSP_AddPair(hsRef, colorPicker);

            device.MISC_Set(hs, Enums.dvMISC.SHOW_VALUES);

            hs.SetDeviceString(hsRef, "ffffff", false);

            Color = hsRef;
        }
Exemple #4
0
        public Scheduler.Classes.DeviceClass createHSDevice(String Name, EnOceanDeviceType type, String id = "")
        {
            var devRefId = HS.NewDeviceRef(Name);
            var newDev   = (Scheduler.Classes.DeviceClass)HS.GetDeviceByRef(devRefId);

            var DT = new DeviceTypeInfo_m.DeviceTypeInfo();

            DT.Device_API     = DeviceTypeInfo_m.DeviceTypeInfo.eDeviceAPI.Plug_In;
            DT.Device_Type    = 33;
            DT.Device_SubType = (int)type;
            newDev.set_DeviceType_Set(HS, DT);
            newDev.set_Address(HS, id);
            newDev.set_Interface(HS, Constants.PLUGIN_STRING_NAME);
            newDev.set_InterfaceInstance(HS, "");
            newDev.set_Last_Change(HS, DateTime.Now);
            newDev.set_Location(HS, "EnOcean");
            newDev.set_Location2(HS, "EnOcean");
            return(newDev);
        }
        public string GetDeviceInfoString(int deviceRef)
        {
            var foundDevice = (DeviceClass)_hs.GetDeviceByRef(deviceRef);

            if (foundDevice != null)
            {
                var deviceName = foundDevice.get_Name(_hs);
                var floor      = foundDevice.get_Location2(_hs);
                var room       = foundDevice.get_Location(_hs);
                return($"{floor} {room} {deviceName}");
            }
            return("");
        }
Exemple #6
0
        private void _associateDevices()
        {
            IHSApplication hs = _plugin.hs;

            DeviceClass root       = (DeviceClass)hs.GetDeviceByRef(Root);
            DeviceClass brightness = (DeviceClass)hs.GetDeviceByRef(Brightness);
            DeviceClass color      = (DeviceClass)hs.GetDeviceByRef(Color);
            DeviceClass temp       = (DeviceClass)hs.GetDeviceByRef(Temperature);

            root.set_Relationship(hs, Enums.eRelationship.Parent_Root);

            brightness.set_Relationship(hs, Enums.eRelationship.Child);
            root.AssociatedDevice_Add(hs, Brightness);
            brightness.AssociatedDevice_Add(hs, Root);

            color.set_Relationship(hs, Enums.eRelationship.Child);
            root.AssociatedDevice_Add(hs, Color);
            color.AssociatedDevice_Add(hs, Root);

            temp.set_Relationship(hs, Enums.eRelationship.Child);
            root.AssociatedDevice_Add(hs, Temperature);
            temp.AssociatedDevice_Add(hs, Root);
        }
Exemple #7
0
        private void _createTemperature(string label)
        {
            if (Temperature != 0)
            {
                return;
            }

            IHSApplication hs = _plugin.hs;

            int         hsRef  = hs.NewDeviceRef(label + " Color Temperature");
            DeviceClass device = (DeviceClass)hs.GetDeviceByRef(hsRef);

            device.set_Address(hs, GetSubDeviceAddress(SubDeviceType.Temperature));
            device.set_Interface(hs, _plugin.Name);
            device.set_InterfaceInstance(hs, _plugin.InstanceFriendlyName());
            device.set_Device_Type_String(hs, "LIFX Device Color Temperature");
            device.set_DeviceType_Set(hs, new DeviceTypeInfo_m.DeviceTypeInfo {
                Device_API = DeviceTypeInfo_m.DeviceTypeInfo.eDeviceAPI.Plug_In
            });

            VSVGPairs.VSPair temp = new VSVGPairs.VSPair(ePairStatusControl.Both);
            temp.PairType          = VSVGPairs.VSVGPairType.Range;
            temp.Render            = Enums.CAPIControlType.ValuesRangeSlider;
            temp.RangeStart        = 2500;
            temp.RangeEnd          = 9000;
            temp.RangeStatusSuffix = " K";

            hs.DeviceVSP_AddPair(hsRef, temp);

            device.MISC_Set(hs, Enums.dvMISC.SHOW_VALUES);

            _plugin.IgnoreNextDeviceControl(hsRef);
            hs.SetDeviceValueByRef(hsRef, 3200, false);

            Temperature = hsRef;
        }
Exemple #8
0
        private void _createRoot(string label)
        {
            if (Root != 0)
            {
                return;
            }

            IHSApplication hs = _plugin.hs;

            int         hsRef  = hs.NewDeviceRef(label);
            DeviceClass device = (DeviceClass)hs.GetDeviceByRef(hsRef);

            device.set_Address(hs, GetSubDeviceAddress(SubDeviceType.Root));
            device.set_Interface(hs, _plugin.Name);
            device.set_InterfaceInstance(hs, _plugin.InstanceFriendlyName());
            device.set_Device_Type_String(hs, "LIFX Root Device");
            device.set_DeviceType_Set(hs, new DeviceTypeInfo_m.DeviceTypeInfo {
                Device_Type = DeviceTypeInfo_m.DeviceTypeInfo.eDeviceType_GenericRoot
            });

            hs.SetDeviceString(hsRef, "No Status", false);

            Root = hsRef;
        }
Exemple #9
0
        private void _createBrightness(string label)
        {
            if (Brightness != 0)
            {
                return;
            }

            IHSApplication hs = _plugin.hs;

            int         hsRef  = hs.NewDeviceRef(label + " Brightness");
            DeviceClass device = (DeviceClass)hs.GetDeviceByRef(hsRef);

            device.set_Address(hs, GetSubDeviceAddress(SubDeviceType.Brightness));
            device.set_Interface(hs, _plugin.Name);
            device.set_InterfaceInstance(hs, _plugin.InstanceFriendlyName());
            device.set_Device_Type_String(hs, "LIFX Device Brightness");
            device.set_DeviceType_Set(hs, new DeviceTypeInfo_m.DeviceTypeInfo {
                Device_API = DeviceTypeInfo_m.DeviceTypeInfo.eDeviceAPI.Plug_In
            });

            // Create the buttons and slider
            VSVGPairs.VSPair offBtn = new VSVGPairs.VSPair(ePairStatusControl.Both);
            offBtn.PairType        = VSVGPairs.VSVGPairType.SingleValue;
            offBtn.Render          = Enums.CAPIControlType.Button;
            offBtn.Status          = "Off";
            offBtn.ControlUse      = ePairControlUse._Off;
            offBtn.Value           = 0;
            offBtn.Render_Location = new Enums.CAPIControlLocation {
                Column = 1,
                Row    = 1,
            };

            VSVGPairs.VSPair onBtn = new VSVGPairs.VSPair(ePairStatusControl.Both);
            onBtn.PairType        = VSVGPairs.VSVGPairType.SingleValue;
            onBtn.Render          = Enums.CAPIControlType.Button;
            onBtn.Status          = "On";
            onBtn.ControlUse      = ePairControlUse._On;
            onBtn.Value           = 99;
            onBtn.Render_Location = new Enums.CAPIControlLocation {
                Column = 2,
                Row    = 1,
            };

            VSVGPairs.VSPair lastBtn = new VSVGPairs.VSPair(ePairStatusControl.Control);
            lastBtn.PairType        = VSVGPairs.VSVGPairType.SingleValue;
            lastBtn.Render          = Enums.CAPIControlType.Button;
            lastBtn.Status          = "Last";
            lastBtn.ControlUse      = ePairControlUse._On_Alternate;
            lastBtn.Value           = 255;
            lastBtn.Render_Location = new Enums.CAPIControlLocation {
                Column = 4,
                Row    = 1,
            };

            VSVGPairs.VSPair dim = new VSVGPairs.VSPair(ePairStatusControl.Both);
            dim.PairType          = VSVGPairs.VSVGPairType.Range;
            dim.Render            = Enums.CAPIControlType.ValuesRangeSlider;
            dim.RangeStart        = 1;
            dim.RangeEnd          = 98;
            dim.RangeStatusPrefix = "Dim ";
            dim.RangeStatusSuffix = "%";
            dim.ControlUse        = ePairControlUse._Dim;
            dim.Render_Location   = new Enums.CAPIControlLocation {
                Column     = 1,
                Row        = 2,
                ColumnSpan = 3,
            };

            hs.DeviceVSP_AddPair(hsRef, offBtn);
            hs.DeviceVSP_AddPair(hsRef, onBtn);
            hs.DeviceVSP_AddPair(hsRef, lastBtn);
            hs.DeviceVSP_AddPair(hsRef, dim);

            device.MISC_Set(hs, Enums.dvMISC.SHOW_VALUES);
            device.MISC_Set(hs, Enums.dvMISC.IS_LIGHT);

            _plugin.IgnoreNextDeviceControl(hsRef);
            hs.SetDeviceValueByRef(hsRef, 0, false);

            Brightness = hsRef;
        }