public Frame WithTargetState(IBinaryStateOutputActuator actuator, BinaryActuatorState state)
        {
            if (actuator == null) throw new ArgumentNullException(nameof(actuator));

            _states.Add(new PendingBinaryStateOutputActuatorState().WithActuator(actuator).WithState(state));
            return this;
        }
        public StateMachineState WithActuator(IBinaryStateOutputActuator actuator, BinaryActuatorState state)
        {
            if (actuator == null) throw new ArgumentNullException(nameof(actuator));

            _actuators.Add(new Tuple<IBinaryStateOutputActuator, BinaryActuatorState>(actuator, state));
            return this;
        }
        public AutomaticTurnOnAndOffAutomation WithTarget(IBinaryStateOutputActuator actuator)
        {
            if (actuator == null) throw new ArgumentNullException(nameof(actuator));

            _actuators.Add(actuator);
            return this;
        }
        public PendingBinaryStateOutputActuatorState WithActuator(IBinaryStateOutputActuator actuator)
        {
            if (actuator == null) throw new ArgumentNullException(nameof(actuator));

            Actuator = actuator;
            return this;
        }
        public LogicalBinaryStateOutputActuator WithActuator(IBinaryStateOutputActuator actuator)
        {
            if (actuator == null) throw new ArgumentNullException(nameof(actuator));

            Actuators.Add(actuator);
            return this;
        }
Exemple #6
0
        public static void TurnOn(this IBinaryStateOutputActuator actuator, params IParameter[] parameters)
        {
            if (parameters == null)
            {
                throw new ArgumentNullException(nameof(parameters));
            }

            actuator.SetState(BinaryActuatorState.On, parameters);
        }
        public static IButton ConnectToggleActionWith(this IButton button, IBinaryStateOutputActuator actuator, ButtonPressedDuration pressedDuration = ButtonPressedDuration.Short)
        {
            if (actuator == null) throw new ArgumentNullException(nameof(actuator));
            if (button == null) throw new ArgumentNullException(nameof(button));

            ConnectToggleAction(button, actuator, pressedDuration);

            return button;
        }
Exemple #8
0
        private void HandleBinaryStateOutputActuator(IBinaryStateOutputActuator binaryStateOutputActuator)
        {
            OnBinaryStateActuatorStateChanged(binaryStateOutputActuator, binaryStateOutputActuator.GetState());

            binaryStateOutputActuator.StateChanged += (s, e) =>
            {
                OnBinaryStateActuatorStateChanged(binaryStateOutputActuator, e.NewValue);
            };
        }
Exemple #9
0
        public PendingBinaryStateOutputActuatorState WithActuator(IBinaryStateOutputActuator actuator)
        {
            if (actuator == null)
            {
                throw new ArgumentNullException(nameof(actuator));
            }

            Actuator = actuator;
            return(this);
        }
Exemple #10
0
        public StateMachineState WithActuator(IBinaryStateOutputActuator actuator, BinaryActuatorState state)
        {
            if (actuator == null)
            {
                throw new ArgumentNullException(nameof(actuator));
            }

            _actuators.Add(new Tuple <IBinaryStateOutputActuator, BinaryActuatorState>(actuator, state));
            return(this);
        }
Exemple #11
0
        public LogicalBinaryStateOutputActuator WithActuator(IBinaryStateOutputActuator actuator)
        {
            if (actuator == null)
            {
                throw new ArgumentNullException(nameof(actuator));
            }

            Actuators.Add(actuator);
            return(this);
        }
        public Frame WithTargetState(IBinaryStateOutputActuator actuator, BinaryActuatorState state)
        {
            if (actuator == null)
            {
                throw new ArgumentNullException(nameof(actuator));
            }

            _states.Add(new PendingBinaryStateOutputActuatorState().WithActuator(actuator).WithState(state));
            return(this);
        }
        public TurnOnAndOffAutomation WithTarget(IBinaryStateOutputActuator actuator)
        {
            if (actuator == null)
            {
                throw new ArgumentNullException(nameof(actuator));
            }

            _turnOnActions.Add(() => actuator.TurnOn());
            _turnOffActions.Add(() => actuator.TurnOff());

            return(this);
        }
        protected override void OnBinaryStateActuatorStateChanged(IBinaryStateOutputActuator actuator, BinaryActuatorState newState)
        {
            ////JsonObject startData = CreateDataPackage(actuator.Id, EventType.OutputActuatorStateChanged);
            ////startData.SetNamedValue("state", JsonValue.CreateStringValue(actuator.GetState().ToString()));
            ////startData.SetNamedValue("kind", JsonValue.CreateStringValue("Start"));
            ////Task.Run(() => SendToAzureEventHubAsync(startData));

            ////BinaryActuatorState previousState = actuator.GetState() == BinaryActuatorState.On ? BinaryActuatorState.Off : BinaryActuatorState.On;
            ////JsonObject endData = CreateDataPackage(actuator.Id, EventType.OutputActuatorStateChanged);
            ////endData.SetNamedValue("state", JsonValue.CreateStringValue(previousState.ToString()));
            ////endData.SetNamedValue("kind", JsonValue.CreateStringValue("End"));
            ////endData.SetNamedValue("duration", JsonValue.CreateNumberValue(previousStateDuration.TotalSeconds));
            ////Task.Run(() => SendToAzureEventHubAsync(endData));
        }
        protected override void OnBinaryStateActuatorStateChanged(IBinaryStateOutputActuator actuator, TimeSpan previousStateDuration)
        {
            JsonObject startData = CreateDataPackage(actuator.Id, EventType.OutputActuatorStateChanged);
            startData.SetNamedValue("state", JsonValue.CreateStringValue(actuator.GetState().ToString()));
            startData.SetNamedValue("kind", JsonValue.CreateStringValue("Start"));
            Task.Run(() => SendToAzureEventHubAsync(startData));

            BinaryActuatorState previousState = actuator.GetState() == BinaryActuatorState.On ? BinaryActuatorState.Off : BinaryActuatorState.On;
            JsonObject endData = CreateDataPackage(actuator.Id, EventType.OutputActuatorStateChanged);
            endData.SetNamedValue("state", JsonValue.CreateStringValue(previousState.ToString()));
            endData.SetNamedValue("kind", JsonValue.CreateStringValue("End"));
            endData.SetNamedValue("duration", JsonValue.CreateNumberValue(previousStateDuration.TotalSeconds));
            Task.Run(() => SendToAzureEventHubAsync(endData));
        }
 private static void ConnectToggleAction(IButton button, IBinaryStateOutputActuator actuator, ButtonPressedDuration pressedDuration)
 {
     if (pressedDuration == ButtonPressedDuration.Short)
     {
         button.PressedShort += (s, e) => actuator.Toggle();
     }
     else if (pressedDuration == ButtonPressedDuration.Long)
     {
         button.PressedLong += (s, e) => actuator.Toggle();
     }
     else
     {
         throw new NotSupportedException();
     }
 }
