Created
November 10, 2014 17:17
-
-
Save keroger2k/474d761f4a59f6c89007 to your computer and use it in GitHub Desktop.
Nest API Starter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Program | |
| { | |
| const string CLIENT_ID = @"my_client_id"; | |
| const string CLIENT_SECRET = @"my_secret"; | |
| const string DEVICE_ID = @"my_device_id"; | |
| const string AUTH_CODE_URL = @"https://home.nest.com/login/oauth2?client_id=a6e9c798-52ba-46ff-8a7d-ecccb9e2ae75&state=STATE"; | |
| const string AUTH_CODE = @"my_auth_code"; | |
| const string ACCESS_TOKEN_URL = @"https://api.home.nest.com/oauth2/access_token?client_id={0}&code={1}&client_secret={2}&grant_type=authorization_code"; | |
| const string ACCESS_TOKEN = @"my_access_token"; | |
| const string DEV_NET = @"https://developer-api.nest.com/devices/thermostats?auth={0}"; | |
| static void Main(string[] args) | |
| { | |
| WebRequest request = WebRequest.Create(string.Format(DEV_NET, ACCESS_TOKEN)); | |
| WebResponse response = request.GetResponse(); | |
| Stream dataStream = response.GetResponseStream(); | |
| StreamReader reader = new StreamReader(dataStream); | |
| JavaScriptSerializer js = new JavaScriptSerializer(); | |
| var tmpNestObject = js.Deserialize<dynamic>(reader.ReadToEnd()); | |
| Nest thermostatStatistics = js.Deserialize<Nest>(js.Serialize(tmpNestObject[DEVICE_ID])); | |
| reader.Close(); | |
| response.Close(); | |
| Console.WriteLine(string.Format("{0} has a current temperature of {1}°F", thermostatStatistics.name, thermostatStatistics.ambient_temperature_f)); | |
| Console.ReadLine(); | |
| } | |
| } | |
| public class Nest | |
| { | |
| public string locale { get; set; } | |
| public string temperature_scale { get; set; } | |
| public bool is_using_emergency_heat { get; set; } | |
| public bool has_fan { get; set; } | |
| public string software_version { get; set; } | |
| public bool has_leaf { get; set; } | |
| public string device_id { get; set; } | |
| public string name { get; set; } | |
| public string hvac_mode { get; set; } | |
| public bool can_heat { get; set; } | |
| public bool can_cool { get; set; } | |
| public float target_temperature_c { get; set; } | |
| public float target_temperature_f { get; set; } | |
| public float target_temperature_high_c { get; set; } | |
| public float target_temperature_high_f { get; set; } | |
| public float target_temperature_low_c { get; set; } | |
| public float target_temperature_low_f { get; set; } | |
| public float ambient_temperature_c { get; set; } | |
| public float ambient_temperature_f { get; set; } | |
| public float away_temperature_high_c { get; set; } | |
| public float away_temperature_high_f { get; set; } | |
| public float away_temperature_low_c { get; set; } | |
| public float away_temperature_low_f { get; set; } | |
| public string name_long { get; set; } | |
| public bool fan_timer_active { get; set; } | |
| public bool is_online { get; set; } | |
| public DateTime last_connection { get; set; } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment