// WILLR RETURN A LIST OF ALL THERMOSTATS WITH THIER NAME, STATE etc... public async Task<IEnumerable<Camera>> GetCameras() { var url = "https://developer-api.nest.com"; var fb = new Firebase(url, ACCESS_TOKEN); dynamic devices = await fb.GetAsync("devices/cameras"); // will return a string dynamic devicesJSON = JObject.Parse(devices); List<Camera> cameras = new List<Camera>(); foreach (dynamic device in devicesJSON) { // can use this to access properties of thermostat // i.e. device.First.humidity; var cameraJSON = device.First; Camera camera = new Camera(); camera.Device_Id = cameraJSON.device_id; camera.Name_Long = cameraJSON.name_long; camera.Is_Online = cameraJSON.is_online; camera.Is_Streaming = cameraJSON.is_streaming; cameras.Add(camera); } return cameras; }
// WILLR RETURN A LIST OF ALL THERMOSTATS WITH THIER NAME, STATE etc... public async Task<IEnumerable<SmokeCoAlarmVM>> GetCameras() { var url = "https://developer-api.nest.com"; var fb = new Firebase(url, ACCESS_TOKEN); dynamic devices = await fb.GetAsync("devices/smoke_co_alarms"); // will return a string dynamic devicesJSON = JObject.Parse(devices); List<SmokeCoAlarmVM> smokecoalarms = new List<SmokeCoAlarmVM>(); foreach (dynamic device in devicesJSON) { // can use this to access properties of thermostat // i.e. device.First.humidity; var smokecoalarmJSON = device.First; SmokeCoAlarmVM smokecoalarm = new SmokeCoAlarmVM(); smokecoalarm.Device_Id = smokecoalarmJSON.device_id; smokecoalarm.Name_Long = smokecoalarmJSON.name_long; smokecoalarm.Is_Online = smokecoalarmJSON.is_online; smokecoalarm.Smoke_Alarm_State= smokecoalarmJSON.smoke_alarm_state; smokecoalarm.Co_Alarm_State = smokecoalarmJSON.co_alarm_state; smokecoalarms.Add(smokecoalarm); } return smokecoalarms; }
// WILLR RETURN A LIST OF ALL THERMOSTATS WITH THIER NAME, STATE etc... public async Task<IEnumerable<ThermostatVM>> GetThermostats() { var url = "https://developer-api.nest.com"; var fb = new Firebase(url, ACCESS_TOKEN); dynamic devices = await fb.GetAsync("devices/thermostats"); // will return a string dynamic devicesJSON = JObject.Parse(devices); List<ThermostatVM> thermostats = new List<ThermostatVM>(); foreach(dynamic device in devicesJSON) { // can use this to access properties of thermostat // i.e. device.First.humidity; var thermostatJSON = device.First; ThermostatVM thermostat = new ThermostatVM(); thermostat.Device_Id = thermostatJSON.device_id; thermostat.Name_Long = thermostatJSON.name_long; thermostat.Current_Temperature = thermostatJSON.ambient_temperature_c; thermostat.Target_Temperature = thermostatJSON.target_temperature_c; thermostats.Add(thermostat); } return thermostats; }
public async Task<ThermostatVM> GetThermostat() { var url = "https://developer-api.nest.com"; var fb = new Firebase(url, ACCESS_TOKEN); dynamic devices = await fb.GetAsync("devices"); var jsonParsed = JsonConvert.DeserializeObject<dynamic>(devices); var thermostats = jsonParsed.thermostats; string dev_id = jsonParsed["thermostats"]["is8MQBKrH-h-UWxetdv7-o-BBzEt2ynq"].device_id; string name = jsonParsed["thermostats"]["is8MQBKrH-h-UWxetdv7-o-BBzEt2ynq"].name_long; string curr_temp = jsonParsed["thermostats"]["is8MQBKrH-h-UWxetdv7-o-BBzEt2ynq"].ambient_temperature_c; string tar_temp = jsonParsed["thermostats"]["is8MQBKrH-h-UWxetdv7-o-BBzEt2ynq"].target_temperature_c; ThermostatVM myThermostat = new ThermostatVM(dev_id, name, curr_temp, tar_temp); return myThermostat; }
/// <summary> /// Gets the news. /// </summary> /// <returns></returns> public async Task <IEnumerable <ViewModels.News> > GetNews() { var rootUri = ConfigurationManager.AppSettings.Get("FirebaseUri"); var authToken = ConfigurationManager.AppSettings.Get("FirebaseAuthToken"); var fb = new FB.Firebase(rootUri, authToken); var data = await fb.GetAsync("news"); try { var result = JsonConvert.DeserializeObject <IEnumerable <ViewModels.News> >(data); var select = result.Where(CurrentNews).OrderBy(s => s.Order); return(select); } catch (Exception exp) { } return(Enumerable.Empty <ViewModels.News>()); }
public async Task<JsonResult> GetThermoStatTemp(string accessToken, string id ) { var url = "https://developer-api.nest.com"; var fb = new Firebase(url, accessToken); dynamic devices = await fb.GetAsync("devices/thermostats/" + id ); return Json(devices, JsonRequestBehavior.AllowGet); }
public async Task<JsonResult> GetSmokeAlarmData(string accessToken) { var url = "https://developer-api.nest.com"; var fb = new Firebase(url, accessToken); dynamic devices = await fb.GetAsync("devices/smoke_co_alarms"); return Json(devices, JsonRequestBehavior.AllowGet); }
public async Task<string> GetDeviceData(string accessToken) { // CREATE A CLIENT WE CAN ACCESS DATA THROUGH var url = "https://developer-api.nest.com"; var fb = new Firebase(url, accessToken); dynamic devices = await fb.GetAsync("devices"); var jsonParsed = JsonConvert.DeserializeObject<dynamic>(devices); var thermostats = jsonParsed.thermostats; string dev_id = jsonParsed["thermostats"]["5TN0NLa65q3XoSjECHNUvI-BBzEt2ynq"].device_id; string name = jsonParsed["thermostats"]["5TN0NLa65q3XoSjECHNUvI-BBzEt2ynq"].name_long; string curr_temp = jsonParsed["thermostats"]["5TN0NLa65q3XoSjECHNUvI-BBzEt2ynq"].ambient_temperature_c; string tar_temp = jsonParsed["thermostats"]["5TN0NLa65q3XoSjECHNUvI-BBzEt2ynq"].target_temperature_c; Thermostat myThermostat = new Thermostat(dev_id, name, curr_temp, tar_temp); //return Json(devices, JsonRequestBehavior.AllowGet); return myThermostat.ToString(); }