예제 #1
0
        public override async Task Handle(CancellationToken token)
        {
            if (_evt.IsOnEvent)
            {
                await Task.Delay(HowLong, token);

                SwitchRelay relay = _hub.GetDeviceById <SwitchRelay>(_evt.DeviceId) as SwitchRelay;
                relay.Off();
            }
        }
예제 #2
0
        /// <summary>
        /// Handles door events coming from the home automation controller.
        /// </summary>
        /// <param name="token">A .NET cancellation token received if this handler is to be cancelled.</param>
        protected override async Task Handle()
        {
            if (_evt.IsOpenEvent)
            {
                // Turn on the light
                await _sampleLight.On();

                // Remember when we turned on the light for later (when we respond to an off event)
                _hub.StateBag.AddOrUpdate(_timeOpenedKey, DateTime.Now,
                                          (key, oldvalue) => DateTime.Now); // This is the lambda to just update an existing value with the current DateTime

                // Wait a bit...
                await WaitForCancellationAsync(_interval);

                await _sampleSpeaker.Speak("Please close the door.");

                // Wait a bit more...
                await WaitForCancellationAsync(_interval);

                await _sampleSpeaker.Speak("I said, please close the door.");

                // Wait a bit longer and then give up...
                await WaitForCancellationAsync(_interval);

                await _sampleSpeaker.Speak("Okay, I'll turn off the light myself.");

                await _sampleLight.Off();
            }
            else
            {
                // Has the door been open five minutes?
                DateTime PantryOpenTime =
                    _hub.StateBag.ContainsKey(_timeOpenedKey) ? (DateTime)_hub.StateBag[_timeOpenedKey] : DateTime.Now;
                if (DateTime.Now - PantryOpenTime > _interval)
                {
                    // It's been open five minutes, so we've nagged by now.
                    // It's only polite to thank them for doing what we've asked!
                    await _sampleSpeaker.Speak("Thank you for closing the pantry door");
                }
                await _sampleLight.Off();
            }
        }
예제 #3
0
 protected override async Task Handle()
 {
     if (_evt.IsOnEvent)
     {
         await _floodlights.On();
     }
     else
     {
         await _floodlights.Off();
     }
 }
예제 #4
0
        protected override async Task Handle()
        {
            if (_evt.IsOnEvent)
            {
                await WaitForCancellationAsync(HowLong);

                SwitchRelay relay = await _hub.GetDeviceById <SwitchRelay>(_evt.DeviceId);

                await relay.Off();
            }
        }
예제 #5
0
        /// <summary>
        /// Handles pantry door events coming from the home automation controller.
        /// </summary>
        /// <param name="token">A .NET cancellation token received if this handler is to be cancelled.</param>
        public override async Task Handle(CancellationToken token)
        {
            if (_evt.IsOpenEvent)
            {
                // Turn on the light
                _pantryLight.On();

                // Remember when we turned on the light for later (when we respond to an off event)
                _hub.StateBag.AddOrUpdate("PantryOpened", DateTime.Now,
                                          (key, oldvalue) => DateTime.Now); // This is the lambda to just update an existing value with the current DateTime

                // Wait a bit...
                await Task.Delay(_interval, token);

                _kitchenSpeaker.Speak("Please close the pantry door");

                // Wait a bit more...
                await Task.Delay(_interval, token);

                _kitchenSpeaker.Speak("I said, please close the pantry door");

                // Wait a bit longer and then give up...
                await Task.Delay(_interval, token);

                _kitchenSpeaker.Speak("Fine, I'll turn off the light myself.");
                _pantryLight.Off();
            }
            else if (_evt.IsClosedEvent)
            {
                // Has the door been open five minutes?
                DateTime PantryOpenTime =
                    _hub.StateBag.ContainsKey("PantryOpened") ? (DateTime)_hub.StateBag["PantryOpened"] : DateTime.Now;
                if (DateTime.Now - PantryOpenTime > _interval)
                {
                    // It's been open five minutes, so we've nagged by now.
                    // It's only polite to thank them for doing what we've asked!
                    _kitchenSpeaker.Speak("Thank you for closing the pantry door");
                }
                _pantryLight.Off();
            }
        }
예제 #6
0
        protected override async Task Handle()
        {
            if (_evt.IsOpenEvent)
            {
                await _barOutlet.On();
            }
            else
            {
                await WaitForCancellationAsync(TimeSpan.FromMinutes(1));

                await _barOutlet.Off();
            }
        }
예제 #7
0
        protected override async Task Handle()
        {
            if (_evt.IsOpenEvent && await IsDark(30, -30))
            {
                await _frontLights.On();
            }
            else
            {
                if (!_doors.IsAnyOpen() && _frontLights.Status == SwitchStatus.On)
                {
                    await WaitForCancellationAsync(TimeSpan.FromMinutes(10));

                    await _frontLights.Off();
                }
            }
        }
예제 #8
0
        private async Task TurnLightsOff()
        {
            await _basementFurnace.Off();

            await _basementWasher.Off();
        }