Exemple #1
0
        public string MakeNewRule()
        {
            var dv = Instance.host.NewDeviceRef("R");


            Scheduler.Classes.DeviceClass newDevice = (Scheduler.Classes.DeviceClass)Instance.host.GetDeviceByRef(dv);
            newDevice.set_InterfaceInstance(Instance.host, Instance.name);
            newDevice.set_Name(Instance.host, "Type Meter Calc " + dv);
            //newDevice.set_Location2(Instance.host, "ScratchpadRule");
            newDevice.set_Location(Instance.host, "Utilities");
            newDevice.set_Location2(Instance.host, "Calcs");
            //newDevice.set_Interface(Instance.host, "Modbus Configuration");//Put here the registered name of the page for what we want in the Modbus tab!!!  So easy!
            newDevice.set_Interface(Instance.host, Util.IFACE_NAME); //Needed to link device to plugin, so the tab calls back to the correct hardcoded homeseer function
                                                                     //newDevice.set_InterfaceInstance()''  SET INTERFACE INSTANCE
            newDevice.set_Relationship(Instance.host, Enums.eRelationship.Not_Set);

            newDevice.MISC_Set(Instance.host, Enums.dvMISC.NO_LOG);
            newDevice.MISC_Set(Instance.host, Enums.dvMISC.SHOW_VALUES);
            // newDevice.MISC_Set(Instance.host, Enums.dvMISC.HIDDEN);
            HomeSeerAPI.PlugExtraData.clsPlugExtraData EDO = new PlugExtraData.clsPlugExtraData();

            // EDO = newDevice.get_PlugExtraData_Get(Instance.host);

            string ruleString = makeNewRules();


            string userNote = newDevice.get_UserNote(Instance.host);

            userNote  = userNote.Split("PLUGIN EXTRA DATA:".ToCharArray())[0];
            userNote += "PLUGIN EXTRA DATA:" + ruleString.ToString();
            newDevice.set_UserNote(Instance.host, userNote);

            EDO.AddNamed("SSIDKey", ruleString);
            newDevice.set_PlugExtraData_Set(Instance.host, EDO);

            // newDevice.set_Device_Type_String(Instance.host, makeNewModbusGateway());
            var DevINFO = new DeviceTypeInfo_m.DeviceTypeInfo();

            DevINFO.Device_API = DeviceTypeInfo_m.DeviceTypeInfo.eDeviceAPI.Plug_In;


            newDevice.set_DeviceType_Set(Instance.host, DevINFO);
            Instance.Devices.Add(new SiidDevice(Instance, newDevice));

            MakeStewardVSP(dv);

            return("refresh");
        }
Exemple #2
0
        private int CreateBasicDevice()
        {
            try
            {
                //Creating a brand new device, and get the actual device from the device reference
                var fullName = Location + GetName() + Location2 + GetName() +
                               Name + Unique;

                var dv = (DeviceClass)_hs.GetDeviceByRef(_hs.NewDeviceRef(fullName));

                var dvRef = dv.get_Ref(_hs);

                //Setting the type to plugin device
                var typeInfo = new DeviceTypeInfo_m.DeviceTypeInfo
                {
                    Device_Type = (int)DeviceTypeInfo_m.DeviceTypeInfo.eDeviceAPI.Plug_In,
                    Device_API  = DeviceTypeInfo_m.DeviceTypeInfo.eDeviceAPI.Plug_In,
                    Device_SubType_Description = Name
                };

                dv.set_DeviceType_Set(_hs, typeInfo);

                var pluginExtraData = new PlugExtraData.clsPlugExtraData();
                //var pluginExtraData = new PlugExtraData.clsPlugExtraData();
                if (PEDStorage.Count > 0)
                {
                    //PED storage got something
                    foreach (KeyValuePair <string, string> pair in PEDStorage)
                    {
                        Console.WriteLine("Found PED");
                        pluginExtraData.AddNamed(pair.Key.ToString(), pair.Value.ToString());
                    }
                }


                dv.set_PlugExtraData_Set(_hs, pluginExtraData);

                dv.set_Interface(_hs, GetName());                      //Don't change this, or the device won't be associated with your plugin
                dv.set_InterfaceInstance(_hs, InstanceFriendlyName()); //Don't change this, or the device won't be associated with that particular instance

                dv.set_Device_Type_String(_hs, Name);
                dv.set_Can_Dim(_hs, false);

                //Setting the name and locations
                dv.set_Name(_hs, Name);
                dv.set_Location(_hs, Location);
                dv.set_Location2(_hs, Location2);

                //Misc options
                dv.set_Status_Support(_hs, true);           //Set to True if the devices can be polled, False if not. (See PollDevice in hspi.vb)
                dv.MISC_Set(_hs, Enums.dvMISC.SHOW_VALUES); //If not set, device control options will not be displayed.
                //dv.MISC_Set(_hs, Enums.dvMISC.NO_LOG); //As default, we don't want to Log every device value change to the Log

                //Committing to the database, clear value-status-pairs and graphic-status pairs
                _hs.SaveEventsDevices();

                _hs.DeviceVSP_ClearAll(dvRef, true);
                _hs.DeviceVGP_ClearAll(dvRef, true);

                Id = dvRef;

                return(dvRef); //Return the reference
            }
            catch (Exception ex)
            {
                throw new Exception("Error creating basic device: " + ex.Message, ex);
            }
        }
