Exemple #1
0
        public static DeviceBase CreateDevice(DeviceCreationInfo info)
        {
            string type;

            try
            {
                type = info.Configuration.type;
            }
            catch (RuntimeBinderException)
            {
                throw new ArgumentException("Missing type of device");
            }

            Type deviceType = Type.GetType(type);

            if (deviceType == null)
            {
                throw new ArgumentException("Invalid device type name " + type);
            }

            if (!deviceType.IsSubclassOf(typeof(DeviceBase)))
            {
                throw new ArgumentException("Type is not a subclass of DeviceBase. Type: " + deviceType.Name);
            }

            Object[] arguments = new Object[] { info };

            return((DeviceBase)Activator.CreateInstance(deviceType, arguments));
        }
Exemple #2
0
        protected LampDeviceBase(LampState state, DeviceCreationInfo creationInfo)
            : base(state, creationInfo)
        {
            ForceSwitching = false;

            mVoiceName = creationInfo.Configuration.voiceName;
        }
Exemple #3
0
        public NexaLampDevice(DeviceCreationInfo creationInfo)
            : base(new NexaLampState(), creationInfo)
        {
            // Enable forced switching since we don't have a closed loop and prediction is causing state changes to be
            // disregarded since LampDeviceBase thinks it's already in that state.
            ForceSwitching = true;

            mService = (RfxComService)creationInfo.ServiceManager.GetService(typeof(RfxComService));
            if (mService == null)
            {
                throw new InvalidOperationException("RfxComService is missing, device cannot run");
            }

            ((NexaLampState)mState).Address = int.Parse(creationInfo.Configuration.code);
            ((NexaLampState)mState).Unit    = int.Parse(creationInfo.Configuration.unit);

            try
            {
                ((NexaLampState)mState).Group = bool.Parse(creationInfo.Configuration.group);
            }
            catch (RuntimeBinderException) { }

            try
            {
                ((NexaLampState)mState).Dimmable = bool.Parse(creationInfo.Configuration.dimmable);
            }
            catch (RuntimeBinderException) { }
        }
Exemple #4
0
        private void CreateDevices(List <dynamic> configs)
        {
            foreach (var deviceConfig in configs)
            {
                DeviceBase device;
                try
                {
                    DeviceCreationInfo info = new DeviceCreationInfo(deviceConfig, mServiceManager, mDeviceManager);
                    device = DeviceFactory.CreateDevice(info);
                    mDeviceManager.AddDevice(device);
                }
                catch (Exception e)
                {
                    Log.Error("Failed creating device for node with config: " + deviceConfig.name);
                    if (e.InnerException != null)
                    {
                        Log.Error("Inner Exception: {0}\nCallstack:\n{1}", e.InnerException.Message, e.InnerException.StackTrace);
                    }
                    else
                    {
                        Log.Error("Exception: {0}\nCallstack:\n{1}", e.Message, e.StackTrace);
                    }

                    continue;
                }

                Log.Info("Created device: {0} of type: {1}", device.Name, device.GetType().ToString());
            }
        }
        public ComputerProxyDevice(DeviceCreationInfo creationInfo)
            : base(new ComputerState(), creationInfo)
        {
            State.Address    = creationInfo.Configuration.address;
            State.MacAddress = creationInfo.Configuration.macaddress;

            mWakeService = (WakeOnLanService)creationInfo.ServiceManager.GetService(typeof(WakeOnLanService));
        }
Exemple #6
0
        public EpsonDevice(DeviceCreationInfo creationInfo)
            : base(new EpsonState(), creationInfo)
        {
            int port = int.Parse(creationInfo.Configuration.port);

            mSerialHelper = new SerialHelper("epson", (uint)port, 9600);
            mSerialHelper.AddListener(this);
        }
Exemple #7
0
        public DeviceBase CreateDevice(dynamic deviceConfiguration)
        {
            var info   = new DeviceCreationInfo(deviceConfiguration, ServiceManager, DeviceManager);
            var device = DeviceFactory.CreateDevice(info);

            DeviceManager.AddDevice(device);

            return(device);
        }
