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> Get(Guid thermostatId, [FromServices] IThermostatSubsystemManager <ThermostatInput, Thermostat> thermostats) { var cached = await repo.Get(thermostatId); var live = await thermostats.Get(cached.Subsystem, cached.Bridge, cached.Id); return(await repo.Update(thermostatId, live)); }
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> 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)); }
public async Task <ThermostatCollection> List([FromQuery] ThermostatQuery query, [FromServices] IThermostatSubsystemManager <ThermostatInput, Thermostat> thermostats) { var result = await repo.List(query); if (query.UpdateStatus && query.ThermostatId != null) { //Allow status update for 1 item var cached = result.Items.FirstOrDefault(); if (cached != null) { var live = await thermostats.Get(cached.Subsystem, cached.Bridge, cached.Id); var item = await repo.Update(cached.ThermostatId, live); return(new ThermostatCollection(query, 1, new Thermostat[] { item })); } } return(result); }