public RollerShutter(
            string id, 
            IBinaryOutput powerOutput, 
            IBinaryOutput directionOutput, 
            TimeSpan autoOffTimeout,
            int maxPosition,
            IHttpRequestController httpApiController,
            INotificationHandler notificationHandler, 
            IHomeAutomationTimer timer)
            : base(id, httpApiController, notificationHandler)
        {
            if (id == null) throw new ArgumentNullException(nameof(id));
            if (powerOutput == null) throw new ArgumentNullException(nameof(powerOutput));
            if (directionOutput == null) throw new ArgumentNullException(nameof(directionOutput));

            _powerGpioPin = powerOutput;
            _directionGpioPin = directionOutput;
            _autoOffTimeout = autoOffTimeout;
            _positionMax = maxPosition;
            _timer = timer;

            //TODO: StartMoveUp();

            timer.Tick += (s, e) => UpdatePosition(e);
        }
        public LogicalBinaryOutput WithOutput(IBinaryOutput output)
        {
            if (output == null) throw new ArgumentNullException(nameof(output));

            _outputs.Add(output);
            return this;
        }
Esempio n. 3
0
        public HealthService(
            ControllerOptions controllerOptions,
            IPi2GpioService pi2GpioService,
            ITimerService timerService,
            ISystemInformationService systemInformationService)
        {
            if (controllerOptions == null)
            {
                throw new ArgumentNullException(nameof(controllerOptions));
            }
            if (timerService == null)
            {
                throw new ArgumentNullException(nameof(timerService));
            }
            if (systemInformationService == null)
            {
                throw new ArgumentNullException(nameof(systemInformationService));
            }

            _systemInformationService = systemInformationService;

            if (controllerOptions.StatusLedNumber.HasValue)
            {
                _led = pi2GpioService.GetOutput(controllerOptions.StatusLedNumber.Value);
                _ledTimeout.Start(TimeSpan.FromMilliseconds(1));
            }

            timerService.Tick += Tick;
        }
        public BinaryOutputWithState(IBinaryOutput output, BinaryState state)
        {
            if (output == null) throw new ArgumentNullException(nameof(output));

            Output = output;
            State = state;
        }
        public static IArea WithRollerShutter(this IArea area, Enum id, IBinaryOutput powerOutput, IBinaryOutput directionOutput)
        {
            if (area == null)
            {
                throw new ArgumentNullException(nameof(area));
            }

            if (powerOutput == null)
            {
                throw new ArgumentNullException(nameof(powerOutput));
            }
            if (directionOutput == null)
            {
                throw new ArgumentNullException(nameof(directionOutput));
            }

            var rollerShutter = new RollerShutter(
                ComponentIdFactory.Create(area.Id, id),
                new PortBasedRollerShutterEndpoint(powerOutput, directionOutput),
                area.Controller.Timer,
                area.Controller.ServiceLocator.GetService <ISchedulerService>());

            area.AddComponent(rollerShutter);
            return(area);
        }
Esempio n. 6
0
        public RollerShutter(
            ActuatorId id,
            IBinaryOutput powerOutput,
            IBinaryOutput directionOutput,
            IHttpRequestController httpApiController,
            ILogger logger,
            IHomeAutomationTimer timer)
            : base(id, httpApiController, logger)
        {
            if (id == null)
            {
                throw new ArgumentNullException(nameof(id));
            }
            if (powerOutput == null)
            {
                throw new ArgumentNullException(nameof(powerOutput));
            }
            if (directionOutput == null)
            {
                throw new ArgumentNullException(nameof(directionOutput));
            }

            _powerGpioPin     = powerOutput;
            _directionGpioPin = directionOutput;
            _timer            = timer;

            timer.Tick += (s, e) => UpdatePosition(e);

            base.Settings = new RollerShutterSettings(id, logger);
        }
        public StateMachineState WithPort(IBinaryOutput output, BinaryState state)
        {
            if (output == null) throw new ArgumentNullException(nameof(output));

            _outputs.Add(new Tuple<IBinaryOutput, BinaryState>(output, state));
            return this;
        }
