public void State_NotEquals_State() { IComponentState state1 = new StatefulComponentState("Off"); IComponentState state2 = new StatefulComponentState("On"); state1.Equals(state2).ShouldBeEquivalentTo(false); }
public override void HandleApiCommand(IApiContext apiContext) { if (apiContext.Request.ContainsKey("action")) { string action = apiContext.Request.GetNamedString("action", "nextState"); if (action == "nextState") { SetState(GetNextState(GetState())); } return; } if (apiContext.Request.ContainsKey("state")) { var stateId = new StatefulComponentState(apiContext.Request.GetNamedString("state", string.Empty)); if (!GetSupportsState(stateId)) { apiContext.ResultCode = ApiResultCode.InvalidBody; apiContext.Response.SetNamedString("Message", "State ID not supported."); } SetState(stateId); } }
private void Update() { var oldState = _state; if (_fullOpenReedSwitch.Read() == BinaryState.Low) { _state = CasementStateId.Open; _openedTrigger.Execute(); return; } if (_tiltReedSwitch != null && _tiltReedSwitch.Read() == BinaryState.Low) { _state = CasementStateId.Tilt; _closedTrigger.Execute(); return; } else { _state = CasementStateId.Closed; _closedTrigger.Execute(); } OnStateChanged(oldState, _state); }
private void SetStates(StatefulComponentState state) { foreach (var rollerShutter in _rollerShutters) { _componentController.GetComponent <IRollerShutter>(rollerShutter).SetState(state); } }
public void State_NotEquals_DifferentState() { IComponentState state1 = new StatefulComponentState("Off"); IComponentState state2 = new NumericSensorValue(5); state1.Equals(state2).ShouldBeEquivalentTo(false); }
public void StatefulState_Serialize() { IComponentState state = new StatefulComponentState("Off"); IJsonValue jsonValue = state.ToJsonValue(); jsonValue.ValueType.ShouldBeEquivalentTo(JsonValueType.String); jsonValue.GetString().ShouldBeEquivalentTo("Off"); }
public TestStateMachine CreateTestStateMachineWithActiveState(StatefulComponentState id) { var stateMachine = new TestStateMachine(ComponentIdFactory.EmptyId); stateMachine.AddState(new StateMachineState(id)); stateMachine.SetState(id); return(stateMachine); }
public void SetInitialState(StatefulComponentState id) { if (id == null) { throw new ArgumentNullException(nameof(id)); } SetState(id, HardwareParameter.ForceUpdateState); }
public StateMachineState WithActuator(IActuator actuator, StatefulComponentState state) { if (actuator == null) { throw new ArgumentNullException(nameof(actuator)); } _pendingActuatorStates.Add(new PendingActuatorState().WithActuator(actuator).WithState(state)); return(this); }
public TestStateMachine CreateTestStateMachineWithOnOffStates(StatefulComponentState activeState) { var stateMachine = new TestStateMachine(ComponentIdFactory.EmptyId); stateMachine.AddState(new StateMachineState(BinaryStateId.Off)); stateMachine.AddState(new StateMachineState(BinaryStateId.On)); stateMachine.SetState(activeState); return(stateMachine); }
private void HandleInputStateChanged(StatefulComponentState state) { if (!this.GetIsEnabled()) { return; } SetState(state); InvokeTriggers(); }
public static StateMachineState AddState(this StateMachine stateMachine, StatefulComponentState id) { if (stateMachine == null) { throw new ArgumentNullException(nameof(stateMachine)); } if (id == null) { throw new ArgumentNullException(nameof(id)); } var state = new StateMachineState(id); stateMachine.AddState(state); return(state); }
private void UpdateState(StatefulComponentState newState) { if (!this.GetIsEnabled()) { return; } SetState(newState); if (newState == MotionDetectorStateId.MotionDetected) { OnMotionDetected(); } else { OnDetectionCompleted(); } }
public StateChangedEventArgs(StatefulComponentState oldState, StatefulComponentState newState) { OldState = oldState; NewState = newState; }
public static IAction GetSetStateAction(this IStateMachine stateStateMachine, StatefulComponentState stateId) { if (stateStateMachine == null) { throw new ArgumentNullException(nameof(stateStateMachine)); } if (stateId == null) { throw new ArgumentNullException(nameof(stateId)); } return(new Action(() => stateStateMachine.SetState(stateId))); }
public override void HandleApiCommand(IApiContext apiContext) { var state = new StatefulComponentState(apiContext.Request.GetNamedString("state")); SetState(state); }
private void SetupLight(StateMachine light, HSREL8 hsrel8, HSPE8OutputOnly hspe8, IArea room) { // Front lights (left, middle, right) var fl = hspe8[HSPE8Pin.GPIO0].WithInvertedState(); var fm = hspe8[HSPE8Pin.GPIO2].WithInvertedState(); var fr = hsrel8[HSREL8Pin.GPIO0].WithInvertedState(); // Middle lights (left, middle, right) var ml = hspe8[HSPE8Pin.GPIO1].WithInvertedState(); var mm = hspe8[HSPE8Pin.GPIO3].WithInvertedState(); var mr = hsrel8[HSREL8Pin.GPIO1].WithInvertedState(); // Rear lights (left, right) var rl = hsrel8[HSREL8Pin.GPIO5].WithInvertedState(); var rr = hsrel8[HSREL8Pin.GPIO4].WithInvertedState(); light.AddOffState() .WithLowOutput(fl) .WithLowOutput(fm) .WithLowOutput(fr) .WithLowOutput(ml) .WithLowOutput(mm) .WithLowOutput(mr) .WithLowOutput(rl) .WithLowOutput(rr); light.AddOnState() .WithHighOutput(fl) .WithHighOutput(fm) .WithHighOutput(fr) .WithHighOutput(ml) .WithHighOutput(mm) .WithHighOutput(mr) .WithHighOutput(rl) .WithHighOutput(rr); var deskOnlyStateId = new StatefulComponentState("DeskOnly"); light.AddState(deskOnlyStateId) .WithHighOutput(fl) .WithHighOutput(fm) .WithLowOutput(fr) .WithHighOutput(ml) .WithLowOutput(mm) .WithLowOutput(mr) .WithLowOutput(rl) .WithLowOutput(rr); var couchOnlyStateId = new StatefulComponentState("CouchOnly"); light.AddState(couchOnlyStateId) .WithLowOutput(fl) .WithLowOutput(fm) .WithLowOutput(fr) .WithLowOutput(ml) .WithLowOutput(mm) .WithLowOutput(mr) .WithLowOutput(rl) .WithHighOutput(rr); light.WithTurnOffIfStateIsAppliedTwice(); room.GetButton(Office.ButtonLowerRight) .GetPressedShortlyTrigger() .Attach(light.GetSetStateAction(couchOnlyStateId)); room.GetButton(Office.ButtonLowerLeft) .GetPressedShortlyTrigger() .Attach(light.GetSetStateAction(deskOnlyStateId)); room.GetButton(Office.ButtonUpperLeft) .GetPressedShortlyTrigger() .Attach(light.GetSetStateAction(BinaryStateId.On)); var synonymService = Controller.GetService <SynonymService>(); synonymService.AddSynonymsForArea(Room.Office, "Büro", "Arbeitszimmer"); synonymService.AddSynonymsForComponent(Room.Office, Office.CombinedCeilingLights, "Licht"); synonymService.AddSynonymsForComponent(Room.Office, Office.SocketRearLeftEdge, "Rotlicht", "Pufflicht", "Rot"); synonymService.AddSynonymsForComponentState(deskOnlyStateId, "Schreibtisch"); synonymService.AddSynonymsForComponentState(couchOnlyStateId, "Couch"); }
private void OnStateChanged(StatefulComponentState oldState, StatefulComponentState newState) { StateChanged?.Invoke(this, new StateChangedEventArgs(oldState, newState)); }
private static void HandleBlindButtonPressedEvent(IRollerShutter rollerShutter, StatefulComponentState direction) { if (direction == RollerShutterStateId.MovingUp && rollerShutter.GetState() == RollerShutterStateId.MovingUp) { rollerShutter.SetState(RollerShutterStateId.Off); } else if (direction == RollerShutterStateId.MovingDown && rollerShutter.GetState() == RollerShutterStateId.MovingDown) { rollerShutter.SetState(RollerShutterStateId.Off); } else if (direction == RollerShutterStateId.MovingDown) { rollerShutter.SetState(RollerShutterStateId.MovingDown); } else if (direction == RollerShutterStateId.MovingUp) { rollerShutter.SetState(RollerShutterStateId.MovingUp); } else { throw new InvalidOperationException(); } }