public void Create(string name, bool force)
        {
            string addr = "AK_" + name;

            deviceHS = controller.GetHSDeviceByAddress(addr, out bool created, create: true, name: name);

            RefId = deviceHS.get_Ref(null);

            if (created)
            {
                DeviceTypeInfo_m.DeviceTypeInfo DT = new DeviceTypeInfo_m.DeviceTypeInfo();
                DT.Device_API  = DeviceTypeInfo_m.DeviceTypeInfo.eDeviceAPI.Security;
                DT.Device_Type = (int)DeviceTypeInfo_m.DeviceTypeInfo.eDeviceAPI.Plug_In;
                deviceHS.set_DeviceType_Set(hs, DT);
                deviceHS.set_InterfaceInstance(hs, "");
                deviceHS.set_Status_Support(hs, false);//Set to True if the devices can be polled,  false if not
                deviceHS.MISC_Set(hs, Enums.dvMISC.SHOW_VALUES);
                deviceHS.MISC_Set(hs, Enums.dvMISC.NO_LOG);

                Interface = controller.plugin.Name;
                Type      = "Virtual";
                Address   = addr;

                //Location = "EnOcean";
                //Location2 = "EnOcean";
                //LastChange = DateTime.Now;
            }

            controller.UsedDevices[RefId] = this;
        }
Beispiel #2
0
        ///<summary>
        ///List of all devices in HomeSeer. Used to enable Linq queries on devices.
        ///</summary>
        ///<returns>Generic.List() of all devices</returns>
        ///<remarks>By Moskus</remarks>
        public static DeviceDictHS Devices()
        {
            DeviceDictHS ret = new DeviceDictHS();

            Scheduler.Classes.clsDeviceEnumeration deviceEnumeration = (clsDeviceEnumeration)Hs.GetDeviceEnumerator();
            while (!deviceEnumeration.Finished)
            {
                HSDevice device = deviceEnumeration.GetNext();
                ret[device.get_Ref(null)] = device;
            }
            return(ret);
        }
Beispiel #3
0
        public bool Create(string name,
                           bool force,
                           string type                       = "Virtual",
                           eDeviceAPI Device_API             = eDeviceAPI.Plug_In,
                           int Device_Type                   = (int)eDeviceAPI.Plug_In,
                           int Device_SubType                = 0,
                           string Device_SubType_Description = ""
                           )
        {
            string addr = ADDR_PREFIX + name;

            deviceHS = controller.GetHSDeviceByAddress(addr, out bool created, create: true, name: name);

            RefId = deviceHS.get_Ref(null);

            if (created)
            {
                DeviceTypeInfo_m.DeviceTypeInfo DT = new DeviceTypeInfo_m.DeviceTypeInfo()
                {
                    Device_API                 = Device_API,
                    Device_Type                = Device_Type,
                    Device_SubType             = Device_SubType,
                    Device_SubType_Description = Device_SubType_Description
                };
                deviceHS.set_DeviceType_Set(hs, DT);

                deviceHS.set_InterfaceInstance(hs, "");
                deviceHS.set_Status_Support(hs, false);//Set to True if the devices can be polled,  false if not
                deviceHS.MISC_Set(hs, Enums.dvMISC.SHOW_VALUES | Enums.dvMISC.NO_LOG);
                deviceHS.MISC_Clear(hs, Enums.dvMISC.AUTO_VOICE_COMMAND);

                Interface = controller.plugin.Name;
                Type      = type;
                Address   = addr;

                //Location = "EnOcean";
                //Location2 = "EnOcean";
                //LastChange = DateTime.Now;
            }

            controller.UsedDevices[RefId] = this;

            return(created);
        }
        /// <summary>
        /// Constructor
        /// Pass either devID or deviceHS
        /// </summary>
        /// <param name="controller">Controller</param>
        /// <param name="devID">HSDevice</param>
        /// <param name="deviceHS">HSDevice</param>
        public DeviceBase(ControllerBase controller, int devID = 0)
        {
            FullUpdate      = false;
            this.controller = controller;
            this.RefId      = devID;

            //if (deviceHS==null)
            {
                deviceHS = controller.GetHSDeviceByRef(devID);
                if (deviceHS == null)
                {
                    // Deleted device. This also sets "Attension" field
                    LogErr("Device doesn't exist in the system");
                    return;
                }
            }

            this.deviceHS = deviceHS;
            this.RefId    = deviceHS.get_Ref(null);
        }
        /// <summary>
        /// Get HSDevice By Address
        /// </summary>
        /// <param name="addr">Device Address</param>
        /// <param name="created">Returns True if new device was created</param>
        /// <param name="create">Create if not found</param>
        /// <param name="name">Name used to create if not found</param>
        /// <returns></returns>
        public HSDevice GetHSDeviceByAddress(string addr, out bool created, bool create = false, string name = null)
        {
            created = false;

            int      devID  = HS.DeviceExistsAddress(addr, CaseSensitive: false);
            HSDevice device = GetHSDeviceByRef(devID);

            if (!create || device != null)
            {
                return(device);
            }

            if (name == null)
            {
                name = addr;
            }

            devID = HS.NewDeviceRef(name);
            //this.devices[devID] = (HSDevice)HS.GetDeviceByRef(devID);
            UpdateDeviceList();
            created = true;
            return(GetHSDeviceByRef(devID));
        }
Beispiel #6
0
        /// <summary>
        /// 2. Helper for above GetDevices - selects devices filtered by Location and/or Location2
        /// </summary>
        /// <param name="Location"></param>
        /// <param name="Location2"></param>
        /// <param name="devices">Full DeviceDictHS, can be "null", then will retrieve inside</param>
        /// <param name="min_vspsCount">Filter devices if their vspsCount exceeds this number</param>
        /// <param name="exclude">List<dev_ids> to exclude</param>
        /// <returns>List of pairs (Name=name, Value=deviceID) for dropbox</returns>
        public static MyPairList GetDevices(string Location,
                                            string Location2,
                                            DeviceDictHS devices = null,
                                            int min_vspsCount    = 0,
                                            DeviceIdList exclude = null)
        {
            IHSApplication _hs = null;

            //IHSApplication _hs = Hs;

            if (devices == null)
            {
                devices = Devices();
            }

            if (exclude == null)
            {
                exclude = new DeviceIdList();
            }

            MyPairList items = new MyPairList();

            foreach (int deviceId in devices.Keys)
            {
                if (exclude.Contains(deviceId))
                {
                    continue;
                }

                HSDevice device   = devices[deviceId];
                string   name     = device.get_Name(_hs);
                string   dev_loc  = device.get_Location(_hs);
                string   dev_loc2 = device.get_Location2(_hs);
                // Select devices matching Loc/Loc2, or if Loc/Loc2 not specified
                if ((String.IsNullOrEmpty(Location) || Location == dev_loc) &&
                    (String.IsNullOrEmpty(Location2) || Location2 == dev_loc2)
                    )
                {
                    // If Loc/Loc2 not specified - prepend them to device name
                    if (String.IsNullOrEmpty(Location))
                    {
                        name = "[" + dev_loc + "] " + name;
                    }
                    if (String.IsNullOrEmpty(Location2))
                    {
                        name = "[" + dev_loc2 + "] " + name;
                    }

                    int num_vsps = 0;
                    if (min_vspsCount > 0)
                    {
                        VSVGPairs.VSPair[] vsps = Hs.DeviceVSP_GetAllStatus(deviceId);
                        num_vsps = vsps.Length;
                    }

                    if (num_vsps >= min_vspsCount)
                    {
                        items.Add(new MyPair(name, deviceId));
                    }
                }
            }
            return(items);
        }