示例#1
0
        private IComponent ParseMotionDetector(XElement element)
        {
            IBinaryInput input = Parser.ParseBinaryInput(element.GetMandatorySingleChildElementOrFromContainer("Input"));

            return(new MotionDetector(
                       new ComponentId(element.GetMandatoryStringFromAttribute("id")),
                       new PortBasedMotionDetectorEndpoint(input),
                       Controller.ServiceLocator.GetService <ISchedulerService>()));
        }
        public RollerShutterButtons(string id, IBinaryInput upInput, IBinaryInput downInput,
            IHttpRequestController httpRequestController, INotificationHandler notificationHandler, IHomeAutomationTimer timer) : base(id, httpRequestController, notificationHandler)
        {
            if (upInput == null) throw new ArgumentNullException(nameof(upInput));
            if (downInput == null) throw new ArgumentNullException(nameof(downInput));

            Up = new Button(id + "-up", upInput, httpRequestController, notificationHandler, timer);
            Down = new Button(id + "-down", downInput, httpRequestController, notificationHandler, timer);
        }
        public BinaryInputStateCondition(IBinaryInput input, BinaryState state)
        {
            if (input == null)
            {
                throw new ArgumentNullException(nameof(input));
            }

            WithExpression(() => input.Read() == state);
        }
示例#4
0
 public Button(string id, IBinaryInput input, IHttpRequestController httpApiController, INotificationHandler notificationHandler, IHomeAutomationTimer timer)
     : base(id, httpApiController, notificationHandler)
 {
     if (id == null) throw new ArgumentNullException(nameof(id));
     if (input == null) throw new ArgumentNullException(nameof(input));
     
     timer.Tick += CheckForTimeout;
     input.StateChanged += HandleInputStateChanged;
 }
        public PortBasedMotionDetectorAdapter(IBinaryInput input)
        {
            if (input == null)
            {
                throw new ArgumentNullException(nameof(input));
            }

            input.StateChanged += DispatchEvents;
        }
示例#6
0
        public PortBasedButtonAdapter(IBinaryInput input)
        {
            if (input == null)
            {
                throw new ArgumentNullException(nameof(input));
            }

            input.StateChanged += ForwardState;
        }
示例#7
0
        public InterruptMonitor(IBinaryInput pin)
        {
            if (pin == null)
            {
                throw new ArgumentNullException(nameof(pin));
            }

            _pin = pin;
        }
        public PortBasedButtonEndpoint(IBinaryInput input)
        {
            if (input == null)
            {
                throw new ArgumentNullException(nameof(input));
            }

            input.StateChanged += DispatchState;
        }
示例#9
0
        private IComponent ParseButton(XElement element)
        {
            IBinaryInput input = Parser.ParseBinaryInput(element.GetMandatorySingleChildElementOrFromContainer("Input"));

            return(new Button(
                       new ComponentId(element.GetMandatoryStringFromAttribute("id")),
                       new PortBasedButtonEndpoint(input),
                       Controller.Timer));
        }
示例#10
0
        public static IBinaryInput WithInvertedState(this IBinaryInput binaryInput)
        {
            if (binaryInput == null)
            {
                throw new ArgumentNullException(nameof(binaryInput));
            }

            return(new InvertedBinaryInput(binaryInput));
        }
示例#11
0
        public BinaryInputButtonAdapter(IBinaryInput input)
        {
            if (input == null)
            {
                throw new ArgumentNullException(nameof(input));
            }

            input.StateChanged += DispatchState;
        }
示例#12
0
        public InterruptMonitor(IBinaryInput binaryInput, ILogService logService)
        {
            _binaryInput = binaryInput ?? throw new ArgumentNullException(nameof(binaryInput));
            _log         = logService?.CreatePublisher(nameof(InterruptMonitor)) ?? throw new ArgumentNullException(nameof(logService));

            // The server-based Timer is designed for use with worker threads in a multithreaded environment.
            // Server timers can move among threads to handle the raised Elapsed event, resulting in more accuracy
            // than Windows timers in raising the event on time.
            _timer = new Timer(Poll, null, Timeout.Infinite, Timeout.Infinite);
        }
