public void Execute() { var thermostats = Thermostats.Read(); var thermostat = thermostats.ThermostatWithSerial(serial); if (thermostat == null) { Console.Error.WriteLine($"Thermostat with serial {serial} not found. Have you run the read command first?"); Environment.Exit(1); } var parsedThermostat = new ParsedThermostat(thermostat); switch (attributeName) { case SET_POINT_TEMPERATURE: SetSetPointTemperature(thermostat); break; case VACATION_PERIOD: SetVacationPeriod(thermostat); break; case CANCEL_VACATION: CancelVacation(thermostat); break; default: Console.Error.WriteLine($"Only setting {SET_POINT_TEMPERATURE}, {VACATION_PERIOD}, and {CANCEL_VACATION} supported for now"); Environment.Exit(1); break; } thermostats.Write(); }
public void Execute() { var thermostats = Thermostats.Read(); thermostats.RemoveThermostatWithSerial(serial); thermostats.Write(); }
public void Execute() { var thermostats = Thermostats.Read(); foreach (var thermostat in thermostats.thermostats) { Console.WriteLine(thermostat.Serial); } }
public void GetAll() { Thermostats.Clear(); SelectedThermostat = null; foreach (var item in context.GetAll()) { Thermostats.Add(item); } }
public Write(string serial, IBluetooth bluetooth) { this.serial = serial; thermostats = Thermostats.Read(); accessor = new PeripheralAccessor(bluetooth); if (!thermostats.HasSecretAndUuidFor(serial)) { Console.Error.WriteLine($"Has not previously connected to {serial}. Do a read first."); Environment.Exit(1); } }
public void Execute() { var thermostats = Thermostats.Read(); var thermostat = thermostats.ThermostatWithSerial(serial); if (thermostat == null) { Console.Error.WriteLine($"Thermostat with serial {serial} not found. Have you run the read command first?"); Environment.Exit(1); } var parsed = new ParsedThermostat(thermostat); Console.WriteLine($"Device name: {parsed.DeviceName}"); Console.WriteLine($"Device UUID: {thermostat.Uuid}"); Console.WriteLine($"Battery level: {parsed.BatteryLevelPercent}%"); Console.WriteLine(""); Console.WriteLine($"Set-point/room temperature: {parsed.SetPointTemperature} / {parsed.RoomTemperature}"); Console.WriteLine($"Home/away temperature: {parsed.HomeTemperature} / {parsed.AwayTemperature}"); Console.WriteLine($"Vacation/frost protection temperature: {parsed.VacationTemperature} / {parsed.FrostProtectionTemperature}"); Console.WriteLine($"Schedule mode: {parsed.ScheduleMode}"); if (parsed.VacationFrom != null && parsed.VacationTo != null) { Console.WriteLine($"Vacation: {parsed.VacationFrom} - {parsed.VacationTo}"); } Console.WriteLine(""); Console.WriteLine($"Monday:\n{parsed.MondaySchedule}"); Console.WriteLine(""); Console.WriteLine($"Tuesday:\n{parsed.TuesdaySchedule}"); Console.WriteLine(""); Console.WriteLine($"Wednesday:\n{parsed.WednesdaySchedule}"); Console.WriteLine(""); Console.WriteLine($"Thursday:\n{parsed.ThursdaySchedule}"); Console.WriteLine(""); Console.WriteLine($"Friday:\n{parsed.FridaySchedule}"); Console.WriteLine(""); Console.WriteLine($"Saturday:\n{parsed.SaturdaySchedule}"); Console.WriteLine(""); Console.WriteLine($"Sunday:\n{parsed.SundaySchedule}"); if (thermostat.HasUpdatedAttributes) { Console.WriteLine(""); Console.WriteLine("Attributes to be updated:"); if (thermostat.UpdatedSetPointTemperature != null) { Console.WriteLine($"Set-point temperature: {thermostat.UpdatedSetPointTemperature}"); } if (thermostat.HasUpdatedVacationPeriod) { if (thermostat.UpdatedVacationPeriod != null) { Console.WriteLine($"Vacation: {thermostat.UpdatedVacationPeriod.From} - {thermostat.UpdatedVacationPeriod.To}"); } else { Console.WriteLine("Clear upcoming vacation period"); } } } }
public Read(string serial, IBluetooth bluetooth) { this.serial = serial; thermostats = Thermostats.Read(); accessor = new PeripheralAccessor(bluetooth); }
private void CheckIn(ThermostatMonitorLib.Location location) { StreamReader reader = new StreamReader(Request.InputStream, Request.ContentEncoding); string jsonInput = reader.ReadToEnd(); reader.Close(); reader.Dispose(); CheckinRequest request = CheckinRequest.Load(location, jsonInput); CheckinResponse response = new CheckinResponse(); //Update inside temperature and thermostat state foreach (Thermostat thermostat in request.Thermostats) { string key = location.Id.ToString() + "_" + thermostat.IpAddress; Thermostat previousThermostat = new Thermostat(); if (Thermostats.Cache.ContainsKey(key)) { previousThermostat = (Thermostat)Thermostats.Cache[key]; } if (thermostat.Temperature != previousThermostat.Temperature) { LogTemperatureChange(location.Id, thermostat, previousThermostat); } if (thermostat.State != previousThermostat.State) { LogStateChange(location.Id, thermostat, previousThermostat); } Thermostats.Cache[key] = thermostat; } //Update outside temperature response.ZipCode = request.ZipCode; string cacheKey = "OutsideTemperature" + location.Id.ToString(); if (Cache.Get(cacheKey) == null) { try { response.OutsideTemperature = ThermostatMonitorLib.Weather.GetTemperature(location.OpenWeatherCityId); Cache.Add(cacheKey, response.OutsideTemperature, null, DateTime.Now.AddMinutes(4).AddSeconds(30), TimeSpan.Zero, System.Web.Caching.CacheItemPriority.Normal, null); } catch {} } else { response.OutsideTemperature = Convert.ToInt32(Cache.Get(cacheKey)); } int previousTemperature = -999; if (CheckinResponse.ConditionHash.ContainsKey(location.Id)) { previousTemperature = Convert.ToInt32(CheckinResponse.ConditionHash[location.Id]); } if (response.OutsideTemperature != previousTemperature && response.OutsideTemperature != 0) { ThermostatMonitorLib.OutsideCondition.Log(location.Id, response.OutsideTemperature); } CheckinResponse.ConditionHash[location.Id] = response.OutsideTemperature; //Add any pending commands to the response response.ReplyCommands = Commands.Get(location.Id); Commands.Remove(location.Id); try { Thermostats.CleanCache(); } catch (Exception ex) { ThermostatMonitorLib.Error error = new ThermostatMonitorLib.Error(); error.ErrorMessage = ex.ToString(); error.LogDate = DateTime.Now; error.UserId = 0; error.Url = "/json/default.aspx"; ThermostatMonitorLib.Error.SaveError(error); } Response.Write(response.GetJson()); Response.End(); }