Exemplo n.º 1
0
        public void State_NotEquals_State()
        {
            IComponentState state1 = new NamedComponentState("Off");
            IComponentState state2 = new NamedComponentState("On");

            state1.Equals(state2).ShouldBeEquivalentTo(false);
        }
Exemplo n.º 2
0
        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 NamedComponentState(apiContext.Request.GetNamedString("state", string.Empty));
                if (!SupportsState(stateId))
                {
                    apiContext.ResultCode = ApiResultCode.InvalidBody;
                    apiContext.Response.SetNamedString("Message", "State ID not supported.");
                }

                SetState(stateId);
            }
        }
Exemplo n.º 3
0
 private void SetStates(NamedComponentState state)
 {
     foreach (var rollerShutter in _rollerShutters)
     {
         _componentController.GetComponent <IRollerShutter>(rollerShutter).SetState(state);
     }
 }
Exemplo n.º 4
0
        public void State_NotEquals_DifferentState()
        {
            IComponentState state1 = new NamedComponentState("Off");
            IComponentState state2 = new NumericSensorValue(5);

            state1.Equals(state2).ShouldBeEquivalentTo(false);
        }
Exemplo n.º 5
0
        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);
        }
Exemplo n.º 6
0
        public void StatefulState_Serialize()
        {
            IComponentState state     = new NamedComponentState("Off");
            IJsonValue      jsonValue = state.ToJsonValue();

            jsonValue.ValueType.ShouldBeEquivalentTo(JsonValueType.String);
            jsonValue.GetString().ShouldBeEquivalentTo("Off");
        }
Exemplo n.º 7
0
        public void SetInitialState(NamedComponentState id)
        {
            if (id == null)
            {
                throw new ArgumentNullException(nameof(id));
            }

            SetState(id, HardwareParameter.ForceUpdateState);
        }
Exemplo n.º 8
0
        public TestStateMachine CreateTestStateMachineWithActiveState(NamedComponentState id)
        {
            var stateMachine = new TestStateMachine(ComponentIdFactory.EmptyId);

            stateMachine.AddState(new StateMachineState(id));
            stateMachine.SetState(id);

            return(stateMachine);
        }
Exemplo n.º 9
0
        private void HandleInputStateChanged(NamedComponentState state)
        {
            if (!this.IsEnabled())
            {
                return;
            }

            SetState(state);
            InvokeTriggers();
        }
Exemplo n.º 10
0
        public StateMachineState WithActuator(IActuator actuator, NamedComponentState state)
        {
            if (actuator == null)
            {
                throw new ArgumentNullException(nameof(actuator));
            }

            _pendingActuatorStates.Add(new PendingActuatorState().WithActuator(actuator).WithState(state));
            return(this);
        }
Exemplo n.º 11
0
        public TestStateMachine CreateTestStateMachineWithOnOffStates(NamedComponentState activeState)
        {
            var stateMachine = new TestStateMachine(ComponentIdFactory.EmptyId);

            stateMachine.AddState(new StateMachineState(BinaryStateId.Off));
            stateMachine.AddState(new StateMachineState(BinaryStateId.On));
            stateMachine.SetState(activeState);

            return(stateMachine);
        }
Exemplo n.º 12
0
        public static StateMachineState AddState(this StateMachine stateMachine, NamedComponentState 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);
        }
Exemplo n.º 13
0
        private void UpdateState(NamedComponentState newState)
        {
            if (!this.IsEnabled())
            {
                return;
            }

            SetState(newState);

            if (newState == MotionDetectorStateId.MotionDetected)
            {
                OnMotionDetected();
            }
            else
            {
                OnDetectionCompleted();
            }
        }
Exemplo n.º 14
0
 public StateChangedEventArgs(NamedComponentState oldState, NamedComponentState newState)
 {
     OldState = oldState;
     NewState = newState;
 }
Exemplo n.º 15
0
        public static IAction GetSetStateAction(this IStateMachine stateStateMachine, NamedComponentState stateId)
        {
            if (stateStateMachine == null)
            {
                throw new ArgumentNullException(nameof(stateStateMachine));
            }
            if (stateId == null)
            {
                throw new ArgumentNullException(nameof(stateId));
            }

            return(new Action(() => stateStateMachine.SetState(stateId)));
        }
Exemplo n.º 16
0
        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 NamedComponentState("DeskOnly");

            light.AddState(deskOnlyStateId)
            .WithHighOutput(fl)
            .WithHighOutput(fm)
            .WithLowOutput(fr)
            .WithHighOutput(ml)
            .WithLowOutput(mm)
            .WithLowOutput(mr)
            .WithLowOutput(rl)
            .WithLowOutput(rr);

            var couchOnlyStateId = new NamedComponentState("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.ServiceLocator.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");
        }
Exemplo n.º 17
0
 private static void HandleBlindButtonPressedEvent(IRollerShutter rollerShutter, NamedComponentState 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();
     }
 }
Exemplo n.º 18
0
        public override void HandleApiCommand(IApiContext apiContext)
        {
            var state = new NamedComponentState(apiContext.Request.GetNamedString("state"));

            SetState(state);
        }
Exemplo n.º 19
0
 private void OnStateChanged(NamedComponentState oldState, NamedComponentState newState)
 {
     StateChanged?.Invoke(this, new StateChangedEventArgs(oldState, newState));
 }