Example #1
0
        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));
        }
Example #2
0
        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));
        }
Example #3
0
        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));
        }
Example #4
0
        public async Task AddNewThermostats([FromServices] IThermostatSubsystemManager <ThermostatInput, Thermostat> thermostats)
        {
            var items = await thermostats.List();

            await repo.AddMissing(items);
        }
Example #5
0
        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);
        }
Example #6
0
        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));
        }