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 "";
                 *  }
                 * }*/


                //pluginSB.Append("<link rel = 'stylesheet' href = 'hspi_ecobeesiid/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

                this.AddHeader(Util.hs.GetPageHeader(pageName, Util.IFACE_NAME, "", "", false, true));


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

                // Status/Options Tabs

                // Options Tab

                pluginSB.Append(PageBuilderAndMenu.clsPageBuilder.FormStart("myform1", "testpage", "post"));
                pluginSB.AppendLine("<table class='full_width_table' cellspacing='0' width='100%' >");

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

                pluginSB.Append("<tr><td class='tablecell'>Open the link in a new tab and sign in</td>");
                pluginSB.Append("<td class='tablecell'><a href='https://www.ecobee.com/home/ecobeeLogin.jsp'>Ecobee Login</a></td>");
                pluginSB.Append("</td></tr>");

                pluginSB.Append("<tr><td class='tablecell'>Hit the Pin-Code Retrieval button to obtain a new pin code</td>");
                pluginSB.Append("<td class='tablecell'>");
                pluginSB = BuildLinkButton(pluginSB, "pin_get", "Pin-Code Retrieval", "");
                pluginSB.Append("</td></tr>");

                pluginSB.Append("<tr><td class='tablecell'>Copy the pin-code, add an application on the MyApps page within the Ecobee portal and manually enter the pin code</td>");
                pluginSB.Append("<td class='tablecell'>");

                clsJQuery.jqScrollingRegion sr = new clsJQuery.jqScrollingRegion("pin_region");
                sr.className = "";
                sr.AddStyle("height:20px;overflow:auto;width: 35px;background: #FFFFFF;");
                sr.content = "[pin]";
                pluginSB.Append(sr.Build());

                //pluginSB = BuildTextBox(pluginSB, "pin_code", "Pin-Code", "Pin-Code", "", 200);
                pluginSB.Append("</td></tr>");

                pluginSB.Append("<tr><td class='tablecell'>After validating the pin code, hit the Reset/Retrieve Access-Token button to reset your access token</td>");
                pluginSB.Append("<td class='tablecell'>");
                pluginSB = BuildLinkButton(pluginSB, "access_button", "Reset/Retrieve Access-Token", "");

                pluginSB.Append("</td></tr>");

                pluginSB.Append("<tr><td class='tablecell'>Finally, hit the Create Homeseer devices button to add the Ecobee thermostat devices to Homeseer</td>");
                pluginSB.Append("<td class='tablecell'>");
                pluginSB = BuildLinkButton(pluginSB, "devices_button", "Create Homeseer devices", "");

                pluginSB.Append("</td></tr>");

                pluginSB.Append("</td></tr>");

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

                pluginSB.Append(PageBuilderAndMenu.clsPageBuilder.FormEnd());
            }
            catch (Exception ex)
            {
                pluginSB.Append("Status/Options error: " + ex.Message);
            }
            pluginSB.Append("<br>");

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

            return(page.BuildPage());
        }