Ejemplo n.º 1
0
        public async Task UpdateSession(GetActiveSessionResponse activeSession)
        {
            SetSessionId(activeSession.SessionId);

            // Read the current temperature inside the sauna booth.
            var temperature = await _gpioService.ReadTemperature();

            // If a sauna session should be active and the sauna GPIO is not turned on...
            if (activeSession.IsSauna && !await _gpioService.IsSaunaOn())
            {
                _logger.LogInformation("Active session requires sauna but sauna is off!");
                _logger.LogInformation($"Temperature goal is {activeSession.TemperatureGoal} and actual temperature is {temperature}.");

                // If the current temperature is below the temperature goal...
                if (temperature < activeSession.TemperatureGoal)
                {
                    _logger.LogInformation("Sauna should be turned on!");
                    await _gpioService.TurnSaunaOn();
                }
            }

            // If a sauna session should be active and the sauna GPIO is turned on...
            if (activeSession.IsSauna && await _gpioService.IsSaunaOn())
            {
                _logger.LogInformation("Active session requires sauna and sauna is on!");
                _logger.LogInformation($"Temperature goal is {activeSession.TemperatureGoal} and actual temperature is {temperature}.");

                // If the current temperature is equal or higher then the temperature goal...
                if (temperature >= activeSession.TemperatureGoal)
                {
                    _logger.LogInformation("Sauna should be turned off!");
                    await _gpioService.TurnSaunaOff();
                }
            }

            // If a sauna session should not be active and the sauna GPIO is turned on...
            if (!activeSession.IsSauna && await _gpioService.IsSaunaOn())
            {
                _logger.LogInformation("Active session requires no sauna and sauna is on!");
                _logger.LogInformation("Sauna should be turned off!");
                await _gpioService.TurnSaunaOff();
            }

            // If an infrared session should be active and the infrared GPIO is not turned on...
            if (activeSession.IsInfrared && !await _gpioService.IsInfraredOn())
            {
                _logger.LogInformation("Active session requires infrared but infrared is off!");
                _logger.LogInformation($"Temperature goal is {activeSession.TemperatureGoal} and actual temperature is {temperature}.");

                // If the current temperature is lower then the temperature goal...
                if (temperature < activeSession.TemperatureGoal)
                {
                    _logger.LogInformation("Infrared should be turned on!");
                    await _gpioService.TurnInfraredOn();
                }
            }

            // If an infrared session should be active and the sauna GPIO is turned on...
            if (activeSession.IsInfrared && await _gpioService.IsInfraredOn())
            {
                _logger.LogInformation("Active session requires infrared and infrared is on!");
                _logger.LogInformation($"Temperature goal is {activeSession.TemperatureGoal} and actual temperature is {temperature}.");

                // If the current temperature is equal or higher then the temperature goal...
                if (temperature >= activeSession.TemperatureGoal)
                {
                    _logger.LogInformation("Infrared should be turned off!");
                    await _gpioService.TurnInfraredOff();
                }
            }

            // If an infrared session should not be active and the sauna GPIO is turned on...
            if (!activeSession.IsInfrared && await _gpioService.IsInfraredOn())
            {
                _logger.LogInformation("Active session requires no infrared and infrared is on!");
                _logger.LogInformation("Infrared should be turned off!");
                await _gpioService.TurnInfraredOff();
            }

            // If a sauna session should be active and the infrared boost is not turned on...
            if (activeSession.IsSauna && temperature < 50 && !await _gpioService.IsInfraredOn())
            {
                _logger.LogInformation("Active session requires sauna and can benefit from infrared boost!");
                await _gpioService.TurnInfraredOn();
            }

            // If a sauna session should be active and the infrared boost is turned on...
            if (activeSession.IsSauna && temperature >= 50 && await _gpioService.IsInfraredOn())
            {
                _logger.LogInformation("Active session requires sauna and should stop boosting from infrared!");
                await _gpioService.TurnInfraredOff();
            }
        }
Ejemplo n.º 2
0
        public async Task UpdateSession(GetActiveSessionResponse activeSession)
        {
            SetSessionId(activeSession.SessionId);

            var temperature = await _gpioService.ReadTemperature();

            if (activeSession.IsSauna && !await _gpioService.IsSaunaOn())
            {
                _logger.LogInformation("Active session requires sauna but sauna is off!");
                _logger.LogInformation($"Temperature goal is {activeSession.TemperatureGoal} and actual temperature is {temperature}.");

                if (temperature < activeSession.TemperatureGoal)
                {
                    _logger.LogInformation("Sauna should be turned on!");
                    await _gpioService.TurnSaunaOn();
                }
            }

            if (activeSession.IsSauna && await _gpioService.IsSaunaOn())
            {
                _logger.LogInformation("Active session requires sauna and sauna is on!");
                _logger.LogInformation($"Temperature goal is {activeSession.TemperatureGoal} and actual temperature is {temperature}.");

                if (temperature >= activeSession.TemperatureGoal)
                {
                    _logger.LogInformation("Sauna should be turned off!");
                    await _gpioService.TurnSaunaOff();
                }
            }

            if (!activeSession.IsSauna && await _gpioService.IsSaunaOn())
            {
                _logger.LogInformation("Active session requires no sauna and sauna is on!");
                _logger.LogInformation("Sauna should be turned off!");
                await _gpioService.TurnSaunaOff();
            }

            if (activeSession.IsInfrared && !await _gpioService.IsInfraredOn())
            {
                _logger.LogInformation("Active session requires infrared but infrared is off!");
                _logger.LogInformation($"Temperature goal is {activeSession.TemperatureGoal} and actual temperature is {temperature}.");

                if (temperature < activeSession.TemperatureGoal)
                {
                    _logger.LogInformation("Infrared should be turned on!");
                    await _gpioService.TurnInfraredOn();
                }
            }

            if (activeSession.IsInfrared && await _gpioService.IsInfraredOn())
            {
                _logger.LogInformation("Active session requires infrared and infrared is on!");
                _logger.LogInformation($"Temperature goal is {activeSession.TemperatureGoal} and actual temperature is {temperature}.");

                if (temperature >= activeSession.TemperatureGoal)
                {
                    _logger.LogInformation("Infrared should be turned off!");
                    await _gpioService.TurnInfraredOff();
                }
            }

            if (!activeSession.IsInfrared && await _gpioService.IsInfraredOn())
            {
                _logger.LogInformation("Active session requires no infrared and infrared is on!");
                _logger.LogInformation("Infrared should be turned off!");
                await _gpioService.TurnInfraredOff();
            }
        }