Exemple #3
0
        public string addSubrule(string data)
        {
            //Make a new rule, but make it in service to an existing rule:
            var dv = Instance.host.NewDeviceRef("R");


            Scheduler.Classes.DeviceClass newDevice = (Scheduler.Classes.DeviceClass)Instance.host.GetDeviceByRef(dv);
            newDevice.set_InterfaceInstance(Instance.host, Instance.name);
            newDevice.set_Name(Instance.host, "Type Meter Rate" + dv);
            //   newDevice.set_Location2(Instance.host, "ScratchpadSubRule");
            newDevice.set_Location(Instance.host, "Utilities");
            newDevice.set_Location2(Instance.host, "Rates");

            //newDevice.set_Interface(Instance.host, "Modbus Configuration");//Put here the registered name of the page for what we want in the Modbus tab!!!  So easy!
            newDevice.set_Interface(Instance.host, Util.IFACE_NAME); //Needed to link device to plugin, so the tab calls back to the correct hardcoded homeseer function
                                                                     //newDevice.set_InterfaceInstance()''  SET INTERFACE INSTANCE
            newDevice.set_Relationship(Instance.host, Enums.eRelationship.Not_Set);

            newDevice.MISC_Set(Instance.host, Enums.dvMISC.NO_LOG);
            newDevice.MISC_Set(Instance.host, Enums.dvMISC.SHOW_VALUES);
            // newDevice.MISC_Set(Instance.host, Enums.dvMISC.HIDDEN);
            HomeSeerAPI.PlugExtraData.clsPlugExtraData EDO = new PlugExtraData.clsPlugExtraData();

            // EDO = newDevice.get_PlugExtraData_Get(Instance.host);


            string ruleString = makeNewRules();


            string userNote = newDevice.get_UserNote(Instance.host);

            userNote  = userNote.Split("PLUGIN EXTRA DATA:".ToCharArray())[0];
            userNote += "PLUGIN EXTRA DATA:" + ruleString.ToString();
            newDevice.set_UserNote(Instance.host, userNote);

            EDO.AddNamed("SSIDKey", ruleString);
            newDevice.set_PlugExtraData_Set(Instance.host, EDO);

            // newDevice.set_Device_Type_String(Instance.host, makeNewModbusGateway());
            var DevINFO = new DeviceTypeInfo_m.DeviceTypeInfo();

            DevINFO.Device_API = DeviceTypeInfo_m.DeviceTypeInfo.eDeviceAPI.Plug_In;


            newDevice.set_DeviceType_Set(Instance.host, DevINFO);
            Instance.Devices.Add(new SiidDevice(Instance, newDevice));

            MakeStewardVSP(dv);



            StringBuilder stb       = new StringBuilder();
            var           page      = this;
            string        GatewayID = data.Split("_".ToCharArray())[1];


            SiidDevice GateWay = SiidDevice.GetFromListByID(Instance.Devices, Convert.ToInt32(GatewayID));

            Scheduler.Classes.DeviceClass Gateway = GateWay.Device; //Should keep in gateway a list of devices

            Gateway.AssociatedDevice_Add(Instance.host, dv);        //This is totally working actually

            return("refresh");

            stb.Append("<meta http-equiv=\"refresh\" content = \"0; URL='/deviceutility?ref=" + dv + "&edit=1'\" />");
            //    stb.Append("<a id = 'LALA' href='/deviceutility?ref=" + dv + "&edit=1'/><script>LALA.click()</script> ");
            page.AddBody(stb.ToString());
            return(page.BuildPage());
        }