Exemple #8
0
        public LampDevice(DeviceCreationInfo creationInfo)
            : base(new LampState(), creationInfo)
        {
            mService = (LampServiceBase)creationInfo.ServiceManager.GetService(typeof(LampServiceBase));
            if (mService == null)
            {
                throw new InvalidOperationException("LampService is missing, device cannot run");
            }

            State.Dimmable = true;
            State.Channel  = int.Parse(creationInfo.Configuration.channel);
        }
Exemple #9
0
        public EverflourishDevice(DeviceCreationInfo creationInfo)
            : base(new EverflourishState(), creationInfo)
        {
            mService = (RfxComService)creationInfo.ServiceManager.GetService(typeof(RfxComService));
            ((EverflourishState)mState).Address = int.Parse(creationInfo.Configuration.code);
            ((EverflourishState)mState).Unit    = int.Parse(creationInfo.Configuration.unit);

            try
            {
                ((EverflourishState)mState).Group = bool.Parse(creationInfo.Configuration.group);
            }
            catch (RuntimeBinderException) { }
        }
Exemple #10
0
        public BluetoothDevice(DeviceCreationInfo creationInfo)
            : base(new BluetoothState(), creationInfo)
        {
            BluetoothState state = (BluetoothState)mState;

            state.BtName = creationInfo.Configuration.btname;

            mService = (BluetoothService)creationInfo.ServiceManager.GetService(typeof(BluetoothService));
            if (mService != null)
            {
                mService.AddDevice(this);
            }
        }
Exemple #11
0
        public CurtainDevice(DeviceCreationInfo creationInfo)
            : base(new CurtainState(), creationInfo)
        {
            mService = (CurtainService)creationInfo.ServiceManager.GetService(typeof(CurtainService));

            CurtainState state = (CurtainState)mState;

            state.Channel = int.Parse(creationInfo.Configuration.channel);

            mVoiceName = creationInfo.Configuration.voiceName;

/*
 *          // TOTO - Look into this in detail.
 *          // Somehow we're getting garbage in the first submission with MS serial implementation.
 *          // No issues in the previous python implementation, but required beefing up error handling on the arduino side as well
 *          // as adding an extra flush from the c# side.
 *          byte[] dummy = new byte[] { (byte)'\n' };
 *          mService.SendData(dummy);
 */
        }
Exemple #12
0
        public YamahaDevice(DeviceCreationInfo creationInfo)
            : base(new YamahaState(), creationInfo)
        {
            mConfiguration = creationInfo.Configuration;

            mService = (YamahaService)creationInfo.ServiceManager.GetService(typeof(YamahaService));
            mLock    = new object();

            YamahaState state = (YamahaState)mState;

            state.Address = creationInfo.Configuration.address;

            // Set up inputs
            foreach (var inputConfig in mConfiguration.inputs)
            {
                state.Inputs.Add(new InputInfo(inputConfig.input, inputConfig.displayName, inputConfig.voiceName));
            }


            // Note. Service will trigger a refresh of the device state, however, for a little while until the receiver responds, this device will have a potentially incorrect default state.
            mService.AddDevice(this);
        }
Exemple #13
0
 public SensorDeviceBase(SensorState state, DeviceCreationInfo creationInfo)
     : base(state, creationInfo)
 {
 }
Exemple #14
0
 public TestDevice(DeviceCreationInfo info)
     : base(new DeviceState(), info)
 {
     mState.Archetype = "ProperArchetype";
 }
Exemple #15
0
 public NexaSensorDevice(DeviceCreationInfo creationInfo)
     : base(new NexaSensorState(), creationInfo)
 {
     ((NexaSensorState)mState).Address = int.Parse(creationInfo.Configuration.code);
     ((NexaSensorState)mState).Unit    = int.Parse(creationInfo.Configuration.unit);
 }
Exemple #16
0
 public DummyDevice(DeviceCreationInfo creationInfo)
     : base(new DummyState(), creationInfo)
 {
 }
 protected CurtainDeviceBase(CurtainState state, DeviceCreationInfo creationInfo)
     : base(state, creationInfo)
 {
 }