예제 #1
0
        private static void Main(string[] args)
        {
            var room1 = Guid.NewGuid();
            var room2 = Guid.NewGuid();
            var lamp1 = new LampDevice(room1);
            var lamp2 = new LampDevice(room2);
            var lamp3 = new LampDevice(room2);

            var deviceManager = new DeviceManager.DeviceManager();

            deviceManager.AddObserver(lamp1);
            deviceManager.AddObserver(lamp2);
            deviceManager.AddObserver(lamp3);

            deviceManager.NotifyObservers(new AlertStateMessage(room1));

            Console.WriteLine($"Send alert message to the first room: {room1}");
            Console.WriteLine($"Room: {lamp1.RoomId}\n" +
                              $"Is Lamp1`s mode is auto: {lamp1.IsAuto}\n" +
                              $"Is lamp1 is calm: {lamp1.IsStateCalm}\n" +
                              $"Is lamp1 turned on: {lamp1.IsTurnedOn}\n");
            Console.WriteLine($"Room: {lamp2.RoomId}\n" +
                              $"Is Lamp2`s mode is auto: {lamp2.IsAuto}\n" +
                              $"Is lamp2 is calm: {lamp2.IsStateCalm}\n" +
                              $"Is lamp2 turned on: {lamp2.IsTurnedOn}\n");
            Console.WriteLine($"Room: {lamp3.RoomId}\n" +
                              $"Is Lamp3`s mode is auto: {lamp3.IsAuto}\n" +
                              $"Is lamp3 is calm: {lamp3.IsStateCalm}\n" +
                              $"Is lamp3 turned on: {lamp3.IsTurnedOn}\n");
        }
예제 #2
0
파일: Logic.cs 프로젝트: radtek/Automation
        public Logic(DeviceManager deviceManager, ServiceManager serviceManager)
        {
            mDeviceManager  = deviceManager;
            mServiceManager = serviceManager;

            mWake = GetService <WakeOnLanService>();

            mMode = GetService <ModeService>();

            if (mMode != null)
            {
                mMode.OnModeChange += OnModeChange;
            }

            mScene = GetService <SceneService>();
            if (mScene != null)
            {
                mScene.OnSceneEvent += OnSceneEvent;
            }

            mEvents = GetService <EventService>();
            if (mEvents != null)
            {
                mEvents.OnEvent += OnExternalEvent;
            }

            // Livingroom
            mCurtainLivingroom = (CurtainDevice)deviceManager.GetDevice("curtain_livingroom");
            mProjector         = (EpsonDevice)deviceManager.GetDevice("projector");
            mReceiver          = (YamahaDevice)deviceManager.GetDevice("receiver");
            mLampLivingroom    = (NexaLampDevice)deviceManager.GetDevice("lamp_livingroom");
            mLampTable         = (NexaLampDevice)deviceManager.GetDevice("lamp_table");
            mLampWindow        = (NexaLampDevice)deviceManager.GetDevice("lamp_window");
            mLampDarthLeft     = (ArduinoLamps.LampDevice)deviceManager.GetDevice("lamp_darth_left");
            mLampDarthRight    = (ArduinoLamps.LampDevice)deviceManager.GetDevice("lamp_darth_right");
            mMotionLivingroom  = (NexaSensorDevice)deviceManager.GetDevice("motion_livingroom");

            mSwitchSofa1 = (NexaSensorDevice)deviceManager.GetDevice("switch_sofa1");
            mSwitchSofa2 = (NexaSensorDevice)deviceManager.GetDevice("switch_sofa2");
            if (mSwitchSofa1 != null)
            {
                mSwitchSofa1.OnDeviceEvent += OnSofaSwitchEvent;
            }
            if (mSwitchSofa2 != null)
            {
                mSwitchSofa2.OnDeviceEvent += OnSofaSwitchEvent;
            }

            mDesktop = (ComputerProxyDevice)deviceManager.GetDevice("desktop");

            // Bedroom
            mCurtainBedroom = (CurtainDevice)deviceManager.GetDevice("curtain_bedroom");
            mLampBedroom    = (NexaLampDevice)deviceManager.GetDevice("lamp_bedroom");
            mLampBed        = (NexaLampDevice)deviceManager.GetDevice("lamp_bed");

            // Hallway
            mLampHallway = (NexaLampDevice)deviceManager.GetDevice("lamp_hallway");
            mMotionDoor  = (NexaSensorDevice)deviceManager.GetDevice("motion_door");
            if (mMotionDoor != null)
            {
                mMotionDoor.OnDeviceEvent += OnDoorSensor;
            }

            mSwitchHallway = (NexaSensorDevice)deviceManager.GetDevice("switch_hallway");
            if (mSwitchHallway != null)
            {
                mSwitchHallway.OnDeviceEvent += OnHallwaySwitch;
            }

            // Presence devices
            mGalaxyS7 = (BluetoothDevice)deviceManager.GetDevice("presence_s7");
            if (mGalaxyS7 != null)
            {
                mGalaxyS7.OnDeviceEvent += OnBluetoothEvent;
            }

            mSpeech = GetService <SpeechService>();
            if (mSpeech != null)
            {
                var commands = new List <DeviceBase.VoiceCommand>();
                commands.Add(new DeviceBase.VoiceCommand("activate night mode", () => { MacroNight(); }));

                mSpeech.LoadCommands(commands);
            }

            Speak("System ready");
        }
예제 #3
0
 public override void SetLevel(LampDevice lampDevice, float level)
 {
     SetLevelCalled = true;
     Level          = level;
 }