Esempio n. 8
0
        public IRollerShutter RegisterRollerShutter(IArea area, Enum id, IBinaryOutput powerOutput, IBinaryOutput directionOutput)
        {
            if (area == null)
            {
                throw new ArgumentNullException(nameof(area));
            }
            if (powerOutput == null)
            {
                throw new ArgumentNullException(nameof(powerOutput));
            }
            if (directionOutput == null)
            {
                throw new ArgumentNullException(nameof(directionOutput));
            }

            var rollerShutter = new RollerShutter(
                ComponentIdGenerator.Generate(area.Id, id),
                new PortBasedRollerShutterEndpoint(powerOutput, directionOutput),
                _timerService,
                _schedulerService,
                _settingsService);

            area.AddComponent(rollerShutter);

            return(rollerShutter);
        }
Esempio n. 9
0
        public IRollerShutter RegisterRollerShutter(IArea area, Enum id, IBinaryOutput powerOutput, IBinaryOutput directionOutput)
        {
            if (area == null)
            {
                throw new ArgumentNullException(nameof(area));
            }
            if (powerOutput == null)
            {
                throw new ArgumentNullException(nameof(powerOutput));
            }
            if (directionOutput == null)
            {
                throw new ArgumentNullException(nameof(directionOutput));
            }

            var rollerShutter = new RollerShutter(
                $"{area.Id}.{id}",
                new PortBasedRollerShutterAdapter(powerOutput, directionOutput),
                _timerService,
                _settingsService);

            area.RegisterComponent(rollerShutter);

            return(rollerShutter);
        }
        public BinaryStateOutputActuator(string id, IBinaryOutput output, IHttpRequestController httpRequestController,
            INotificationHandler notificationHandler) : base(id, httpRequestController, notificationHandler)
        {
            if (output == null) throw new ArgumentNullException(nameof(output));

            _output = output;
            SetStateInternal(BinaryActuatorState.Off, new ForceUpdateStateParameter());
        }
Esempio n. 11
0
        private IComponent ParseCustomBinaryStateOutputActuator(XElement element)
        {
            IBinaryOutput output = Parser.ParseBinaryOutput(element.GetMandatorySingleChildElementOrFromContainer("Output"));

            return(new CustomBinaryStateActuator(
                       new ComponentId(element.GetMandatoryStringFromAttribute("id")),
                       new PortBasedBinaryStateEndpoint(output)));
        }
        public PortBasedRollerShutterEndpoint(IBinaryOutput powerOutput, IBinaryOutput directionOutput)
        {
            if (powerOutput == null) throw new ArgumentNullException(nameof(powerOutput));
            if (directionOutput == null) throw new ArgumentNullException(nameof(directionOutput));

            _powerOutput = powerOutput;
            _directionOutput = directionOutput;
        }
Esempio n. 13
0
        public StateMachineState WithHighOutput(IBinaryOutput output)
        {
            if (output == null)
            {
                throw new ArgumentNullException(nameof(output));
            }

            return(WithOutput(output, BinaryState.High));
        }
        public PortBasedBinaryStateEndpoint(IBinaryOutput output)
        {
            if (output == null)
            {
                throw new ArgumentNullException(nameof(output));
            }

            _output = output;
        }
Esempio n. 15
0
 /// <summary>
 /// Default ctor
 /// </summary>
 public BinaryOutputItem(IBinaryOutput entity, IBinaryOutputState state, ItemContext context, bool interactive)
     : base(entity, false, context)
 {
     this.state = state;
     if (interactive)
     {
         MouseHandler = new ClickHandler(null, state);
     }
 }
