public async Task <Thermostat> ApplySetting(Guid thermostatSettingId, [FromServices] IThermostatSettingRepository settingRepository, [FromServices] IThermostatSubsystemManager <ThermostatInput, Thermostat> thermostats) { var setting = await settingRepository.Get(thermostatSettingId); var cached = await repo.Get(setting.ThermostatId); var thermostat = new ThermostatInput(); thermostat.Bridge = cached.Bridge; thermostat.Subsystem = cached.Subsystem; thermostat.Id = cached.Id; if (setting.On) { thermostat.HeatTemp = setting.HeatTemp; thermostat.CoolTemp = setting.CoolTemp; thermostat.Fan = FanSetting.Auto; thermostat.Mode = Mode.Auto; } else { thermostat.HeatTemp = 70; thermostat.CoolTemp = 75; thermostat.Fan = FanSetting.Auto; thermostat.Mode = Mode.Off; } await thermostats.Set(thermostat); var live = await thermostats.Get(cached.Subsystem, cached.Bridge, cached.Id); return(await repo.Update(setting.ThermostatId, live)); }
public async Task <Thermostat> Add(ThermostatInput thermostat) { var entity = mapper.Map <ThermostatEntity>(thermostat); this.dbContext.Add(entity); await SaveChanges(); return(mapper.Map <Thermostat>(entity)); }
public async Task <Thermostat> Update(Guid thermostatId, [FromBody] ThermostatInput thermostat, [FromServices] IThermostatSubsystemManager <ThermostatInput, Thermostat> thermostats) { var cached = await repo.Get(thermostatId); thermostat.Bridge = cached.Bridge; thermostat.Subsystem = cached.Subsystem; thermostat.Id = cached.Id; await thermostats.Set(thermostat); var live = await thermostats.Get(cached.Subsystem, cached.Bridge, cached.Id); return(await repo.Update(thermostatId, live)); }
public async Task <Thermostat> Update(Guid thermostatId, ThermostatInput thermostat) { var entity = await this.Entity(thermostatId); if (entity != null) { mapper.Map(thermostat, entity); await SaveChanges(); return(mapper.Map <Thermostat>(entity)); } throw new KeyNotFoundException($"Cannot find thermostat {thermostatId.ToString()}"); }
public async Task Set(TIn setting) { var input = new ThermostatInput() { Bridge = setting.Bridge, CoolTemp = setting.CoolTemp, Fan = (FanSetting)setting.Fan, HeatTemp = setting.HeatTemp, Id = setting.Id, Mode = (Mode)setting.Mode, Subsystem = setting.Subsystem, }; var thermostat = await clientManager.GetClient(setting.Bridge).GetThermostat(setting.Id); await thermostat.Update(input); }
public async Task <Thermostat> SetTemp(Guid thermostatId, [FromBody] ThermostatTempInput tempInput, [FromServices] IThermostatSubsystemManager <ThermostatInput, Thermostat> thermostats) { var cached = await repo.Get(thermostatId); var thermostat = new ThermostatInput(); thermostat.Bridge = cached.Bridge; thermostat.Subsystem = cached.Subsystem; thermostat.Id = cached.Id; thermostat.HeatTemp = tempInput.HeatTemp; thermostat.CoolTemp = tempInput.CoolTemp; thermostat.Fan = FanSetting.Auto; thermostat.Mode = Mode.Auto; await thermostats.Set(thermostat); var live = await thermostats.Get(cached.Subsystem, cached.Bridge, cached.Id); return(await repo.Update(thermostatId, live)); }