Пример #1
0
        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));
        }
Пример #2
0
        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));
        }
Пример #3
0
        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));
        }
Пример #4
0
        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));
        }
Пример #5
0
        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));
        }
Пример #6
0
        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));
        }
Пример #7
0
        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()));
        }