Esempio n. 16
0
        public static IBinaryOutput WithInvertedState(this IBinaryOutput binaryOutput)
        {
            if (binaryOutput == null)
            {
                throw new ArgumentNullException(nameof(binaryOutput));
            }

            return(new InvertedBinarOutput(binaryOutput));
        }
        public BinaryOutputWithState(IBinaryOutput output, BinaryState state)
        {
            if (output == null)
            {
                throw new ArgumentNullException(nameof(output));
            }

            Output = output;
            State  = state;
        }
        public ISocket RegisterSocket(IArea area, Enum id, IBinaryOutput output)
        {
            if (area == null) throw new ArgumentNullException(nameof(area));
            if (output == null) throw new ArgumentNullException(nameof(output));

            var socket = new Socket(ComponentIdGenerator.Generate(area.Id, id), new PortBasedBinaryStateEndpoint(output));
            area.AddComponent(socket);

            return socket;
        }
        protected BinaryStateOutputActuator(ActuatorId id, IBinaryOutput output, IHttpRequestController httpApiController, ILogger logger)
            : base(id, httpApiController, logger)
        {
            if (output == null)
            {
                throw new ArgumentNullException(nameof(output));
            }

            _output = output;
        }
Esempio n. 20
0
        private IActuator ParseCustomBinaryStateOutputActuator(XElement element)
        {
            IBinaryOutput output = Parser.ParseBinaryOutput(element.GetMandatorySingleChildElementOrFromContainer("Output"));

            return(new CustomBinaryStateOutputActuator(
                       new ActuatorId(element.GetMandatoryStringFromAttribute("id")),
                       output,
                       Controller.HttpApiController,
                       Controller.Logger));
        }
        public ILamp RegisterLamp(IArea area, Enum id, IBinaryOutput output)
        {
            if (area == null) throw new ArgumentNullException(nameof(area));
            if (output == null) throw new ArgumentNullException(nameof(output));

            var lamp = new Lamp(ComponentIdGenerator.Generate(area.Id, id), new PortBasedBinaryStateEndpoint(output));
            area.AddComponent(lamp);

            return lamp;
        }
Esempio n. 22
0
        private IComponent ParseRollerShutter(XElement element)
        {
            IBinaryOutput powerOutput     = Parser.ParseBinaryOutput(element.GetMandatorySingleChildFromContainer("Power"));
            IBinaryOutput directionOutput = Parser.ParseBinaryOutput(element.GetMandatorySingleChildFromContainer("Direction"));

            return(new RollerShutter(
                       new ComponentId(element.GetMandatoryStringFromAttribute("id")),
                       new PortBasedRollerShutterEndpoint(powerOutput, directionOutput),
                       Controller.Timer));
        }
Esempio n. 23
0
        public StateMachineState WithOutput(IBinaryOutput output, BinaryState state)
        {
            if (output == null)
            {
                throw new ArgumentNullException(nameof(output));
            }

            _pendingBinaryOutputStates.Add(new Tuple <IBinaryOutput, BinaryState>(output, state));
            return(this);
        }
Esempio n. 24
0
        public LogicalBinaryOutput WithOutput(IBinaryOutput output)
        {
            if (output == null)
            {
                throw new ArgumentNullException(nameof(output));
            }

            _outputs.Add(output);
            return(this);
        }
Esempio n. 25
0
        public StateMachineState WithBinaryOutput(IBinaryOutput output, BinaryState state)
        {
            if (output == null)
            {
                throw new ArgumentNullException(nameof(output));
            }

            _binaryOutputs.Add(new PendingBinaryOutputState {
                BinaryOutput = output, State = state
            });
            return(this);
        }
Esempio n. 26
0
        private void InitializeHealthMonitor()
        {
            IBinaryOutput ledPin = null;

            if (_statusLedNumber.HasValue)
            {
                var pi2PortController = new Pi2PortController();
                ledPin = pi2PortController.GetOutput(_statusLedNumber.Value);
            }

            ServiceLocator.RegisterService(typeof(HealthService), new HealthService(ledPin, Timer, ServiceLocator.GetService <ISystemInformationService>()));
        }
Esempio n. 27
0
        private IActuator ParseRollerShutter(XElement element)
        {
            IBinaryOutput powerOutput     = Parser.ParseBinaryOutput(element.GetMandatorySingleChildFromContainer("Power"));
            IBinaryOutput directionOutput = Parser.ParseBinaryOutput(element.GetMandatorySingleChildFromContainer("Direction"));

            return(new RollerShutter(
                       new ActuatorId(element.GetMandatoryStringFromAttribute("id")),
                       powerOutput,
                       directionOutput,
                       Controller.HttpApiController,
                       Controller.Logger,
                       Controller.Timer));
        }
