Пример #1
0
        private void SetupHumidityDependingLamp(IHumiditySensor sensor, ILamp lamp)
        {
            ITrigger trigger = sensor.GetHumidityReachedTrigger(80);
            IAction  action  = lamp.GetTurnOnAction();

            trigger.Attach(action);

            var twitterClient = new TwitterClient();

            trigger.Attach(twitterClient.GetTweetAction("Hello World"));
        }
        public ConditionalTrigger WithTrigger(ITrigger trigger)
        {
            if (trigger == null) throw new ArgumentNullException(nameof(trigger));

            trigger.Attach(ForwardTriggerEvent);
            return this;
        }
        public static IAction OnTrigger(this IAction action, ITrigger trigger)
        {
            if (action == null) throw new ArgumentNullException(nameof(action));
            if (trigger == null) throw new ArgumentNullException(nameof(trigger));

            trigger.Attach(action);
            return action;
        }
Пример #4
0
        public TurnOnAndOffAutomation WithTrigger(ITrigger trigger)
        {
            if (trigger == null)
            {
                throw new ArgumentNullException(nameof(trigger));
            }

            trigger.Attach(ExecuteManualTrigger);
            return(this);
        }
Пример #5
0
        public Automation WithTrigger(ITrigger trigger)
        {
            if (trigger == null)
            {
                throw new ArgumentNullException(nameof(trigger));
            }

            trigger.Attach(Trigger);
            return(this);
        }
Пример #6
0
        public ConditionalTrigger WithTrigger(ITrigger trigger)
        {
            if (trigger == null)
            {
                throw new ArgumentNullException(nameof(trigger));
            }

            trigger.Attach(ForwardTriggerEvent);
            return(this);
        }
        public static IAction OnTrigger(this IAction action, ITrigger trigger)
        {
            if (action == null)
            {
                throw new ArgumentNullException(nameof(action));
            }
            if (trigger == null)
            {
                throw new ArgumentNullException(nameof(trigger));
            }

            trigger.Attach(action);
            return(action);
        }
        public static ITrigger Attach(this ITrigger trigger, IAction actuatorAction)
        {
            if (trigger == null)
            {
                throw new ArgumentNullException(nameof(trigger));
            }
            if (actuatorAction == null)
            {
                throw new ArgumentNullException(nameof(actuatorAction));
            }

            trigger.Attach(actuatorAction.Execute);
            return(trigger);
        }
Пример #9
0
        private void SetupDemo()
        {
            // Get the area from the controller.
            IArea area = this.GetArea(Room.ExampleRoom);

            // Get the single motion detector from the controller.
            IMotionDetector motionDetector        = GetComponent <IMotionDetector>();
            ITrigger        motionDetectedTrigger = motionDetector.GetMotionDetectedTrigger();

            // Get the single temperature and humidity sensor from the controller.
            ITemperatureSensor temperatureSensor = GetComponent <ITemperatureSensor>();
            IHumiditySensor    humiditySensor    = GetComponent <IHumiditySensor>();

            // Get the button with the specified ID from the area (not globally).
            IButton  button        = area.GetButton(ExampleRoom.Button1);
            ITrigger buttonTrigger = button.GetPressedShortlyTrigger();

            // Get a test lamp from the area (not globally).
            ILamp lamp2 = area.GetLamp(ExampleRoom.Lamp2);
            ILamp lamp3 = area.GetLamp(ExampleRoom.Lamp3);

            // Integrate the twitter client if the configuration file is available.
            TwitterClient twitterClient;

            if (TwitterClientFactory.TryCreateFromDefaultConfigurationFile(out twitterClient))
            {
                RegisterService(new TwitterClient());

                IAction tweetAction = twitterClient.GetTweetAction($"Someone is here ({DateTime.Now})... @chkratky");

                motionDetectedTrigger.Attach(tweetAction);
                buttonTrigger.Attach(tweetAction);
            }

            // An automation is "Fulfilled" per default.
            ////var automation = new Automation(new AutomationId("DemoAutomation"))
            ////    .WithTrigger(motionDetectedTrigger)
            ////    .WithActionIfConditionsFulfilled(lamp3.GetTurnOnAction())
            ////    .WithCondition(ConditionRelation.And, new ComponentIsInStateCondition(lamp2, BinaryStateId.Off))
            ////    .WithCondition(ConditionRelation.And, new NumericValueSensorHasValueGreaterThanCondition(humiditySensor, 80));

            //AddAutomation(automation);

            SetupTelegramBot();

            new PersonalAgentToApiDispatcher(this).ExposeToApi(ApiController);
        }
        public TurnOnAndOffAutomation WithTrigger(ITrigger trigger)
        {
            if (trigger == null) throw new ArgumentNullException(nameof(trigger));

            trigger.Attach(ExecuteManualTrigger);
            return this;
        }
Пример #11
0
        public Automation WithTrigger(ITrigger trigger)
        {
            if (trigger == null) throw new ArgumentNullException(nameof(trigger));

            trigger.Attach(Trigger);
            return this;
        }