Example #1
0
        public string InitIO(string port) //Init plugin
        {
            Console.WriteLine("InitIO called with parameter port as " + port);

            string[] plugins = Util.hs.GetPluginsList();
            Util.gEXEPath = Util.hs.GetAppPath();

            try
            {
                // create our jquery web page
                pluginpage = new OptionsPage(WebPageName);
                // register the page with the HS web server, HS will post back to the WebPage class
                // "pluginpage" is the URL to access this page
                // comment this out if you are going to use the GenPage/PutPage API istead
                if (string.IsNullOrEmpty(Util.Instance))
                {
                    Util.hs.RegisterPage(Util.IFACE_NAME, Util.IFACE_NAME, Util.Instance);
                }
                else
                {
                    Util.hs.RegisterPage(Util.IFACE_NAME + Util.Instance, Util.IFACE_NAME, Util.Instance);
                }
                Console.WriteLine("Creates options page...");
                WebPageDesc wpd = new WebPageDesc();
                // create test page


                // register a normal page to appear in the HomeSeer menu

                wpd.link = Util.IFACE_NAME + Util.Instance;
                if (!string.IsNullOrEmpty(Util.Instance))
                {
                    wpd.linktext = Util.IFACE_NAME + " Page instance " + Util.Instance;
                }
                else
                {
                    wpd.linktext = Util.IFACE_NAME + " Status/Options";
                }
                wpd.page_title     = Util.IFACE_NAME + " Status/Options";
                wpd.plugInName     = Util.IFACE_NAME;
                wpd.plugInInstance = Util.Instance;
                Util.callback.RegisterLink(wpd);

                // register a normal page to appear in the HomeSeer menu

                // init a speak proxy
                //Util.callback.RegisterProxySpeakPlug(Util.IFACE_NAME, "")

                // register a generic Util.callback for other plugins to raise to use
                Util.callback.RegisterGenericEventCB("sample_type", Util.IFACE_NAME, "");

                Util.Log("InitIO called, plug-in is being initialized...", Util.LogType.LOG_TYPE_INFO);



                // register for events from homeseer if a device changes value
                Util.callback.RegisterEventCB(Enums.HSEvent.VALUE_CHANGE, Util.IFACE_NAME, "");

                start_test_timer();

                //Util.hs.SaveINISetting("Settings", "test", null, "hspi_HSTouch.ini");

                // example of how to save a file to the HS images folder, mainly for use by plugins that are running remotely, album art, etc.
                //SaveImageFileToHS(gEXEPath & "\html\images\browser.png", "sample\browser.png")//TODO look here
                //SaveFileToHS(gEXEPath & "\html\images\browser.png", "sample\browser.png")
            }
            catch (Exception ex)
            {
                bShutDown = true;
                return("Error on InitIO: " + ex.Message);
            }

            bShutDown = false;
            return("");
            // return no error, or an error message
        }
        public string GetPagePlugin(string pageName, string user, int userRights, string queryString)
        {
            StringBuilder pluginSB = new StringBuilder();
            OptionsPage   page     = this;

            try
            {
                page.reset();

                // handle queries with special data

                /*System.Collections.Specialized.NameValueCollection parts = null;
                 * if ((!string.IsNullOrEmpty(queryString)))
                 * {
                 *  parts = HttpUtility.ParseQueryString(queryString);
                 * }
                 * if (parts != null)
                 * {
                 *  if (parts["myslide1"] == "myslide_name_open")
                 *  {
                 *      // handle a get for tab content
                 *      string name = parts["name"];
                 *      return ("<table><tr><td>cell1</td><td>cell2</td></tr><tr><td>cell row 2</td><td>cell 2 row 2</td></tr></table>");
                 *      //Return ("<div><b>content data for tab</b><br><b>content data for tab</b><br><b>content data for tab</b><br><b>content data for tab</b><br><b>content data for tab</b><br><b>content data for tab</b><br></div>")
                 *  }
                 *  if (parts["myslide1"] == "myslide_name_close")
                 *  {
                 *      return "";
                 *  }
                 * }*/

                this.AddHeader(Util.hs.GetPageHeader(pageName, Util.IFACE_NAME, "", "", false, true));
                //pluginSB.Append("<link rel = 'stylesheet' href = 'HSPI_Nest_Thermostat_and_Camera_Plugin/css/style.css' type = 'text/css' /><br>");
                //page.AddHeader(pluginSB.ToString());



                //page.RefreshIntervalMilliSeconds = 5000
                // handler for our status div
                //stb.Append(page.AddAjaxHandler("/devicestatus?ref=3576", "stat"))
                pluginSB.Append(this.AddAjaxHandlerPost("action=updatetime", this.PageName));



                // page body starts here



                //pluginSB.Append(clsPageBuilder.DivStart("pluginpage", ""));
                //Dim dv As DeviceClass = GetDeviceByRef(3576)
                //Dim CS As CAPIStatus
                //CS = dv.GetStatus

                pluginSB.AppendLine("<table class='full_width_table' cellspacing='0' width='100%' >");
                pluginSB.AppendLine("<tr><td  colspan='1' >");
                // Status/Options Tabs

                clsJQuery.jqTabs jqtabs = new clsJQuery.jqTabs("optionsTab", this.PageName);



                // Options Tab
                clsJQuery.Tab tab = new clsJQuery.Tab();
                tab          = new clsJQuery.Tab();
                tab.tabTitle = "Options";
                tab.tabDIVID = "nestsiid-options";

                var optionsString = new StringBuilder();
                optionsString.Append(PageBuilderAndMenu.clsPageBuilder.FormStart("myform1", "testpage", "post"));
                optionsString.Append("<table>");
                optionsString.Append("<tr><td class='tableheader' colspan='2'>Follow the inputs below to retrieve/reset your API access token</td></tr>");

                // Nest API Access Token
                optionsString.Append("<tr><td class='tableheader' colspan='2'>Nest API Access Token</td></tr>");

                optionsString.Append("<tr><td class='tablecell'>Follow the Retrieve Pin-Code link to obtain a pin-code</td>");
                optionsString.Append("<td class='tablecell'>");
                optionsString = BuildLinkButton(optionsString, "pin_button", "Retrieve Pin-Code", "https://home.nest.com/login/oauth2?client_id=7ba01588-498d-4f20-a524-14c3c8f9134a&state=STATE");
                optionsString.Append("</td></tr>");

                optionsString.Append("<tr><td class='tablecell'>Copy the Pin-Code into this box</td>");
                optionsString.Append("<td class='tablecell'>");
                optionsString = BuildTextBox(optionsString, "pin_code", "Pin-Code", "Pin-Code", "", 200);
                optionsString.Append("</td></tr>");

                optionsString.Append("<tr><td class='tablecell'>Hit the Reset button to renew your access token</td>");
                optionsString.Append("<td class='tablecell'>");
                optionsString = BuildLinkButton(optionsString, "access_button", "Reset Access-Token", "");
                optionsString.Append("</td></tr>");

                optionsString.Append("</table><br>");

                optionsString.Append("<p>If the Reset was successful, restart the plugin and the new token should connect.</p>");


                optionsString.Append("<p>Now hit the Create Homeseer devices to add the Nest devices to homeseer.</p>");
                optionsString = BuildLinkButton(optionsString, "devices_button", "Create Homeseer devices", "");
                optionsString.Append(PageBuilderAndMenu.clsPageBuilder.FormEnd());

                tab.tabContent = optionsString.ToString();
                jqtabs.tabs.Add(tab);

                pluginSB.Append(jqtabs.Build());
                pluginSB.AppendLine("</td></tr></table>");
            }
            catch (Exception ex)
            {
                pluginSB.Append("Status/Options error: " + ex.Message);
            }
            pluginSB.Append("<br>");

            pluginSB.Append(DivEnd());
            page.AddBody(pluginSB.ToString());

            return(page.BuildPage());
        }