Пример #1
0
        public async Task SessionService_UpdateSession_Without_IsSauna_Or_IsInfrared_Should_Not_Do_Anything()
        {
            // Arrange
            var sessionContext = new Mock <ISessionContext>();
            var gpioService    = new Mock <IGpioService>();
            var loggerService  = new Mock <ILoggerService <SessionService> >();
            var sessionService = new SessionService(sessionContext.Object, gpioService.Object, loggerService.Object);

            var data = new GetActiveSessionResponse
            {
                IsSauna    = false,
                IsInfrared = false
            };

            // Mock
            gpioService.Setup(x => x.ReadTemperature()).ReturnsAsync(0);
            gpioService.Setup(x => x.IsSaunaOn()).ReturnsAsync(false);
            gpioService.Setup(x => x.IsInfraredOn()).ReturnsAsync(false);

            // Act
            await sessionService.UpdateSession(data);

            // Assert
            gpioService.Verify(x => x.TurnSaunaOn(), Times.Never);
            gpioService.Verify(x => x.TurnSaunaOff(), Times.Never);
            gpioService.Verify(x => x.TurnInfraredOn(), Times.Never);
            gpioService.Verify(x => x.TurnInfraredOff(), Times.Never);
        }
Пример #2
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();
            }
        }
Пример #3
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();
            }
        }