示例#13
0
        private IActuator ParseButton(XElement element)
        {
            IBinaryInput input = Parser.ParseBinaryInput(element.GetMandatorySingleChildElementOrFromContainer("Input"));

            return(new Button(
                       new ActuatorId(element.GetMandatoryStringFromAttribute("id")),
                       input,
                       Controller.HttpApiController,
                       Controller.Logger,
                       Controller.Timer));
        }
        public InterruptMonitor(IBinaryInput pin)
        {
            if (pin == null) throw new ArgumentNullException(nameof(pin));

            _pin = pin;

            // The server-based Timer is designed for use with worker threads in a multithreaded environment.
            // Server timers can move among threads to handle the raised Elapsed event, resulting in more accuracy
            // than Windows timers in raising the event on time.
            _timer = new Timer(Poll, null, Timeout.Infinite, Timeout.Infinite);
        }
示例#15
0
        public InterruptMonitor(string id, IBinaryInput input, ILogService logService)
        {
            if (input == null)
            {
                throw new ArgumentNullException(nameof(input));
            }
            _id  = id ?? throw new ArgumentNullException(nameof(id));
            _log = logService?.CreatePublisher(nameof(InterruptMonitor)) ?? throw new ArgumentNullException(nameof(logService));

            input.StateChanged += HandleInterrupt;
        }
        public MotionDetector(string id, IBinaryInput input, IHomeAutomationTimer timer, IHttpRequestController httpApiController, INotificationHandler notificationHandler)
            : base(id, httpApiController, notificationHandler)
        {
            if (input == null) throw new ArgumentNullException(nameof(input));
            
            input.StateChanged += (s, e) => HandleInputStateChanged(e);

            IsEnabledChanged += (s, e) =>
            {
                HandleIsEnabledStateChanged(timer, notificationHandler);
            };
        }
示例#17
0
        public PortBasedWindowAdapter(IBinaryInput fullOpenReedSwitch, IBinaryInput tildOpenReedSwitch = null)
        {
            _fullOpenReedSwitch = fullOpenReedSwitch ?? throw new ArgumentNullException(nameof(fullOpenReedSwitch));
            _tildOpenReedSwitch = tildOpenReedSwitch;

            if (_tildOpenReedSwitch != null)
            {
                _tildOpenReedSwitch.StateChanged += (s, e) => Refresh();
            }

            _fullOpenReedSwitch.StateChanged += (s, e) => Refresh();
        }
示例#18
0
        private IActuator ParseRollerShutterButtons(XElement element)
        {
            IBinaryInput upInput   = Parser.ParseBinaryInput(element.GetMandatorySingleChildFromContainer("Up"));
            IBinaryInput downInput = Parser.ParseBinaryInput(element.GetMandatorySingleChildFromContainer("Down"));

            return(new RollerShutterButtons(
                       new ActuatorId(element.GetMandatoryStringFromAttribute("id")),
                       upInput,
                       downInput,
                       Controller.HttpApiController,
                       Controller.Logger,
                       Controller.Timer));
        }
        public static IArea WithButton(this IArea room, Enum id, IBinaryInput input)
        {
            if (room == null)
            {
                throw new ArgumentNullException(nameof(room));
            }
            if (input == null)
            {
                throw new ArgumentNullException(nameof(input));
            }

            room.AddActuator(new Button(ActuatorIdFactory.Create(room, id), input, room.Controller.HttpApiController, room.Controller.Logger, room.Controller.Timer));
            return(room);
        }
示例#20
0
        public InterruptMonitor(IBinaryInput pin)
        {
            if (pin == null)
            {
                throw new ArgumentNullException(nameof(pin));
            }

            _pin = pin;

            // The server-based Timer is designed for use with worker threads in a multithreaded environment.
            // Server timers can move among threads to handle the raised Elapsed event, resulting in more accuracy
            // than Windows timers in raising the event on time.
            _timer = new Timer(Poll, null, Timeout.Infinite, Timeout.Infinite);
        }
