Example #1
0
        public async Task CheckAsync()
        {
            if (_thermostatConfig.Mode == ThermostatModes.Off)
            {
                return;
            }

            var currentTemperature = await _temperatureService.GetCurrentAsync();

            var setpoint   = _thermostatConfig.Setpoint;
            var hysteresis = _thermostatConfig.Hysteresis;

            if (currentTemperature - hysteresis >= setpoint)
            {
                await _relayService.PowerOffAsync();
            }
            else if (await _relayService.GetStatusAsync() == RelayStatuses.Off)
            {
                await _relayService.PowerOnAsync();
            }

            PrintResult(currentTemperature,
                        setpoint,
                        hysteresis);
        }
Example #2
0
        public async Task <IActionResult> PowerOnAsync()
        {
            try
            {
                await _relayService.PowerOnAsync();

                return(Ok());
            }
            catch (Exception ex)
            {
                await _mailService.SendEmailAsync("Error in RelayController PowerOnAsync", ex.ToString());

                return(StatusCode(500, ex.ToString()));
            }
        }