private void ScheduleLightsSwitch()
            {
                if (IsSwitchOffTime())
                {
                    _logger.LogInformation("Switching lights off.");
                    JobManager.AddJob(
                        () => _lightSwitchService.SetLightsState(new LightsStateViewModel {
                        State = LightSwitchState.Off
                    }),
                        s => s.ToRunNow());
                }
                else
                {
                    var switchOnTime    = GetSunsetTime().Subtract(_options.TimeToSwitchBeforeSunset);
                    var switchOnTimeUtc = switchOnTime.ConvertToUtc(_timeProvider.TimeZone);

                    _logger.LogInformation($"Scheduling evening lights on switch at {switchOnTime} ({switchOnTimeUtc} UTC), " +
                                           $"{_options.TimeToSwitchBeforeSunset} before sunset.");

                    JobManager.AddJob(
                        () => _lightSwitchService.SetLightsState(new LightsStateViewModel {
                        State = LightSwitchState.On
                    }),
                        s => s.ToRunOnceAt(switchOnTimeUtc));
                }
            }
Beispiel #2
0
 public async Task SetAllLightsState(LightsStateViewModel lightsState)
 {
     await _lightSwitchService.SetLightsState(lightsState);
 }