Exemple #17
0
 private static void ConnectToggleAction(IButton button, IBinaryStateOutputActuator actuator, ButtonPressedDuration pressedDuration)
 {
     if (pressedDuration == ButtonPressedDuration.Short)
     {
         button.GetPressedShortlyTrigger().Attach(() => actuator.Toggle());
     }
     else if (pressedDuration == ButtonPressedDuration.Long)
     {
         button.GetPressedLongTrigger().Attach(() => actuator.Toggle());
     }
     else
     {
         throw new NotSupportedException();
     }
 }
Exemple #18
0
        public static IBinaryStateOutputActuator ConnectToggleActionWith(this IBinaryStateOutputActuator actuator, IButton button, ButtonPressedDuration pressedDuration = ButtonPressedDuration.Short)
        {
            if (actuator == null)
            {
                throw new ArgumentNullException(nameof(actuator));
            }
            if (button == null)
            {
                throw new ArgumentNullException(nameof(button));
            }

            ConnectToggleAction(button, actuator, pressedDuration);

            return(actuator);
        }
Exemple #19
0
        public static void Toggle(this IBinaryStateOutputActuator actuator, params IParameter[] parameters)
        {
            if (parameters == null)
            {
                throw new ArgumentNullException(nameof(parameters));
            }

            if (actuator.GetState() == BinaryActuatorState.Off)
            {
                actuator.TurnOn();
            }
            else
            {
                actuator.TurnOff();
            }
        }
 private void WriteToLocalCsvFile(IBinaryStateOutputActuator actuator)
 {
     lock (_filename)
     {
         try
         {
             // Template: {ISO_TIMESTAMP},{ACTUATOR_ID},{NEW_STATE}
             string newLine = DateTime.Now.ToString("O") + "," + actuator.Id + "," + actuator.GetState();
             File.AppendAllText(_filename, newLine + Environment.NewLine);
         }
         catch (Exception exception)
         {
             NotificationHandler.PublishFrom(this, NotificationType.Warning, "Error while write actuator state changes to CSV log. {0}",
                 exception.Message);
         }
     }
 }
        private void HandleBinaryStateOutputActuator(IBinaryStateOutputActuator binaryStateOutputActuator)
        {
            Stopwatch stopwatch = Stopwatch.StartNew();
            binaryStateOutputActuator.StateChanged += (s, e) =>
            {
                TimeSpan previousStateDuration = stopwatch.Elapsed;
                stopwatch.Restart();

                OnBinaryStateActuatorStateChanged(binaryStateOutputActuator, previousStateDuration);
            };
        }
 protected override void OnBinaryStateActuatorStateChanged(IBinaryStateOutputActuator actuator, BinaryActuatorState newState)
 {
     QueueEntry(actuator, newState.ToString());
 }
Exemple #23
0
 public ConditionalOnAutomation WithActuator(IBinaryStateOutputActuator actuator)
 {
     _actuators.Add(actuator);
     return(this);
 }
 protected override void OnBinaryStateActuatorStateChanged(IBinaryStateOutputActuator actuator, TimeSpan previousStateDuration)
 {
     Task.Run(() => WriteToLocalCsvFile(actuator));
 }
        public Automation WithBinaryStateOutputActuatorStateChangedTrigger(IBinaryStateOutputActuator actuator, BinaryActuatorState desiredState)
        {
            if (actuator == null) throw new ArgumentNullException(nameof(actuator));

            actuator.StateChanged += (s, e) =>
            {
                if (actuator.GetState() == desiredState)
                {
                    Trigger();
                }
            };

            return this;
        }
 protected virtual void OnBinaryStateActuatorStateChanged(IBinaryStateOutputActuator actuator, TimeSpan previousStateDuration)
 {
 }
Exemple #27
0
 protected virtual void OnBinaryStateActuatorStateChanged(IBinaryStateOutputActuator actuator, BinaryActuatorState newState)
 {
 }