Esempio n. 1
0
        public Room(string uid, IEnumerable <string> neighbors, Component lamp, IDaylightService daylightService,
                    IConcurrencyProvider concurrencyProvider, ILogger logger,
                    AreaDescriptor areaDescriptor, MotionConfiguration motionConfiguration, IEnumerable <IEventDecoder> eventsDecoders)
        {
            Uid       = uid ?? throw new ArgumentNullException(nameof(uid));
            Neighbors = neighbors ?? throw new ArgumentNullException(nameof(neighbors));
            Lamp      = lamp ?? throw new ArgumentNullException(nameof(lamp));

            if (areaDescriptor.WorkingTime == WorkingTime.DayLight)
            {
                _turnOnConditionsValidator.WithCondition(ConditionRelation.And, new IsDayCondition(daylightService));
            }
            else if (areaDescriptor.WorkingTime == WorkingTime.AfterDusk)
            {
                _turnOnConditionsValidator.WithCondition(ConditionRelation.And, new IsNightCondition(daylightService));
            }

            _turnOnConditionsValidator.WithCondition(ConditionRelation.And, new IsEnabledAutomationCondition(this));
            _turnOffConditionsValidator.WithCondition(ConditionRelation.And, new IsEnabledAutomationCondition(this));
            _turnOffConditionsValidator.WithCondition(ConditionRelation.And, new IsTurnOffAutomaionCondition(this));

            _logger = logger;
            _motionConfiguration = motionConfiguration;
            _concurrencyProvider = concurrencyProvider;
            _eventsDecoders      = eventsDecoders;
            AreaDescriptor       = areaDescriptor;
            _TurnOffTimeOut      = new Timeout(AreaDescriptor.TurnOffTimeout, _motionConfiguration.TurnOffPresenceFactor);

            _eventsDecoders?.ForEach(decoder => decoder.Init(this));
        }
Esempio n. 2
0
        public TurnOnAndOffAutomation WithTurnOnWithinTimeRange(Func <TimeSpan> from, Func <TimeSpan> until)
        {
            if (@from == null)
            {
                throw new ArgumentNullException(nameof(@from));
            }
            if (until == null)
            {
                throw new ArgumentNullException(nameof(until));
            }

            _enablingConditionsValidator.WithCondition(ConditionRelation.Or, new TimeRangeCondition(_timer).WithStart(from).WithEnd(until));
            return(this);
        }
Esempio n. 3
0
        public TurnOnAndOffAutomation WithTurnOffCondition(ConditionRelation relation, ICondition condition)
        {
            if (condition == null)
            {
                throw new ArgumentNullException(nameof(condition));
            }

            _turnOffConditionsValidator.WithCondition(relation, condition);
            return(this);
        }
Esempio n. 4
0
        public TurnOnAndOffAutomation WithSkipIfAnyActuatorIsAlreadyOn(params IStateMachine[] actuators)
        {
            if (actuators == null)
            {
                throw new ArgumentNullException(nameof(actuators));
            }

            _disablingConditionsValidator.WithCondition(ConditionRelation.Or,
                                                        new Condition().WithExpression(() => actuators.Any(a => a.GetState().Equals(BinaryStateId.On))));

            return(this);
        }
Esempio n. 5
0
        public TurnOnAndOffAutomation WithSkipIfAnyIsAlreadyOn(params IComponent[] components)
        {
            if (components == null)
            {
                throw new ArgumentNullException(nameof(components));
            }

            _disablingConditionsValidator.WithCondition(ConditionRelation.Or,
                                                        new Condition().WithExpression(() => components.Any(a => a.GetState().Has(PowerState.On))));

            return(this);
        }