Ejemplo n.º 1
0
        private void unsubscribeArea(IArea area)
        {
            var areaComp = area.GetComponent <IAreaComponent>();

            if (areaComp != null)
            {
                areaComp.PropertyChanged -= _onAreaPropertyChangedCallback;
            }
            var scale = area.GetComponent <IScalingArea>();

            if (scale != null)
            {
                scale.PropertyChanged -= _onScalingAreaChangedCallback;
            }
            var restriction = area.GetComponent <IAreaRestriction>();

            if (restriction != null)
            {
                restriction.PropertyChanged -= _onAreaRestrictionChangedCallback;
                restriction.RestrictionList.OnListChanged.Unsubscribe(_onAreaRestrictionListChangedCallback);
            }
            _areaBindings.TryGetValue(area.ID, out var bindings);
            if (bindings == null)
            {
                return;
            }
            foreach (var binding in bindings)
            {
                binding.Unbind();
            }
        }
Ejemplo n.º 2
0
 private void SetupStairwayLamps(IArea room)
 {
     _automationFactory.RegisterTurnOnAndOffAutomation(room, Floor.CombinedStairwayLampAutomation)
     .WithTrigger(room.GetMotionDetector(Floor.StairwayMotionDetector))
     .WithTrigger(room.GetButton(Floor.ButtonStairway).PressedShortTrigger)
     .WithTarget(room.GetComponent(Floor.CombinedStairwayLamp))
     .WithEnabledAtNight();
 }
Ejemplo n.º 3
0
        public static IMotionDetector GetMotionDetector(this IArea area, Enum id)
        {
            if (area == null)
            {
                throw new ArgumentNullException(nameof(area));
            }

            return(area.GetComponent <IMotionDetector>($"{area.Id}.{id}"));
        }
Ejemplo n.º 4
0
        public static IStateMachine GetStateMachine(this IArea area, Enum id)
        {
            if (area == null)
            {
                throw new ArgumentNullException(nameof(area));
            }

            return(area.GetComponent <IStateMachine>(ComponentIdFactory.Create(area.Id, id)));
        }
Ejemplo n.º 5
0
        public static IRollerShutter GetRollerShutter(this IArea area, Enum id)
        {
            if (area == null)
            {
                throw new ArgumentNullException(nameof(area));
            }

            return(area.GetComponent <RollerShutter>(ComponentIdFactory.Create(area.Id, id)));
        }
Ejemplo n.º 6
0
        public static ITemperatureSensor GetTemperatureSensor(this IArea area, Enum id)
        {
            if (area == null)
            {
                throw new ArgumentNullException(nameof(area));
            }

            return(area.GetComponent <ITemperatureSensor>(ComponentIdGenerator.Generate(area.Id, id)));
        }
Ejemplo n.º 7
0
        public static ITemperatureSensor GetTemperatureSensor(this IArea area, Enum id)
        {
            if (area == null)
            {
                throw new ArgumentNullException(nameof(area));
            }

            return(area.GetComponent <ITemperatureSensor>($"{area.Id}.{id}"));
        }
Ejemplo n.º 8
0
        public static BinaryStateActuator GetBinaryStateActuator(this IArea area, Enum id)
        {
            if (area == null)
            {
                throw new ArgumentNullException(nameof(area));
            }

            return(area.GetComponent <BinaryStateActuator>(ComponentIdGenerator.Generate(area.Id, id)));
        }
        public static IActuator GetActuator(this IArea area, Enum id)
        {
            if (area == null)
            {
                throw new ArgumentNullException(nameof(area));
            }

            return(area.GetComponent <IActuator>(ComponentIdFactory.Create(area.Id, id)));
        }
Ejemplo n.º 10
0
        public static Window GetWindow(this IArea area, Enum id)
        {
            if (area == null)
            {
                throw new ArgumentNullException(nameof(area));
            }

            return(area.GetComponent <Window>($"{area.Id}.{id}"));
        }
Ejemplo n.º 11
0
        public static IButton GetButton(this IArea area, Enum id)
        {
            if (area == null)
            {
                throw new ArgumentNullException(nameof(area));
            }

            return(area.GetComponent <IButton>($"{area.Id}.{id}"));
        }
Ejemplo n.º 12
0
        public static IRollerShutter GetRollerShutter(this IArea area, Enum id)
        {
            if (area == null)
            {
                throw new ArgumentNullException(nameof(area));
            }

            return(area.GetComponent <RollerShutter>($"{area.Id}.{id}"));
        }
