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 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 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 void SetState(BinaryActuatorState state, params IParameter[] parameters) { if (parameters == null) { throw new ArgumentNullException(nameof(parameters)); } if (!Settings.IsEnabled.Value) { return; } SetStateInternal(state, parameters); }
protected override void SetStateInternal(BinaryActuatorState newState, params IParameter[] parameters) { BinaryActuatorState oldState = GetState(); bool stateHasChanged = newState != oldState; bool commit = !parameters.Any(p => p is DoNotCommitStateParameter); _output.Write(newState == BinaryActuatorState.On ? BinaryState.High : BinaryState.Low, commit); bool forceUpdate = parameters.Any(p => p is ForceUpdateStateParameter); if (forceUpdate || stateHasChanged) { NotificationHandler.PublishFrom(this, NotificationType.Verbose, "'{0}' set to '{1}'.", Id, newState); OnStateChanged(oldState, newState); } }
protected override void SetStateInternal(BinaryActuatorState newState, params IParameter[] parameters) { BinaryActuatorState oldState = GetState(); bool stateHasChanged = newState != oldState; bool commit = !parameters.Any(p => p is DoNotCommitStateParameter); _output.Write(newState == BinaryActuatorState.On ? BinaryState.High : BinaryState.Low, commit); bool forceUpdate = parameters.Any(p => p is ForceUpdateStateParameter); if (forceUpdate || stateHasChanged) { Logger.Info(Id + ": " + oldState + "->" + newState); OnStateChanged(oldState, newState); } }
public void SetState(BinaryActuatorState state, params IParameter[] parameters) { if (state == State) { return; } State = state; var oldState = BinaryActuatorState.Off; if (state == BinaryActuatorState.Off) { oldState = BinaryActuatorState.On; } StateChanged?.Invoke(this, new BinaryActuatorStateChangedEventArgs(oldState, state)); }
protected override void SetStateInternal(BinaryActuatorState newState, params IParameter[] parameters) { if (parameters == null) { throw new ArgumentNullException(nameof(parameters)); } BinaryActuatorState oldState = GetStateInternal(); var animationParameter = parameters.SingleOrDefault(p => p is AnimateParameter) as AnimateParameter; if (animationParameter != null) { var directionAnimation = new DirectionAnimation(_timer); directionAnimation.WithActuator(this); directionAnimation.WithTargetState(newState); if (animationParameter.Reverse) { directionAnimation.WithReversed(); } directionAnimation.Start(); OnStateChanged(oldState, newState); return; } // Set the state of the actuators without a commit to ensure that the state is applied at once without a delay. foreach (var actuator in Actuators) { actuator.SetState(newState, new DoNotCommitStateParameter()); } bool commit = !parameters.Any(p => p is DoNotCommitStateParameter); if (commit) { foreach (var actuator in Actuators) { actuator.SetState(newState); } } OnStateChanged(newState, GetStateInternal()); }
public void SetState(BinaryActuatorState state, params IParameter[] parameters) { if (state == State) { return; } State = state; var oldState = BinaryActuatorState.Off; if (state == BinaryActuatorState.Off) { oldState = BinaryActuatorState.On; } StateChanged?.Invoke(this, new BinaryActuatorStateChangedEventArgs(oldState, state)); }
protected override void SetStateInternal(BinaryActuatorState newState, params IParameter[] parameters) { if (parameters == null) throw new ArgumentNullException(nameof(parameters)); BinaryActuatorState oldState = GetStateInternal(); var animationParameter = parameters.SingleOrDefault(p => p is AnimateParameter) as AnimateParameter; if (animationParameter != null) { var directionAnimation = new DirectionAnimation(_timer); directionAnimation.WithActuator(this); directionAnimation.WithTargetState(newState); if (animationParameter.Reverse) { directionAnimation.WithReversed(); } directionAnimation.Start(); OnStateChanged(oldState, newState); return; } // Set the state of the actuators without a commit to ensure that the state is applied at once without a delay. foreach (var actuator in Actuators) { actuator.SetState(newState, new DoNotCommitStateParameter()); } bool commit = !parameters.Any(p => p is DoNotCommitStateParameter); if (commit) { foreach (var actuator in Actuators) { actuator.SetState(newState); } } OnStateChanged(newState, GetStateInternal()); }
public override void HandleApiPost(ApiRequestContext context) { base.HandleApiPost(context); if (!context.Request.ContainsKey("state")) { return; } string action = context.Request.GetNamedString("state", "toggle"); bool commit = context.Request.GetNamedBoolean("commit", true); if (action.Equals("toggle", StringComparison.OrdinalIgnoreCase)) { if (commit) { this.Toggle(); } else { this.Toggle(new DoNotCommitStateParameter()); } context.Response = ExportStatusToJsonObject(); return; } BinaryActuatorState state = (BinaryActuatorState)Enum.Parse(typeof(BinaryActuatorState), action, true); if (commit) { SetState(state); } else { SetState(state, new DoNotCommitStateParameter()); } }
public DirectionAnimation WithTargetOffState() { _targetState = BinaryActuatorState.Off; return(this); }
protected void OnStateChanged(BinaryActuatorState oldState, BinaryActuatorState newState) { StateChanged?.Invoke(this, new BinaryActuatorStateChangedEventArgs(oldState, newState)); }
protected abstract void SetStateInternal(BinaryActuatorState state, params IParameter[] parameters);
public DirectionAnimation WithTargetState(BinaryActuatorState state) { _targetState = state; return this; }
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; }
public DirectionAnimation WithTargetOffState() { _targetState = BinaryActuatorState.Off; return this; }
public TestBinaryStateOutputActuator WithOffState() { State = BinaryActuatorState.Off; return this; }
protected virtual void OnBinaryStateActuatorStateChanged(IBinaryStateOutputActuator actuator, BinaryActuatorState newState) { }
public PendingBinaryStateOutputActuatorState WithState(BinaryActuatorState state) { State = state; 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)); }
public PendingBinaryStateOutputActuatorState WithState(BinaryActuatorState state) { State = state; return(this); }
protected override void OnBinaryStateActuatorStateChanged(IBinaryStateOutputActuator actuator, BinaryActuatorState newState) { QueueEntry(actuator, newState.ToString()); }
public DirectionAnimation WithTargetState(BinaryActuatorState state) { _targetState = state; return(this); }