public override string postBackProc(string page, string data, string user, int userRights) { System.Collections.Specialized.NameValueCollection parts = null; parts = HttpUtility.ParseQueryString(data); Console.WriteLine(data); string id = parts["id"]; if (parts["pin_code"] != null) { pin_code = parts["pin_code"]; Console.WriteLine(pin_code); } if (parts["id"] != null && parts["id"].Contains("access_button")) { using (var nest = new NestConnection()) { if (nest.retrieveAccess(pin_code)) { pageCommands.Add("popmessage", "Successfully reset Access Token"); } else { pageCommands.Add("popmessage", "Failed to reset Access Token"); } } } return(base.postBackProc(page, data, user, userRights)); }
public void RunObservableUpdate() { using (var nest = new NestConnection()) { nest.setInitialConnectionProps(); if (nest.isAccessNotNull()) { nest.connectNestData(); } } }
public override string postBackProc(string page, string data, string user, int userRights) { System.Collections.Specialized.NameValueCollection parts = null; parts = HttpUtility.ParseQueryString(data); Console.WriteLine(data); string id = parts["id"]; if (parts["pin_code"] != null) { pin_code = parts["pin_code"]; Console.WriteLine(pin_code); } if (parts["id"] != null && parts["id"].Contains("access_button")) { using (var nest = new NestConnection()) { if (nest.retrieveAccess(pin_code)) { pageCommands.Add("popmessage", "Successfully reset Access Token"); } else { pageCommands.Add("popmessage", "Failed to reset Access Token"); } } } if (id == "devices_button") { using (var nest = new NestConnection()) { nest.setInitialConnectionProps(); if (nest.isAccessNotNull()) { using (var nestData = nest.getNestData()) { Util.Find_Create_Devices(nestData.Devices, true); Util.Find_Create_Structures(nestData.Structures, true); } } else { Util.Log("Access Token is null", Util.LogType.LOG_TYPE_ERROR); } } } return(base.postBackProc(page, data, user, userRights)); }
private void updateStatusValues() { try { if (!observeRunning) // Set True in NestConnection.connectNestData() { observeRunning = true; System.Threading.Tasks.Task.Factory.StartNew(() => RunObservableUpdate()); } if (!running) { using (var nest = new NestConnection()) { running = true; nest.setInitialConnectionProps(); if (nest.isAccessNotNull()) { using (var nestData = nest.getNestData()) { Util.Find_Create_Devices(nestData.Devices, false); Util.Find_Create_Structures(nestData.Structures, false); } } else { Util.Log("Access Token is null", Util.LogType.LOG_TYPE_ERROR); } running = false; } } } catch (Exception ex) { //Console.WriteLine("Failed: No API Key?"); Util.Log(ex.ToString(), Util.LogType.LOG_TYPE_ERROR); System.IO.File.WriteAllText(@"Data/HSPI_Nest_Thermostat_and_Camera_Plugin/debug.txt", ex.ToString()); if (ex.ToString().Contains("connectNestData")) { observeRunning = false; } running = false; } }
public void NestControls(List <HomeSeerAPI.CAPI.CAPIControl> colSend) { foreach (var CC in colSend) { try { Util.Log("SetIOMulti set value: " + CC.ControlValue.ToString() + "->ref:" + CC.Ref.ToString(), Util.LogType.LOG_TYPE_INFO); using (var nest = new NestConnection()) { nest.setInitialConnectionProps(); DeviceClass dv = (DeviceClass)Util.hs.GetDeviceByRef(CC.Ref); string name; string id = Util.GetDeviceKeys(dv, out name); if (name == "Is Streaming") { if (CC.Label == "On") { nest.setApiJson("{\"is_streaming\": true}", "devices/cameras", id); //Util.hs.SetDeviceValueByRef(CC.Ref, 1, true); } if (CC.Label == "Off") { nest.setApiJson("{\"is_streaming\": false}", "devices/cameras", id); //Util.hs.SetDeviceValueByRef(CC.Ref, 0, true); } } if (name == "HVAC Mode") { if (CC.Label.Equals("Auto")) { nest.setApiJson("{\"hvac_mode\": \"" + "heat-cool" + "\"}", "devices/thermostats", id); } else { nest.setApiJson("{\"hvac_mode\": \"" + CC.Label.ToLower() + "\"}", "devices/thermostats", id); } /* * if (CC.Label.Equals("Off")) * { * Util.hs.SetDeviceValueByRef(CC.Ref, 0, true); * } * if (CC.Label.Equals("Auto")) * { * Util.hs.SetDeviceValueByRef(CC.Ref, 1, true); * } * if (CC.Label.Equals("Cool")) * { * Util.hs.SetDeviceValueByRef(CC.Ref, 2, true); * } * if (CC.Label.Equals("Heat")) * { * Util.hs.SetDeviceValueByRef(CC.Ref, 3, true); * } * if (CC.Label.Equals("Eco")) * { * Util.hs.SetDeviceValueByRef(CC.Ref, 4, true); * } */ } if (name.Contains("Temperature")) { using (var nestData = nest.getNestData()) { var currentTemp = dv.get_devValue(Util.hs); var targetWithScale = ""; foreach (var thermostat in nestData.Devices.thermostats) { //Console.WriteLine(thermostat.Value.hvac_mode); //Console.WriteLine(id[5]); if (!thermostat.Value.hvac_mode.Equals("eco")) { if (name == "Target Temperature") { if (thermostat.Value.temperature_scale.Equals("F")) { targetWithScale = "target_temperature_f"; } else { targetWithScale = "target_temperature_c"; } } if (name == "Target Temperature Low") { if (thermostat.Value.temperature_scale.Equals("F")) { targetWithScale = "target_temperature_low_f"; currentTemp = thermostat.Value.target_temperature_low_f; } else { targetWithScale = "target_temperature_low_c"; currentTemp = thermostat.Value.target_temperature_low_c; } } if (name == "Target Temperature High") { if (thermostat.Value.temperature_scale.Equals("F")) { targetWithScale = "target_temperature_high_f"; currentTemp = thermostat.Value.target_temperature_high_f; } else { targetWithScale = "target_temperature_high_c"; currentTemp = thermostat.Value.target_temperature_high_c; } } } else { if (name == "Target Temperature Low") { if (thermostat.Value.temperature_scale.Equals("F")) { targetWithScale = "eco_temperature_low_f"; currentTemp = thermostat.Value.eco_temperature_low_f; } else { targetWithScale = "eco_temperature_low_c"; currentTemp = thermostat.Value.eco_temperature_low_c; } } if (name == "Target Temperature High") { if (thermostat.Value.temperature_scale.Equals("F")) { targetWithScale = "eco_temperature_high_f"; currentTemp = thermostat.Value.eco_temperature_high_f; } else { targetWithScale = "eco_temperature_high_c"; currentTemp = thermostat.Value.eco_temperature_high_c; } } } } nest.setApiJson("{\"" + targetWithScale + "\": " + CC.ControlValue + "}", "devices/thermostats", id); } } if (name == "Structure") { var structId = ""; using (var nestData = nest.getNestData()) { foreach (var structure in nestData.Structures) { if (structure.Value.thermostats.Contains(id)) { structId = structure.Value.structure_id; } } string jsonValue = ""; if (CC.Label == "Away") { jsonValue = "away"; //Util.hs.SetDeviceValueByRef(CC.Ref, 0, true); } if (CC.Label == "Home") { jsonValue = "home"; //Util.hs.SetDeviceValueByRef(CC.Ref, 1, true); } Console.WriteLine("{\"away\": \"" + jsonValue + "\"}"); nest.setApiJson("{\"away\": \"" + jsonValue + "\"}", "structures", structId); } } } } catch (Exception e) { Util.Log(e.ToString(), Util.LogType.LOG_TYPE_ERROR); } } updateStatusValues();//after sending a command, update with the new status }