示例#21
0
        public InterruptMonitor(IBinaryInput pin, ILogger logger)
        {
            if (pin == null)
            {
                throw new ArgumentNullException(nameof(pin));
            }
            if (logger == null)
            {
                throw new ArgumentNullException(nameof(logger));
            }

            _pin    = pin;
            _logger = logger;
        }
示例#22
0
        public IMotionDetector RegisterMotionDetector(IArea area, Enum id, IBinaryInput input)
        {
            if (area == null) throw new ArgumentNullException(nameof(area));
            if (input == null) throw new ArgumentNullException(nameof(input));

            var motionDetector = new MotionDetector(
                ComponentIdGenerator.Generate(area.Id, id),
                new PortBasedMotionDetectorEndpoint(input),
                _schedulerService,
                _settingsService);

            area.AddComponent(motionDetector);

            return motionDetector;
        }
示例#23
0
        public Button(ActuatorId id, IBinaryInput input, IHttpRequestController api, ILogger logger, IHomeAutomationTimer timer)
            : base(id, api, logger)
        {
            if (id == null)
            {
                throw new ArgumentNullException(nameof(id));
            }
            if (input == null)
            {
                throw new ArgumentNullException(nameof(input));
            }

            timer.Tick         += CheckForTimeout;
            input.StateChanged += HandleInputStateChanged;
        }
示例#24
0
        private Casement ParseCasement(XElement element, string defaultId)
        {
            IBinaryInput fullOpenInput = Parser.ParseBinaryInput(element.GetMandatorySingleChildFromContainer("FullOpen"));

            IBinaryInput tiltInput = null;

            if (element.HasChildElement("Tilt"))
            {
                tiltInput = Parser.ParseBinaryInput(element.GetMandatorySingleChildFromContainer("Tilt"));
            }

            var casement = new Casement(element.GetStringFromAttribute("id", defaultId), fullOpenInput, tiltInput);

            return(casement);
        }
示例#25
0
        public IButton RegisterButton(IArea area, Enum id, IBinaryInput input, Action<IButton> initializer = null)
        {
            if (area == null) throw new ArgumentNullException(nameof(area));
            if (input == null) throw new ArgumentNullException(nameof(input));

            var button = new Button(
                ComponentIdGenerator.Generate(area.Id, id),
                new PortBasedButtonEndpoint(input),
                _timerService,
                _settingsService);

            initializer?.Invoke(button);

            area.AddComponent(button);
            return button;
        }
示例#26
0
        public MotionDetector(ActuatorId id, IBinaryInput input, IHomeAutomationTimer timer, IHttpRequestController api, ILogger logger)
            : base(id, api, logger)
        {
            if (input == null)
            {
                throw new ArgumentNullException(nameof(input));
            }

            input.StateChanged += (s, e) => HandleInputStateChanged(e);

            base.Settings = new ActuatorSettings(id, logger);
            Settings.IsEnabled.ValueChanged += (s, e) =>
            {
                HandleIsEnabledStateChanged(timer, logger);
            };
        }
        public RollerShutterButtons(ActuatorId id, IBinaryInput upInput, IBinaryInput downInput,
                                    IHttpRequestController httpApiController, ILogger logger, IHomeAutomationTimer timer) : base(id, httpApiController, logger)
        {
            if (upInput == null)
            {
                throw new ArgumentNullException(nameof(upInput));
            }
            if (downInput == null)
            {
                throw new ArgumentNullException(nameof(downInput));
            }

            Up   = new Button(new ActuatorId(id + "-up"), upInput, httpApiController, logger, timer);
            Down = new Button(new ActuatorId(id + "-down"), downInput, httpApiController, logger, timer);

            Settings = new ActuatorSettings(id, logger);
        }
