Esempio n. 1
0
        /// <summary>
        /// Creates the HS device.
        /// </summary>
        /// <param name="parent">The data for parent of device.</param>
        /// <param name="rootDeviceData">The root device data.</param>
        /// <param name="deviceData">The device data.</param>
        /// <returns>New Device</returns>
        private DeviceClass CreateDevice([AllowNull] DeviceClass parent, [AllowNull] RootDeviceData rootDeviceData, DeviceDataBase deviceData)
        {
            if (rootDeviceData != null)
            {
                LogDebug(Invariant($"Creating {deviceData.Name} under {rootDeviceData.Name}"));
            }
            else
            {
                LogDebug(Invariant($"Creating Root {deviceData.Name}"));
            }

            DeviceClass device = null;
            int         refId  = HS.NewDeviceRef(rootDeviceData != null ? Invariant($"{rootDeviceData.Name} {deviceData.Name}") : deviceData.Name);

            if (refId > 0)
            {
                device = (DeviceClass)HS.GetDeviceByRef(refId);
                string address = rootDeviceData != null?CreateChildAddress(rootDeviceData.Name, deviceData.Name) : deviceData.Name;

                device.set_Address(HS, address);
                device.set_Device_Type_String(HS, deviceData.HSDeviceTypeString);
                var deviceType = new DeviceTypeInfo_m.DeviceTypeInfo();
                deviceType.Device_API  = DeviceTypeInfo_m.DeviceTypeInfo.eDeviceAPI.Plug_In;
                deviceType.Device_Type = deviceData.HSDeviceType;

                device.set_DeviceType_Set(HS, deviceType);
                device.set_Interface(HS, Name);
                device.set_InterfaceInstance(HS, string.Empty);
                device.set_Last_Change(HS, DateTime.Now);
                device.set_Location(HS, Name);
                var pairs = deviceData.StatusPairs;
                foreach (var pair in pairs)
                {
                    HS.DeviceVSP_AddPair(refId, pair);
                }

                var gPairs = deviceData.GraphicsPairs;
                foreach (var gpair in gPairs)
                {
                    HS.DeviceVGP_AddPair(refId, gpair);
                }

                device.MISC_Set(HS, Enums.dvMISC.STATUS_ONLY);
                device.MISC_Set(HS, Enums.dvMISC.SHOW_VALUES);
                device.MISC_Clear(HS, Enums.dvMISC.AUTO_VOICE_COMMAND);
                device.MISC_Clear(HS, Enums.dvMISC.SET_DOES_NOT_CHANGE_LAST_CHANGE);
                device.set_Status_Support(HS, false);

                if (parent != null)
                {
                    parent.set_Relationship(HS, Enums.eRelationship.Parent_Root);
                    device.set_Relationship(HS, Enums.eRelationship.Child);
                    device.AssociatedDevice_Add(HS, parent.get_Ref(HS));
                    parent.AssociatedDevice_Add(HS, device.get_Ref(HS));
                }
                deviceData.SetInitialData(HS, device);
            }

            return(device);
        }
Esempio n. 2
0
        public override void AddOrUpdateHSDeviceProperties()
        {
            Console.WriteLine("FIXME: Adding HS Device control status");
//            hsDevice.MISC_Set(HS, Enums.dvMISC.NO_LOG);
            hsDevice.MISC_Set(HS, Enums.dvMISC.SHOW_VALUES);

            hsDevice.set_Relationship(HS, Enums.eRelationship.Standalone);

            // Clear existing VSP
            HS.DeviceVSP_ClearAll(hsDevice.get_Ref(null), true);

            VSVGPairs.VSPair v = new VSVGPairs.VSPair(ePairStatusControl.Status);
            v.PairType               = VSVGPairs.VSVGPairType.SingleValue;
            v.Value                  = 0;
            v.Status                 = "Closed";
            v.Render                 = Enums.CAPIControlType.Button;
            v.Render_Location.Row    = 1;
            v.Render_Location.Column = 1;
            v.ControlUse             = ePairControlUse._Off;
            HS.DeviceVSP_AddPair(hsDevice.get_Ref(null), v);

            VSVGPairs.VSPair v2 = new VSVGPairs.VSPair(ePairStatusControl.Status);
            v2.PairType               = VSVGPairs.VSVGPairType.SingleValue;
            v2.Value                  = 1;
            v2.Status                 = "Open";
            v2.Render                 = Enums.CAPIControlType.Button;
            v2.Render_Location.Row    = 1;
            v2.Render_Location.Column = 2;
            v2.ControlUse             = ePairControlUse._On;
            HS.DeviceVSP_AddPair(hsDevice.get_Ref(null), v2);

            SaveConfiguration();
        }
