public ActionResult Timeline() { var cx = SmartHomeDBContext.Create(AppSettings); var model = cx.EventLists.AsQueryable().OrderByDescending(e => e.Created).Take(25); return(View(model)); }
public ActionResult SettingHeating(IFormCollection form) { var cx = SmartHomeDBContext.Create(AppSettings); Guid gid = new Guid(AppSettings.JABLOTRON); var model = cx.Devices.Single(e => e.DeviceId == gid); var conf = SmartHomeConfig.Deserialize(model.Config); conf.homeheatingoutofhometemp = int.Parse(form["homeheatingoutofhometemp"]); conf.homeheatingoutofhome = (form["homeheatingoutofhome"].Contains("true")); List <SmartHomeConfig.MySmartHomeHeatingItem> data = new List <SmartHomeConfig.MySmartHomeHeatingItem>(); foreach (var i in form.Keys.Where(e => e.StartsWith("ht_"))) { var iarr = i.Split('_'); DayOfWeek _d = (DayOfWeek)int.Parse(iarr[1]); int _h = int.Parse(iarr[2]); decimal _t = decimal.Parse(form[i]); var k = new SmartHomeConfig.MySmartHomeHeatingItem(); k.d = _d; k.h = _h; k.t = _t; data.Add(k); } conf.heatingitems = data.ToArray(); model.Config = conf.Serialize(); cx.SaveChanges(); return(View(conf)); }
public ActionResult Setting(IFormCollection form) { var cx = SmartHomeDBContext.Create(AppSettings); Guid gid = new Guid(AppSettings.UNIT1); var model = cx.Devices.Single(e => e.DeviceId == gid); var conf = SmartHomeConfig.Deserialize(model.Config); conf.dogontemp = int.Parse(form["dogontemp"]); conf.irrigationOn = (form["irrigationOn"].Contains("true")); conf.christmasOn = (form["christmasOn"].Contains("true")); conf.ClearWaterItems(); for (int i = 0; i < 20; i++) { string f = "irrigation" + i.ToString(); if (form.ContainsKey(f)) { var itm = new SmartHomeConfig.MySmartHomeConfigWaterItem(); itm.starthour = form[f]; itm.intervalsec = int.Parse(form[f + "m"]) * 60; conf.AddWaterItem(itm); } } model.Config = conf.Serialize(); cx.SaveChanges(); return(View(conf)); }
public ActionResult SettingHeating() { var cx = SmartHomeDBContext.Create(AppSettings); Guid gid = new Guid(AppSettings.JABLOTRON); var model = SmartHomeConfig.Deserialize(cx.Devices.Single(e => e.DeviceId == gid).Config); return(View(model)); }
public ActionResult Water() { var cx = SmartHomeDBContext.Create(AppSettings); ViewBag.Saved = ""; Guid gid = new Guid(AppSettings.UNIT1); var model = SmartHomeConfig.Deserialize(cx.Devices.Single(e => e.DeviceId == gid).Config); return(View(model)); }
private ActionResult stats(Guid gid) { var cx = SmartHomeDBContext.Create(AppSettings); var fromD = DateTime.Now.AddDays(-1); var toD = DateTime.Now; var firstlist = from s in cx.DeviceLogs where s.DeviceId == gid && s.Created > fromD && s.Created <= toD select s; var list = from s in firstlist.ToList() let groupKey = new DateTime(s.Created.Year, s.Created.Month, s.Created.Day, s.Created.Hour, (s.Created.Minute / 10) * 10, 0) group s by groupKey into g select new { Timestamp = g.Key, DogHouseHeat = g.Max(e => e.DogHouseHeatingOn), DogHouseTemp = g.Average(e => e.DogHouseTemperature), IsWet = g.Max(e => e.IsWet), WaterOn = g.Max(e => e.WaterOn), Temp = g.Average(e => e.Temperature) }; var finallist = list.OrderBy(e => e.Timestamp); var ret = new StatObject(); foreach (var i in finallist) { var itm = new StatItem(); itm.dogheating = i.DogHouseHeat; itm.dogtemp = i.DogHouseTemp; itm.iswet = i.IsWet; itm.temp = i.Temp; itm.time = MySmartHomeCore.Extensions.DateTimeUtil.GetZonedDate(i.Timestamp, "HH:mm"); itm.wateron = i.WaterOn; if (ret.min > itm.dogtemp) { ret.min = itm.dogtemp; } if (ret.min > itm.temp) { ret.min = itm.temp; } if (ret.max < itm.dogtemp) { ret.max = itm.dogtemp; } if (ret.max < i.Temp) { ret.max = itm.temp; } ret.items.Add(itm); } return(View(ret)); }
public ActionResult IndexPartial() { var cx = SmartHomeDBContext.Create(AppSettings); var model = new HomeIndexData(); Guid gid = new Guid(AppSettings.UNIT1); model.unit1 = cx.Devices.Single(e => e.DeviceId == gid); gid = new Guid(AppSettings.JABLOTRON); model.jablotron = cx.Jablotrons.Single(e => e.DeviceId == gid); return(Content(RenderPartialViewToString("_HomeData", model))); }
public ActionResult IndexHash() { var cx = SmartHomeDBContext.Create(AppSettings); var model = new HomeIndexData(); Guid gid = new Guid(AppSettings.UNIT1); model.unit1 = cx.Devices.Single(e => e.DeviceId == gid); gid = new Guid(AppSettings.JABLOTRON); model.jablotron = cx.Jablotrons.Single(e => e.DeviceId == gid); return(Content(model.checksum())); }
public ActionResult Water(IFormCollection form) { var cx = SmartHomeDBContext.Create(AppSettings); ViewBag.Saved = "YES"; Guid gid = new Guid(AppSettings.UNIT1); var model = cx.Devices.Single(e => e.DeviceId == gid); var conf = SmartHomeConfig.Deserialize(model.Config); conf.water = new SmartHomeConfig.MySmartHomeConfigWaterHardOn(); conf.water.from = DateTime.Now; conf.water.to = DateTime.Now.AddMinutes(1); model.Config = conf.Serialize(); cx.SaveChanges(); return(View(conf)); }
public ActionResult Index(string cmd) { if (cmd == null) { cmd = ""; } var cx = SmartHomeDBContext.Create(AppSettings); var model = new HomeIndexData(); Guid gid = new Guid(AppSettings.UNIT1); model.unit1 = cx.Devices.Single(e => e.DeviceId == gid); gid = new Guid(AppSettings.JABLOTRON); model.jablotron = cx.Jablotrons.Single(e => e.DeviceId == gid); switch (cmd) { case "switchwater": { var conf = SmartHomeConfig.Deserialize(model.unit1.Config); conf.water = new SmartHomeConfig.MySmartHomeConfigWaterHardOn(); conf.irrigationOn = !conf.irrigationOn; model.unit1.Config = conf.Serialize(); cx.SaveChanges(); return(RedirectToAction("Index")); } //break; case "switchalarm": { if (model.jablotron.CommandToExecute == "") { model.jablotron.CommandToExecute = model.jablotron.State == "IDLE" ? "ARM" : "DISARM"; } else { model.jablotron.CommandToExecute = model.jablotron.CommandToExecute == "ARM" ? "DISARM" : "ARM"; } cx.SaveChanges(); return(RedirectToAction("Index")); } //break; } return(View(model)); }
public JToken Log(string id, JToken data) { var gid = new Guid(id); var obj = SmartHomeDataList.Create(data.ToString()); var cx = SmartHomeDBContext.Create(AppSettings); // get device detail, if there is no device we will throw exception var device = cx.Devices.Single(e => e.DeviceId == gid); for (int i = 0; i < obj.data.Length; i++) { var itm = obj.data[i]; var tmstmp = new DateTime(itm.timestamp.Year, itm.timestamp.Month, itm.timestamp.Day, itm.timestamp.Hour, (itm.timestamp.Minute / 10) * 10, 0); var curr = cx.DeviceLogs.SingleOrDefault(e => e.DeviceId == gid && e.Created == tmstmp); if (curr == null) { var d = new DeviceLog(); d.Created = tmstmp; d.DeviceId = gid; d.DogHouseHeatingOn = itm.doghouseheating; d.DogHouseTemperature = (decimal)itm.doghousetemp; d.Temperature = (decimal)itm.outsidetemp; d.WaterOn = itm.waterswitchon; d.IsWet = itm.iswet; cx.DeviceLogs.Add(d); } else { var d = curr; if (itm.doghouseheating) { d.DogHouseHeatingOn = itm.doghouseheating; } d.DogHouseTemperature = (d.DogHouseTemperature * 9 + (decimal)itm.doghousetemp) / 10; d.Temperature = (d.Temperature * 9 + (decimal)itm.outsidetemp) / 10; if (itm.waterswitchon) { d.WaterOn = itm.waterswitchon; } if (itm.iswet) { d.IsWet = itm.iswet; } } if (i == (obj.data.Length - 1)) { device.Contacted = itm.timestamp; device.DogHouseHeatingOn = itm.doghouseheating; device.DogHouseTemperature = (decimal)itm.doghousetemp; device.Temperature = (decimal)itm.outsidetemp; device.WaterOn = itm.waterswitchon; device.IsWet = itm.iswet; } cx.SaveChanges(); } var conf = SmartHomeConfig.Deserialize(device.Config); if (!conf.irrigationOn) { conf.ClearWaterItems(); } return(JObject.Parse(conf.Serialize())); }
public JToken Log(string id, JToken data) { var gid = new Guid(id); var obj = JablotronDataList.Create(data.ToString()); var cx = SmartHomeDBContext.Create(AppSettings); // get device detail, if there is no device we will throw exception var device = cx.Jablotrons.Single(e => e.DeviceId == gid); var prevData = new JablotronData(); for (int i = 0; i < obj.data.Length; i++) { var itm = obj.data[i]; string newData = JsonConvert.SerializeObject(itm); if (!prevData.IsEqual(itm)) { var newEntryObj = new EventListEntry(); newEntryObj.Icon = "ALARM-" + itm.GetArmStateEx().ToString(); switch (itm.GetArmStateEx()) { case AlarmStateEx.IDLE: newEntryObj.Row1 = "Alarm OFF"; newEntryObj.Row2 = ""; break; case AlarmStateEx.ARMED: newEntryObj.Row1 = "Alarm ARMED"; newEntryObj.Row2 = "Zones: " + itm.armedzone; break; case AlarmStateEx.ALARM: newEntryObj.Row1 = "ALARM"; newEntryObj.Row2 = "Zone: " + EventListEntry.DecodeDevice(itm.deviceid, AppSettings.JABLOTRONZONES); break; } if (device.Note != newEntryObj.Serialize()) { var entry = new EventList(); entry.DeviceId = device.DeviceId; entry.Created = DateTime.Now; entry.EventCode = newEntryObj.Icon; entry.EventText = newEntryObj.Serialize(); cx.EventLists.Add(entry); cx.SaveChanges(); device.Note = entry.EventText; } device.Contacted = itm.timestamp; if (itm.commandexecuted != "") { device.CommandToExecute = ""; } device.LED_A = itm.led_a; device.LED_B = itm.led_b; device.LED_C = itm.led_c; device.LED_Warning = itm.led_warning; device.State = itm.state; } cx.SaveChanges(); } var ret = new JablotronResponse(); ret.status = "OK"; ret.commandtoexecute = device.CommandToExecute; return(JObject.Parse(JsonConvert.SerializeObject(ret))); }