示例#28
0
        public IButton RegisterButton(IArea area, Enum id, IBinaryInput input)
        {
            if (area == null)
            {
                throw new ArgumentNullException(nameof(area));
            }
            if (input == null)
            {
                throw new ArgumentNullException(nameof(input));
            }

            var adapter = new PortBasedButtonAdapter(input);
            var button  = new Button($"{area.Id}.{id}", adapter, _timerService, _settingsService, _messageBroker, _logService);

            area.RegisterComponent(button);
            return(button);
        }
示例#29
0
        public IWindow RegisterWindow(IArea area, Enum id, IBinaryInput fullOpenReedSwitch, IBinaryInput tildOpenReedSwitch = null)
        {
            if (area == null)
            {
                throw new ArgumentNullException(nameof(area));
            }
            if (fullOpenReedSwitch == null)
            {
                throw new ArgumentNullException(nameof(fullOpenReedSwitch));
            }

            var adapter = new PortBasedWindowAdapter(fullOpenReedSwitch, tildOpenReedSwitch);
            var window  = new Window($"{area.Id}.{id}", adapter, _settingsService);

            area.RegisterComponent(window);
            return(window);
        }
示例#30
0
        public Casement(string id, IBinaryInput fullOpenReedSwitch, IBinaryInput tiltReedSwitch = null)
        {
            if (id == null) throw new ArgumentNullException(nameof(id));
            if (fullOpenReedSwitch == null) throw new ArgumentNullException(nameof(fullOpenReedSwitch));

            Id = id;
            _fullOpenReedSwitch = fullOpenReedSwitch;
            _tiltReedSwitch = tiltReedSwitch;

            if (_tiltReedSwitch != null)
            {
                _tiltReedSwitch.StateChanged += (s, e) => Update();
            }

            _fullOpenReedSwitch.StateChanged += (s, e) => Update();

            Update();
        }
示例#31
0
        public static IArea WithMotionDetector(this IArea area, Enum id, IBinaryInput input)
        {
            if (area == null)
            {
                throw new ArgumentNullException(nameof(area));
            }
            if (input == null)
            {
                throw new ArgumentNullException(nameof(input));
            }

            var motionDetector = new MotionDetector(
                ComponentIdFactory.Create(area.Id, id),
                new PortBasedMotionDetectorEndpoint(input),
                area.Controller.ServiceLocator.GetService <ISchedulerService>());

            area.AddComponent(motionDetector);
            return(area);
        }
示例#32
0
        private void RegisterInterrupt(string id, IBinaryInput input)
        {
            if (id == null)
            {
                throw new ArgumentNullException(nameof(id));
            }
            if (input == null)
            {
                throw new ArgumentNullException(nameof(input));
            }

            var interruptMonitor = new InterruptMonitor(id, input, _logService);

            lock (_interruptMonitors)
            {
                _interruptMonitors.Add(id, interruptMonitor);
            }

            _log.Verbose($"Registered interrupt '{id}'.");
        }
        public static IArea WithRollerShutterButtons(this IArea room, Enum id, IBinaryInput upInput, IBinaryInput downInput)
        {
            if (room == null)
            {
                throw new ArgumentNullException(nameof(room));
            }
            if (upInput == null)
            {
                throw new ArgumentNullException(nameof(upInput));
            }
            if (downInput == null)
            {
                throw new ArgumentNullException(nameof(downInput));
            }

            var rollerShutterButtons = new RollerShutterButtons(ActuatorIdFactory.Create(room, id), upInput, downInput,
                                                                room.Controller.HttpApiController, room.Controller.Logger, room.Controller.Timer);

            room.AddActuator(rollerShutterButtons);
            return(room);
        }