Esempio n. 3
0
        public override void AddOrUpdateHSDeviceProperties()
        {
            Console.WriteLine("FIXME: Adding HS Device control status");
//            hsDevice.MISC_Set(HS, Enums.dvMISC.NO_LOG);
            hsDevice.MISC_Set(HS, Enums.dvMISC.SHOW_VALUES);

            hsDevice.set_Relationship(HS, Enums.eRelationship.Standalone);

            // Clear existing VSP
            HS.DeviceVSP_ClearAll(hsDevice.get_Ref(null), true);

            VSVGPairs.VSPair v = new VSVGPairs.VSPair(ePairStatusControl.Status);
            v.PairType = VSVGPairs.VSVGPairType.Range;
            var vg = new HomeSeerAPI.VSVGPairs.VGPair();

            vg.PairType = VSVGPairs.VSVGPairType.Range;
            //v.ControlStatus = ePairStatusControl.Status;
            //v.ControlUse = ePairControlUse.
            v.RangeStatusSuffix = " C";


            v.RangeStart          = -50;
            v.RangeEnd            = 100;
            v.RangeStatusDecimals = 2;

            vg.RangeStart = -50;
            vg.RangeEnd   = 100;
            vg.Graphic    = "/images/HomeSeer/status/Thermometer-50.png";

            v.Render = Enums.CAPIControlType.ValuesRange;

            hsDevice.MISC_Clear(HS, Enums.dvMISC.SHOW_VALUES); // Should be set or not ?
            HS.DeviceVSP_AddPair(hsDevice.get_Ref(null), v);
            HS.DeviceVGP_AddPair(hsDevice.get_Ref(null), vg);

/*
 *          VSVGPairs.VSPair v = new VSVGPairs.VSPair(ePairStatusControl.Status);
 *          v.PairType = VSVGPairs.VSVGPairType.SingleValue;
 *          v.Value = 0;
 *          v.Status = "Closed";
 *          v.Render = Enums.CAPIControlType.Button;
 *          v.Render_Location.Row = 1;
 *          v.Render_Location.Column = 1;
 *          v.ControlUse = ePairControlUse._Off;
 *          HS.DeviceVSP_AddPair(hsDevice.get_Ref(null), v);
 *
 *          VSVGPairs.VSPair v2 = new VSVGPairs.VSPair(ePairStatusControl.Status);
 *          v2.PairType = VSVGPairs.VSVGPairType.SingleValue;
 *          v2.Value = 1;
 *          v2.Status = "Open";
 *          v2.Render = Enums.CAPIControlType.Button;
 *          v2.Render_Location.Row = 1;
 *          v2.Render_Location.Column = 2;
 *          v2.ControlUse = ePairControlUse._On;
 *          HS.DeviceVSP_AddPair(hsDevice.get_Ref(null), v2);
 */
            SaveConfiguration();
        }
Esempio n. 4
0
        public bool SetButtonState(int button, Boolean pressed)
        {
            String btnDeviceId = DeviceId + ":" + button;
            //    Console.WriteLine("Button {0} pressed: {1}", button, pressed);
            var btnDevice = Controller.getHSDevice(EnOceanController.EnOceanDeviceType.ChildDevice, btnDeviceId);

            buttonState[button] = pressed;
            if (btnDevice == null)
            {
                Console.WriteLine("No button device for btn {0} - creating");
                btnDevice = Controller.createHSDevice(hsDevice.get_Name(null) + " Button " + button, EnOceanController.EnOceanDeviceType.ChildDevice, btnDeviceId);
                btnDevice.set_Device_Type_String(HS, "EnOcean " + EnOceanController.EnOceanDeviceType.ChildDevice.ToString());
                btnDevice.set_Relationship(HS, Enums.eRelationship.Child);
                btnDevice.AssociatedDevice_Add(HS, hsDevice.get_Ref(null));
                hsDevice.AssociatedDevice_Add(HS, btnDevice.get_Ref(null));

                VSVGPairs.VSPair v = new VSVGPairs.VSPair(ePairStatusControl.Status);
                v.PairType               = VSVGPairs.VSVGPairType.SingleValue;
                v.Value                  = 0;
                v.Status                 = "Released";
                v.Render                 = Enums.CAPIControlType.Button;
                v.Render_Location.Row    = 1;
                v.Render_Location.Column = 1;
                v.ControlUse             = ePairControlUse._Off;
                HS.DeviceVSP_AddPair(btnDevice.get_Ref(null), v);

                VSVGPairs.VSPair v2 = new VSVGPairs.VSPair(ePairStatusControl.Status);
                v2.PairType               = VSVGPairs.VSVGPairType.SingleValue;
                v2.Value                  = 1;
                v2.Status                 = "Pressed";
                v2.Render                 = Enums.CAPIControlType.Button;
                v2.Render_Location.Row    = 1;
                v2.Render_Location.Column = 2;
                v2.ControlUse             = ePairControlUse._On;
                HS.DeviceVSP_AddPair(btnDevice.get_Ref(null), v2);

//                btnDevice.MISC_Set(HS, Enums.dvMISC.NO_LOG);
                btnDevice.MISC_Set(HS, Enums.dvMISC.SHOW_VALUES);

                Controller.SaveConfiguration();
            }
            HS.SetDeviceValueByRef(btnDevice.get_Ref(null), pressed ? 1 : 0, true);
            return(true);
        }