Esempio n. 28
0
        public ILamp RegisterLamp(IArea area, Enum id, IBinaryOutput output)
        {
            if (area == null)
            {
                throw new ArgumentNullException(nameof(area));
            }
            if (output == null)
            {
                throw new ArgumentNullException(nameof(output));
            }

            return(RegisterLamp(area, id, new PortBasedBinaryOutputAdapter(output)));
        }
        public PortBasedRollerShutterEndpoint(IBinaryOutput powerOutput, IBinaryOutput directionOutput)
        {
            if (powerOutput == null)
            {
                throw new ArgumentNullException(nameof(powerOutput));
            }
            if (directionOutput == null)
            {
                throw new ArgumentNullException(nameof(directionOutput));
            }

            _powerOutput     = powerOutput;
            _directionOutput = directionOutput;
        }
Esempio n. 30
0
 private void SetupHumidityDependingOutput(IHumiditySensor sensor, IBinaryOutput output)
 {
     sensor.ValueChanged += (s, e) =>
     {
         if (e.NewValue > 80.0F)
         {
             output.Write(BinaryState.High);
         }
         else
         {
             output.Write(BinaryState.Low);
         }
     };
 }
Esempio n. 31
0
        public ILamp RegisterLamp(IArea area, Enum id, IBinaryOutput output)
        {
            if (area == null)
            {
                throw new ArgumentNullException(nameof(area));
            }
            if (output == null)
            {
                throw new ArgumentNullException(nameof(output));
            }

            var lamp = new Lamp(ComponentIdGenerator.Generate(area.Id, id), new PortBasedBinaryStateEndpoint(output));

            area.AddComponent(lamp);

            return(lamp);
        }
Esempio n. 32
0
        public ISocket RegisterSocket(IArea area, Enum id, IBinaryOutput output)
        {
            if (area == null)
            {
                throw new ArgumentNullException(nameof(area));
            }
            if (output == null)
            {
                throw new ArgumentNullException(nameof(output));
            }

            var socket = new Socket($"{area.Id}.{id}", new PortBasedBinaryOutputAdapter(output));

            area.RegisterComponent(socket);

            return(socket);
        }
Esempio n. 33
0
        public static IArea WithLamp(this IArea area, Enum id, IBinaryOutput output)
        {
            if (area == null)
            {
                throw new ArgumentNullException(nameof(area));
            }
            if (output == null)
            {
                throw new ArgumentNullException(nameof(output));
            }

            var lamp = new Lamp(ComponentIdFactory.Create(area.Id, id), new PortBasedBinaryStateEndpoint(output));

            area.AddComponent(lamp);

            return(area);
        }
Esempio n. 34
0
        public ISocket RegisterSocket(IArea area, Enum id, IBinaryOutput output)
        {
            if (area == null)
            {
                throw new ArgumentNullException(nameof(area));
            }
            if (output == null)
            {
                throw new ArgumentNullException(nameof(output));
            }

            var socket = new Socket(ComponentIdGenerator.Generate(area.Id, id), new PortBasedBinaryStateEndpoint(output));

            area.AddComponent(socket);

            return(socket);
        }
        public IRollerShutter RegisterRollerShutter(IArea area, Enum id, IBinaryOutput powerOutput, IBinaryOutput directionOutput)
        {
            if (area == null) throw new ArgumentNullException(nameof(area));
            if (powerOutput == null) throw new ArgumentNullException(nameof(powerOutput));
            if (directionOutput == null) throw new ArgumentNullException(nameof(directionOutput));

            var rollerShutter = new RollerShutter(
                ComponentIdGenerator.Generate(area.Id, id),
                new PortBasedRollerShutterEndpoint(powerOutput, directionOutput),
                _timerService,
                _schedulerService,
                _settingsService);

            area.AddComponent(rollerShutter);

            return rollerShutter;
        }
        public static IArea WithLamp(this IArea room, Enum id, IBinaryOutput output)
        {
            if (room == null)
            {
                throw new ArgumentNullException(nameof(room));
            }
            if (output == null)
            {
                throw new ArgumentNullException(nameof(output));
            }

            var lamp = new Lamp(ActuatorIdFactory.Create(room, id), output, room.Controller.HttpApiController, room.Controller.Logger);

            lamp.SetInitialState();

            room.AddActuator(lamp);
            return(room);
        }
