Exemplo n.º 1
0
        /// <summary>
        /// Initializes thermostat default values from appsettings.json
        /// if they don't exist in DB
        /// </summary>
        public void Init()
        {
            var connectionString = _appConfig.GetConnectionString("MomitKiller");

            using (var db = new MomitKillerDbContext(connectionString))
            {
                _configuration = db.Configuration.FirstOrDefault();
                if (_configuration == null)
                {
                    var thermostatDefaults = _appConfig
                                             .GetSection("ThermostatDefaults");

                    _configuration = new Configuration()
                    {
                        Id          = 1,
                        Temperature = thermostatDefaults
                                      .GetValue <float>("Temperature"),

                        Hysteresis = thermostatDefaults
                                     .GetValue <float>("Hysteresis")
                    };

                    db.Configuration.Add(_configuration);
                    db.SaveChanges();
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Initializes thermostat default values from appsettings.json
        /// if they don't exist in DB
        /// </summary>
        public void Init()
        {
            var connectionString = _appSettings.GetConnectionString("MomitKiller");

            using (var db = new MomitKillerDbContext(connectionString))
            {
                _thermostatConfig = db.ThermostatConfig.FirstOrDefault();
                if (_thermostatConfig == null)
                {
                    var thermostatDefaults = _appSettings
                                             .GetSection("ThermostatDefaults");

                    _thermostatConfig = new ThermostatConfig()
                    {
                        Id       = 1,
                        Setpoint = thermostatDefaults
                                   .GetValue <decimal>("Temperature"),

                        Hysteresis = thermostatDefaults
                                     .GetValue <decimal>("Hysteresis"),

                        Calibration = thermostatDefaults
                                      .GetValue <decimal>("Calibration"),

                        Mode = thermostatDefaults
                               .GetValue <ThermostatModes>("Mode")
                    };

                    db.ThermostatConfig.Add(_thermostatConfig);
                    db.SaveChanges();
                }
            }
        }
Exemplo n.º 3
0
 public ThermostatService(ThermostatConfig thermostatConfig,
                          ITemperatureService temperatureService,
                          IRelayService relayService,
                          MomitKillerDbContext db)
 {
     _thermostatConfig   = thermostatConfig;
     _temperatureService = temperatureService;
     _relayService       = relayService;
     _db = db;
 }