示例#34
0
        public IMotionDetector RegisterMotionDetector(IArea area, Enum id, IBinaryInput input)
        {
            if (area == null)
            {
                throw new ArgumentNullException(nameof(area));
            }
            if (input == null)
            {
                throw new ArgumentNullException(nameof(input));
            }

            var motionDetector = new MotionDetector(
                $"{area.Id}.{id}",
                new PortBasedMotionDetectorAdapter(input),
                _schedulerService,
                _settingsService);

            area.RegisterComponent(motionDetector);

            return(motionDetector);
        }
示例#35
0
        public static IArea WithButton(this IArea area, Enum id, IBinaryInput input, Action <IButton> initializer = null)
        {
            if (area == null)
            {
                throw new ArgumentNullException(nameof(area));
            }
            if (input == null)
            {
                throw new ArgumentNullException(nameof(input));
            }

            var button = new Button(
                ComponentIdFactory.Create(area.Id, id),
                new PortBasedButtonEndpoint(input),
                area.Controller.Timer);

            initializer?.Invoke(button);

            area.AddComponent(button);
            return(area);
        }
示例#36
0
        public IMotionDetector RegisterMotionDetector(IArea area, Enum id, IBinaryInput input)
        {
            if (area == null)
            {
                throw new ArgumentNullException(nameof(area));
            }
            if (input == null)
            {
                throw new ArgumentNullException(nameof(input));
            }

            var motionDetector = new MotionDetector(
                ComponentIdGenerator.Generate(area.Id, id),
                new PortBasedMotionDetectorEndpoint(input),
                _schedulerService,
                _settingsService);

            area.AddComponent(motionDetector);

            return(motionDetector);
        }
示例#37
0
        public IButton RegisterButton(IArea area, Enum id, IBinaryInput input, Action <IButton> initializer = null)
        {
            if (area == null)
            {
                throw new ArgumentNullException(nameof(area));
            }
            if (input == null)
            {
                throw new ArgumentNullException(nameof(input));
            }

            var button = new Button(
                ComponentIdGenerator.Generate(area.Id, id),
                new PortBasedButtonEndpoint(input),
                _timerService,
                _settingsService);

            initializer?.Invoke(button);

            area.AddComponent(button);
            return(button);
        }
示例#38
0
 public Window WithRightCasement(IBinaryInput fullOpenReedSwitch, IBinaryInput tiltReedSwitch = null)
 {
     return WithCasement(new Casement(Casement.RightCasementId, fullOpenReedSwitch, tiltReedSwitch));
 }
示例#39
0
 public Window WithCasement(string id, IBinaryInput fullOpenReedSwitch, IBinaryInput tiltReedSwitch = null)
 {
     return WithCasement(new Casement(id, fullOpenReedSwitch, tiltReedSwitch));
 }
        public InterruptMonitor(IBinaryInput pin)
        {
            if (pin == null) throw new ArgumentNullException(nameof(pin));

            _pin = pin;
        }
示例#41
0
        public void RegisterRollerShutterButtons(
            IArea area,
            Enum upId,
            IBinaryInput upInput,
            Enum downId,
            IBinaryInput downInput)
        {
            if (area == null) throw new ArgumentNullException(nameof(area));
            if (upInput == null) throw new ArgumentNullException(nameof(upInput));
            if (downInput == null) throw new ArgumentNullException(nameof(downInput));

            var upButton = new Button(
                ComponentIdGenerator.Generate(area.Id, upId),
                new PortBasedButtonEndpoint(upInput),
                _timerService,
                _settingsService);

            area.AddComponent(upButton);

            var downButton = new Button(
                ComponentIdGenerator.Generate(area.Id, downId),
                new PortBasedButtonEndpoint(downInput),
                _timerService,
                _settingsService);

            area.AddComponent(downButton);
        }
        public PortBasedMotionDetectorEndpoint(IBinaryInput input)
        {
            if (input == null) throw new ArgumentNullException(nameof(input));

            input.StateChanged += DispatchEvents;
        }
        public PortBasedButtonEndpoint(IBinaryInput input)
        {
            if (input == null) throw new ArgumentNullException(nameof(input));

            input.StateChanged += DispatchState;
        }