Esempio n. 1
0
        /// <summary>
        /// Cycles living room lights between two scenes while a v-switch is turned on
        /// </summary>
        /// <param name="evt"></param>
        /// <param name="token"></param>
        protected override async Task Handle()
        {
            TimeSpan timeBetweenCycles = TimeSpan.FromMinutes(5);

            if (_evt.IsOnEvent)
            {
                SwitchRelay LivingRoomXmas1 =
                    await _hub.GetDeviceByMappedName <SwitchRelay>("Switch.LivingRoomXmasScene1");

                SwitchRelay LivingRoomXmas2 =
                    await _hub.GetDeviceByMappedName <SwitchRelay>("Switch.LivingRoomXmasScene2");

                while (true)
                {
                    await LivingRoomXmas1.On();
                    await WaitForCancellationAsync(timeBetweenCycles);

                    await LivingRoomXmas2.On();
                    await WaitForCancellationAsync(timeBetweenCycles);
                }
            }
            else
            {
                SwitchRelay DefaultLivingRoomScene =
                    await _hub.GetDeviceByMappedName <SwitchRelay>("Switch.LivingRoomNormalScene");

                await DefaultLivingRoomScene.On();

                return;
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Cycles living room lights between two scenes while a vswitch is turned on
        /// </summary>
        /// <param name="evt"></param>
        /// <param name="token"></param>
        public override async Task Handle(CancellationToken token)
        {
            TimeSpan timeBetweenCycles = TimeSpan.FromMinutes(5);

            if (_evt.IsOnEvent)
            {
                SwitchRelay LivingRoomXmas1 =
                    _hub.GetDeviceByMappedName <SwitchRelay>("Switch.LivingRoomXmasScene1") as SwitchRelay;
                SwitchRelay LivingRoomXmas2 =
                    _hub.GetDeviceByMappedName <SwitchRelay>("Switch.LivingRoomXmasScene2") as SwitchRelay;

                while (true)
                {
                    LivingRoomXmas1.On();
                    await Task.Delay(timeBetweenCycles, token);

                    LivingRoomXmas2.On();
                    await Task.Delay(timeBetweenCycles, token);
                }
            }
            else
            {
                SwitchRelay DefaultLivingRoomScene =
                    _hub.GetDeviceByMappedName <SwitchRelay>("Switch.LivingRoomNormalScene") as SwitchRelay;
                DefaultLivingRoomScene.On();
                return;
            }
        }
Esempio n. 3
0
 protected override async Task Handle()
 {
     if (_evt.IsOnEvent)
     {
         await _floodlights.On();
     }
     else
     {
         await _floodlights.Off();
     }
 }
Esempio n. 4
0
        protected override async Task Handle()
        {
            if (_evt.IsOpenEvent)
            {
                await _barOutlet.On();
            }
            else
            {
                await WaitForCancellationAsync(TimeSpan.FromMinutes(1));

                await _barOutlet.Off();
            }
        }
Esempio n. 5
0
        protected override async Task Handle()
        {
            if (_evt.IsActiveEvent && !LightsOn)
            {
                await _basementFurnace.On();

                await _basementWasher.On();
                await WaitForCancellationAsync(TimeSpan.FromMinutes(10));
                await TurnLightsOff();
            }
            else if (_evt.IsActiveEvent && LightsOn)
            {
                await TurnLightsOff();
            }
        }
Esempio n. 6
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();
                }
            }
        }
Esempio n. 7
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();
            }
        }
Esempio n. 8
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();
            }
        }