Ejemplo n.º 13
0
        public static IComponent GetComponent(this IArea area, Enum id)
        {
            if (area == null)
            {
                throw new ArgumentNullException(nameof(area));
            }

            return(area.GetComponent(area.Id + "." + id));
        }
Ejemplo n.º 14
0
        public static ILamp GetLamp(this IArea area, Enum id)
        {
            if (area == null)
            {
                throw new ArgumentNullException(nameof(area));
            }

            return(area.GetComponent <ILamp>(ComponentIdGenerator.Generate(area.Id, id)));
        }
Ejemplo n.º 15
0
        public static IStateMachine GetStateMachine(this IArea area, Enum id)
        {
            if (area == null)
            {
                throw new ArgumentNullException(nameof(area));
            }

            return(area.GetComponent <IStateMachine>($"{area.Id}.{id}"));
        }
Ejemplo n.º 16
0
        private void OnMessageReceived(object sender, DeviceMessageReceivedEventArgs e)
        {
            try
            {
                IComponent component = null;
                if (e.Message.Topic == "garden_controller/$PATCH/socket.pavillion")
                {
                    component = _area.GetComponent(Garden.SocketPavillion);
                }
                else if (e.Message.Topic == "garden_controller/$PATCH/lamp.rear_area")
                {
                    component = _area.GetComponent(Garden.LampRearArea);
                }
                else if (e.Message.Topic == "garden_controller/$PATCH/lamp.roof")
                {
                    component = _area.GetComponent(Garden.SpotlightRoof);
                }
                else if (e.Message.Topic == "garden_controller/$PATCH/lamp.tap")
                {
                    component = _area.GetComponent(Garden.LampTap);
                }
                else if (e.Message.Topic == "garden_controller/$PATCH/lamp.garage")
                {
                    component = _area.GetComponent(Garden.LampGarage);
                }
                else if (e.Message.Topic == "garden_controller/$PATCH/lamp.terrace")
                {
                    component = _area.GetComponent(Garden.LampTerrace);
                }
                else if (e.Message.Topic == "garden_controller/$PATCH/lamp.parking_lot")
                {
                    component = _area.GetComponent(Garden.LampParkingLot);
                }

                if (component == null)
                {
                    return;
                }

                var status = Encoding.UTF8.GetString(e.Message.Payload ?? new byte[0]);

                ICommand command = new TurnOffCommand();

                if (status == "on")
                {
                    command = new TurnOnCommand();
                }
                else if (status == "toggle")
                {
                    command = new TogglePowerStateCommand();
                }

                component.ExecuteCommand(command);
            }
            catch (Exception exception)
            {
                Log.Default.Error(exception, "Errow while patching state.");
            }
        }
Ejemplo n.º 17
0
        public IObject GetDrawable(IArea area, IBitmap bg)
		{
            IWalkBehindArea walkBehind = area.GetComponent<IWalkBehindArea>();
            if (walkBehind == null) return null;
			AreaKey key = new AreaKey (area, bg);
			IObject obj = _objects.GetOrAdd(key, () => createObject());
			obj.Z = walkBehind.Baseline == null ? area.Mask.MinY : walkBehind.Baseline.Value;
			obj.Image = _images.GetOrAdd(key, () => createImage(area, bg));
			return obj;
		}
Ejemplo n.º 18
0
        public IObject GetDrawable(IArea area, IBitmap bg)
        {
            IWalkBehindArea walkBehind = area.GetComponent <IWalkBehindArea>();

            if (walkBehind == null)
            {
                return(null);
            }
            AreaKey key = new AreaKey(area, bg);
            IObject obj = _objects.GetOrAdd(key, () => createObject(area.ID));

            obj.Z     = walkBehind.Baseline == null ? area.Mask.MinY : walkBehind.Baseline.Value;
            obj.Image = _images.GetOrAdd(key, () => createImage(area, bg));
            return(obj);
        }
Ejemplo n.º 19
0
        public static void AllowEntity(this IArea a, IEntity e)
        {
            var res = a.GetComponent <IAreaRestriction>();

            if (res == null)
            {
                return;
            }
            if (res.RestrictionType == RestrictionListType.BlackList)
            {
                res.RestrictionList.Remove(e.ID);
            }
            else
            {
                res.RestrictionList.Add(e.ID);
            }
        }
