public void GetLastSignal_SetAndGet()
        {
            var lastSignal = new DateTime(2018, 1, 1, 15, 15, 30);
            var stateStore = new SoundSnifferStateStore();

            stateStore.SetLastSignal(lastSignal);

            Assert.Equal(lastSignal, stateStore.GetLastSignal());
        }
Ejemplo n.º 2
0
        private void _timer_Elapsed(object sender, ElapsedEventArgs e)
        {
            var  sockets        = _stateStore.GetSockets();
            bool isPlaying      = isAudioPlaying();
            var  lastSignal     = _stateStore.GetLastSignal();
            var  signalDuration = _stateStore.GetSignalDuration();

            foreach (var socket in sockets)
            {
                var settings = _stateStore.GetSettings(socket);
                var status   = _stateStore.GetStatus(socket);

                var  signalIdle    = DateTime.Now - lastSignal;
                bool turnSocketOn  = signalDuration > settings.MinimumSignalDuration && status != PowerStatus.On;
                bool turnSocketOff = signalIdle >= settings.OffDelay && status != PowerStatus.Off;

                if (turnSocketOn)
                {
                    _stateStore.SetStatus(socket, PowerStatus.On);
                    StatusChanged?.Invoke(this, new StatusChangedEventArgs("", "", socket, PowerStatus.On));
                }
                else if (turnSocketOff)
                {
                    _stateStore.SetStatus(socket, PowerStatus.Off);
                    StatusChanged?.Invoke(this, new StatusChangedEventArgs("", "", socket, PowerStatus.Off));
                }

                fireStatusForecastEvent(socket, signalIdle, settings.OffDelay);
            }

            if (isPlaying)
            {
                _stateStore.SetSignalDuration(signalDuration + TimeSpan.FromSeconds(((Timer)sender).Interval / 1000));
                _stateStore.SetLastSignal(DateTime.Now);
            }
            else
            {
                _stateStore.SetSignalDuration(TimeSpan.FromSeconds(0));
            }
        }
        public void GetLastSignal_DefaultValue()
        {
            var stateStore = new SoundSnifferStateStore();

            Assert.Equal(DateTime.MinValue, stateStore.GetLastSignal());
        }