Esempio n. 5
0
        /// <summary>
        /// Creates the HS device.
        /// </summary>
        /// <param name="optionalParentRefId">The optional parent reference identifier.</param>
        /// <param name="name">The name of device</param>
        /// <param name="deviceAddress">The device address.</param>
        /// <param name="deviceData">The device data.</param>
        /// <returns>
        /// New Device
        /// </returns>
        private DeviceClass CreateDevice(int?optionalParentRefId, string name, string deviceAddress, DeviceDataBase deviceData)
        {
            Trace.TraceInformation(Invariant($"Creating Device with Address:{deviceAddress}"));

            DeviceClass device = null;
            int         refId  = HS.NewDeviceRef(name);

            if (refId > 0)
            {
                device = (DeviceClass)HS.GetDeviceByRef(refId);
                string address = deviceAddress;
                device.set_Address(HS, address);
                device.set_Device_Type_String(HS, deviceData.HSDeviceTypeString);
                var deviceType = new DeviceTypeInfo_m.DeviceTypeInfo
                {
                    Device_API  = deviceData.DeviceAPI,
                    Device_Type = deviceData.HSDeviceType
                };

                device.set_DeviceType_Set(HS, deviceType);
                device.set_Interface(HS, PluginData.PlugInName);
                device.set_InterfaceInstance(HS, string.Empty);
                device.set_Last_Change(HS, DateTime.Now);
                device.set_Location(HS, PluginData.PlugInName);

                device.MISC_Set(HS, Enums.dvMISC.SHOW_VALUES);
                if (deviceData.StatusDevice)
                {
                    device.MISC_Set(HS, Enums.dvMISC.STATUS_ONLY);
                    device.MISC_Clear(HS, Enums.dvMISC.AUTO_VOICE_COMMAND);
                    device.MISC_Clear(HS, Enums.dvMISC.SET_DOES_NOT_CHANGE_LAST_CHANGE);
                    device.set_Status_Support(HS, true);
                }
                else
                {
                    device.MISC_Set(HS, Enums.dvMISC.SET_DOES_NOT_CHANGE_LAST_CHANGE);
                    device.MISC_Set(HS, Enums.dvMISC.AUTO_VOICE_COMMAND);
                    device.set_Status_Support(HS, false);
                }

                var pairs = deviceData.StatusPairs;
                foreach (var pair in pairs)
                {
                    HS.DeviceVSP_AddPair(refId, pair);
                }

                var gPairs = deviceData.GraphicsPairs;
                foreach (var gpair in gPairs)
                {
                    HS.DeviceVGP_AddPair(refId, gpair);
                }

                DeviceClass parent = null;
                if (optionalParentRefId.HasValue)
                {
                    parent = (DeviceClass)HS.GetDeviceByRef(optionalParentRefId.Value);
                }

                if (parent != null)
                {
                    parent.set_Relationship(HS, Enums.eRelationship.Parent_Root);
                    device.set_Relationship(HS, Enums.eRelationship.Child);
                    device.AssociatedDevice_Add(HS, parent.get_Ref(HS));
                    parent.AssociatedDevice_Add(HS, device.get_Ref(HS));
                }

                deviceData.SetOnDeviceCreateData(HS, CameraSettings, refId);
            }

            return(device);
        }