Ejemplo n.º 20
0
        private void InitializeStateMachine(StateMachine stateMachine, IArea garden)
        {
            var turnOffCommand = new TurnOffCommand();
            var turnOnCommand  = new TurnOnCommand();

            stateMachine.ResetStateId = StateMachineStateExtensions.OffStateId;

            stateMachine.AddOffState()
            .WithCommand(garden.GetComponent(Garden.LampTerrace), turnOffCommand)
            .WithCommand(garden.GetLamp(Garden.LampTerrace), turnOffCommand)
            .WithCommand(garden.GetLamp(Garden.LampGarage), turnOffCommand)
            .WithCommand(garden.GetLamp(Garden.LampTap), turnOffCommand)
            .WithCommand(garden.GetLamp(Garden.SpotlightRoof), turnOffCommand)
            .WithCommand(garden.GetLamp(Garden.LampRearArea), turnOffCommand);

            stateMachine.AddState("Te")
            .WithCommand(garden.GetLamp(Garden.LampTerrace), turnOnCommand)
            .WithCommand(garden.GetLamp(Garden.LampGarage), turnOffCommand)
            .WithCommand(garden.GetLamp(Garden.LampTap), turnOffCommand)
            .WithCommand(garden.GetLamp(Garden.SpotlightRoof), turnOffCommand)
            .WithCommand(garden.GetLamp(Garden.LampRearArea), turnOffCommand);

            stateMachine.AddState("G")
            .WithCommand(garden.GetLamp(Garden.LampTerrace), turnOffCommand)
            .WithCommand(garden.GetLamp(Garden.LampGarage), turnOnCommand)
            .WithCommand(garden.GetLamp(Garden.LampTap), turnOffCommand)
            .WithCommand(garden.GetLamp(Garden.SpotlightRoof), turnOffCommand)
            .WithCommand(garden.GetLamp(Garden.LampRearArea), turnOffCommand);

            stateMachine.AddState("W")
            .WithCommand(garden.GetLamp(Garden.LampTerrace), turnOffCommand)
            .WithCommand(garden.GetLamp(Garden.LampGarage), turnOffCommand)
            .WithCommand(garden.GetLamp(Garden.LampTap), turnOnCommand)
            .WithCommand(garden.GetLamp(Garden.SpotlightRoof), turnOffCommand)
            .WithCommand(garden.GetLamp(Garden.LampRearArea), turnOffCommand);

            stateMachine.AddState("D")
            .WithCommand(garden.GetLamp(Garden.LampTerrace), turnOffCommand)
            .WithCommand(garden.GetLamp(Garden.LampGarage), turnOffCommand)
            .WithCommand(garden.GetLamp(Garden.LampTap), turnOffCommand)
            .WithCommand(garden.GetLamp(Garden.SpotlightRoof), turnOnCommand)
            .WithCommand(garden.GetLamp(Garden.LampRearArea), turnOffCommand);

            stateMachine.AddState("Ti")
            .WithCommand(garden.GetLamp(Garden.LampTerrace), turnOffCommand)
            .WithCommand(garden.GetLamp(Garden.LampGarage), turnOffCommand)
            .WithCommand(garden.GetLamp(Garden.LampTap), turnOffCommand)
            .WithCommand(garden.GetLamp(Garden.SpotlightRoof), turnOffCommand)
            .WithCommand(garden.GetLamp(Garden.LampRearArea), turnOnCommand);

            stateMachine.AddState("G+W")
            .WithCommand(garden.GetLamp(Garden.LampTerrace), turnOffCommand)
            .WithCommand(garden.GetLamp(Garden.LampGarage), turnOnCommand)
            .WithCommand(garden.GetLamp(Garden.LampTap), turnOnCommand)
            .WithCommand(garden.GetLamp(Garden.SpotlightRoof), turnOffCommand)
            .WithCommand(garden.GetLamp(Garden.LampRearArea), turnOffCommand);

            stateMachine.AddState("Te+G+W")
            .WithCommand(garden.GetLamp(Garden.LampTerrace), turnOnCommand)
            .WithCommand(garden.GetLamp(Garden.LampGarage), turnOnCommand)
            .WithCommand(garden.GetLamp(Garden.LampTap), turnOnCommand)
            .WithCommand(garden.GetLamp(Garden.SpotlightRoof), turnOffCommand)
            .WithCommand(garden.GetLamp(Garden.LampRearArea), turnOffCommand);

            stateMachine.AddOnState()
            .WithCommand(garden.GetLamp(Garden.LampTerrace), turnOnCommand)
            .WithCommand(garden.GetLamp(Garden.LampGarage), turnOnCommand)
            .WithCommand(garden.GetLamp(Garden.LampTap), turnOnCommand)
            .WithCommand(garden.GetLamp(Garden.SpotlightRoof), turnOnCommand)
            .WithCommand(garden.GetLamp(Garden.LampRearArea), turnOnCommand);
        }