Example #1
0
        //ChangeDevStat("Living Room Kitchen Light", "on");
        internal string ChangeDevState(string SwitchName, string state)
        {
            string            retVal   = "";
            SmartThingsDevice stDevice = StDevices.First(d => d.name == SwitchName);
            string            uri      = _baseurl + @"/switchesz/" + stDevice.id + @"/" + state;

            XMLHTTPRequest HTTPRequest = new XMLHTTPRequest(); // u cant reinitialize the var again but not define it again.

            string request = uri;

            HTTPRequest.open("GET", request, false); // get module status
            HTTPRequest.setRequestHeader("Authorization", "Bearer " + _access_token);
            HTTPRequest.setRequestHeader("If-None-Match", "\"doesnt-match-anything\"");
            HTTPRequest.send();

            retVal = HTTPRequest.responseText;

            try
            {
                //JArray jResponse = (JArray)JsonConvert.DeserializeObject(retVal);
                JObject jResponse = (JObject)JsonConvert.DeserializeObject(retVal);
                retVal = jResponse["response"].ToString();
            }
            catch (Exception e)
            {
                retVal = "Error: " + e.Message;
            }
            // This error means requested POST/GET/PUT/DELETE is not allowed
            //"{\"error\":true,\"type\":\"SmartAppException\",\"message\":\"Method Not Allowed\"}"
            //Debugger.Break();

            return(retVal);
        }
Example #2
0
        private void GetAllthings(string uri)
        {
            XMLHTTPRequest HTTPRequest = new XMLHTTPRequest(); // u can reinitialize the var again but not define it again.

            string request      = uri + @"/switches";
            string responseText = "";

            HTTPRequest.open("Get", request, false); // get module status
            HTTPRequest.setRequestHeader("Authorization", "Bearer " + _access_token);
            HTTPRequest.setRequestHeader("If-None-Match", "\"doesnt-match-anything\"");
            //HTTPRequest.setRequestHeader("cache-control", "private");
            HTTPRequest.send();

            responseText = HTTPRequest.responseText;

            try
            {
                StDevices = JsonConvert.DeserializeObject <SmartThingsDevice[]>(responseText); //argh! lol oo it gets multiple  end points..
            }
            catch
            {
                ErrorObject err = JsonConvert.DeserializeObject <ErrorObject>(responseText); //argh! lol oo it gets multiple  end points..
                Console.WriteLine(err.message);
                //Debugger.Break();
            }
            //Console.WriteLine(_stDevices[0].id); // here is ur uri hehe

            _baseurl = uri;

            //Debugger.Break();
        }
Example #3
0
        //[Test]
        public static string Put(string str, string uri)
        {
            string retVal = "";

            XMLHTTPRequest HTTPRequest = new XMLHTTPRequest(); // u cant reinitialize the var again but not define it again.

            string request = uri;

            HTTPRequest.open("PUT", request, false); // get module status
            HTTPRequest.send(str);
            //HTTPRequest.setRequestHeader("Authorization", "Bearer " + _access_token);
            //HTTPRequest.setRequestHeader("If-None-Match", "\"doesnt-match-anything\"");
            //HTTPRequest.send();

            retVal = HTTPRequest.responseText;
            //Console.WriteLine("retVal " + retVal);
            try
            {
                //JArray jResponse = (JArray)JsonConvert.DeserializeObject(retVal);
                retVal = "";
            }
            catch (Exception e)
            {
                retVal = "Error: " + e.Message;
            }

            return(retVal);
        }
Example #4
0
        /// <summary>
        /// Gets the installations path,
        /// from there you get the endpoints with /switches, /energies, /thermostats, et. etc.
        /// </summary>
        private void GetEndPoints()
        {
            XMLHTTPRequest HTTPRequest = new XMLHTTPRequest(); // u cant reinitialize the var again but not define it again.

            string request      = "https://graph.api.smartthings.com/api/smartapps/endpoints";
            string responseText = "";


            HTTPRequest.open("GET", request, false); // get module status
            HTTPRequest.setRequestHeader("Authorization", "Bearer " + _access_token);
            HTTPRequest.send();
            responseText = HTTPRequest.responseText;

            EndPoint[] stEndPoint = JsonConvert.DeserializeObject <EndPoint[]>(responseText); //argh! lol oo it gets multiple  end points..
            Console.WriteLine(stEndPoint[0].uri.ToString());                                  // here is ur uri hehe
            //Debugger.Break();

            GetAllthings(stEndPoint[0].uri);
        }