Esempio n. 37
0
        public HealthService(
            ControllerOptions controllerOptions, 
            IPi2GpioService pi2GpioService,
            ITimerService timerService, 
            ISystemInformationService systemInformationService)
        {
            if (controllerOptions == null) throw new ArgumentNullException(nameof(controllerOptions));
            if (timerService == null) throw new ArgumentNullException(nameof(timerService));
            if (systemInformationService == null) throw new ArgumentNullException(nameof(systemInformationService));

            _systemInformationService = systemInformationService;

            if (controllerOptions.StatusLedNumber.HasValue)
            {
                _led = pi2GpioService.GetOutput(controllerOptions.StatusLedNumber.Value);
                _ledTimeout.Start(TimeSpan.FromMilliseconds(1));
            }

            timerService.Tick += Tick;
        }
Esempio n. 38
0
        public HealthService(IBinaryOutput statusLed, IHomeAutomationTimer timer, ISystemInformationService systemInformationService)
        {
            if (timer == null)
            {
                throw new ArgumentNullException(nameof(timer));
            }
            if (systemInformationService == null)
            {
                throw new ArgumentNullException(nameof(systemInformationService));
            }

            _statusLed = statusLed;
            _systemInformationService = systemInformationService;

            if (statusLed != null)
            {
                _ledTimeout.Start(TimeSpan.FromMilliseconds(1));
            }

            timer.Tick += Tick;
        }
Esempio n. 39
0
        public static IArea WithRollerShutter(this IArea area, Enum id, IBinaryOutput powerOutput, IBinaryOutput directionOutput)
        {
            if (area == null)
            {
                throw new ArgumentNullException(nameof(area));
            }

            if (powerOutput == null)
            {
                throw new ArgumentNullException(nameof(powerOutput));
            }
            if (directionOutput == null)
            {
                throw new ArgumentNullException(nameof(directionOutput));
            }

            var rollerShutter = new RollerShutter(ActuatorIdFactory.Create(area, id), powerOutput, directionOutput,
                                                  area.Controller.HttpApiController, area.Controller.Logger, area.Controller.Timer);

            area.AddActuator(rollerShutter);
            return(area);
        }
Esempio n. 40
0
        public HealthMonitor(IBinaryOutput statusLed, IHomeAutomationTimer timer, IApiController apiController)
        {
            if (timer == null)
            {
                throw new ArgumentNullException(nameof(timer));
            }
            if (apiController == null)
            {
                throw new ArgumentNullException(nameof(apiController));
            }

            _statusLed   = statusLed;
            _timer       = timer;
            _startedDate = _timer.CurrentDateTime;

            if (statusLed != null)
            {
                _ledTimeout.Start(TimeSpan.FromMilliseconds(1));
            }

            timer.Tick += Tick;
            apiController.RouteRequest("health", HandleApiGet);
            apiController.RouteCommand("health/reset", c => ResetStatistics());
        }
 public StateMachineState WithLowPort(IBinaryOutput output)
 {
     return WithPort(output, BinaryState.Low);
 }
 public StateMachineState WithHighPort(IBinaryOutput output)
 {
     return WithPort(output, BinaryState.High);
 }
        public StateMachineState WithLowOutput(IBinaryOutput output)
        {
            if (output == null) throw new ArgumentNullException(nameof(output));

            return WithOutput(output, BinaryState.Low);
        }
Esempio n. 44
0
 public Lamp(string id, IBinaryOutput output, IHttpRequestController httpRequestController, INotificationHandler notificationHandler)
     : base(id, output, httpRequestController, notificationHandler)
 {
 }
        public PortBasedBinaryStateEndpoint(IBinaryOutput output)
        {
            if (output == null) throw new ArgumentNullException(nameof(output));

            _output = output;
        }