Example #1
0
        public override void ApplyState(DeviceBase.DeviceState state)
        {
            base.ApplyState(state);

            CurtainState currentState = (CurtainState)mState;
            CurtainState newState = (CurtainState)state;

            Debug.Assert(newState.Channel == currentState.Channel);

            // FIXME - Disable prediction since we're getting out of sync somehow.
            //if (newState.Action != currentState.Action)
            {
                switch (newState.Action)
                {
                    case Key.Up:
                        Up();
                        break;
                    case Key.Stop:
                        Stop();
                        break;
                    case Key.Down:
                        Down();
                        break;
                }
            }
        }
Example #2
0
        public override void ApplyState(DeviceBase.DeviceState state)
        {
            base.ApplyState(state);

            LampState currentState = (LampState)mState;
            LampState newState = (LampState)state;

            // Make sure we don't try to change these values.
            newState.Dimmable = currentState.Dimmable;
            newState.Group = currentState.Group;

            // Prioritize level changes which would indirectly affect Value changes.
            if (currentState.Dimmable
                && Math.Abs(newState.Level - currentState.Level) > 0.001f)
            {
                DimDevice(newState.Level);
            }
            else if (newState.Value != currentState.Value)
            {
                SwitchDevice(newState.Value);
            }
            else if (ForceSwitching)
            {
                if (newState.Level > 0.0f && newState.Level < 1.0f)
                    DimDevice(newState.Level);
                else
                    SwitchDevice(newState.Value);
            }
        }
Example #3
0
        public override void ApplyState(DeviceBase.DeviceState state)
        {
            base.ApplyState(state);

            NexaLampState currentState = (NexaLampState)mState;
            NexaLampState newState = (NexaLampState)state;

            Debug.Assert(newState.Address == currentState.Address);
            Debug.Assert(newState.Unit == currentState.Unit);
        }
        public List <DeviceBase.DeviceState> OnListDevices()
        {
            var devices = new List <DeviceBase.DeviceState>();

            foreach (var pair in mDeviceManager.Devices)
            {
                DeviceBase deviceBase = pair.Value;
                devices.Add(pair.Value.CopyState());
            }

            return(devices);
        }
        public object OnGetDeviceStatus(string deviceName)
        {
            DeviceBase device = mDeviceManager.GetDevice(deviceName);

            if (device == null)
            {
                throw new ServiceBase.RequestException(string.Format("Unknown device: {0}", deviceName));
            }

            lock (device)
            {
                return(device.CopyState());
            }
        }
Example #6
0
        public override void ApplyState(DeviceBase.DeviceState state)
        {
            lock (mLock)
                base.ApplyState(state);

            var currentState = (YamahaState)mState;
            var newState = (YamahaState)state;

            if (newState.Power != currentState.Power)
                SetPower(newState.Power);

            if (newState.Input != currentState.Input)
                SetInput(newState.Input);

            if (newState.Mute != currentState.Mute)
                Mute(newState.Mute);

            if (newState.Volume != currentState.Volume)
                SetVolume(newState.Volume);
        }
Example #7
0
        public bool DimDevice(DeviceBase device, float level)
        {
            if (!mSerialHelper.IsConnected)
            {
                Log.Warning("Disregarding DimDevice() request for device {0} since we're not connected", device.Name);
                return false;
            }

            level = Math.Min(Math.Max(level, 0.0f), 1.0f);

            lock (mActionQueue)
            {
                // Double send to try avoid failed sends
                mActionQueue.Enqueue(new DeviceAction(device, level));
                mActionQueue.Enqueue(new DeviceAction(device, level));
            }

            // Notify thread that there's stuff to do
            mActionEvent.Set();

            return true;
        }
Example #8
0
 public ProxyDevice(DeviceBase.DeviceState state, DeviceCreationInfo creationInfo)
     : base(state, creationInfo)
 {
 }
Example #9
0
 public void UpdateState(DeviceBase.DeviceState state)
 {
     // Replace internal state with the updated one.
     lock (mLock)
         mState = state;
 }
Example #10
0
 public void AddDevice(DeviceBase device)
 {
     mDevices.Add(device.Name, device);
     //Log.Info("Adding device. Name: {0}, Type: {1}", device.Name, device.GetType().Name);
 }
Example #11
0
        public object OnUpdateDeviceStatus(string deviceName, dynamic body)
        {
            DeviceBase device = mDeviceManager.GetDevice(deviceName);

            if (device == null)
            {
                throw new ServiceBase.RequestException(string.Format("Unknown device: {0}", deviceName));
            }

            DeviceBase.DeviceState state = device.CopyState();
            foreach (var property in state.GetType().GetProperties())
            {
                if (!body.ContainsKey(property.Name))
                {
                    continue;
                }

                // Make sure we can actually set the value to begin with.
                if (property.SetMethod == null)
                {
                    continue;
                }

                Type type  = property.PropertyType;
                var  value = body[property.Name];

                if (type == typeof(System.Int32))
                {
                    property.SetValue(state, Int32.Parse((string)value));
                }
                else if (type == typeof(string))
                {
                    property.SetValue(state, (string)value);
                }
                else if (type == typeof(bool))
                {
                    property.SetValue(state, bool.Parse((string)value));
                }
                else if (type == typeof(float))
                {
                    property.SetValue(state, float.Parse((string)value));
                }
                else if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(List <>))
                {
                    // TODO - Add proper support for lists.
                }
                else if (type.IsEnum)
                {
                    var intValue = Int32.Parse((string)value);
                    property.SetValue(state, Enum.ToObject(type, intValue));
                }
                else
                {
                    throw new ArgumentException("Unhandled type: " + type.Name);
                }
            }

            lock (device)
            {
                device.ApplyState(state);

                return(device.CopyState());
            }
        }
Example #12
0
        public override void ApplyState(DeviceBase.DeviceState state)
        {
            base.ApplyState(state);

            EpsonState currentState = (EpsonState)mState;
            EpsonState newState = (EpsonState)state;

            if (newState.Power != currentState.Power)
            {
                if (newState.Power)
                    PowerOn();
                else
                    PowerOff();
            }
            else if (newState.Source != currentState.Source)
            {
                Source = newState.Source;
            }
        }
Example #13
0
 public void AddDevice(DeviceBase device)
 {
     mDevices.Add(device.Name, device);
     //Log.Info("Adding device. Name: {0}, Type: {1}", device.Name, device.GetType().Name);
 }
Example #14
0
 public DeviceAction(DeviceBase device, float level)
 {
     Device = device;
     Level = level;
     Value = level > 0.0f;
 }
Example #15
0
 public DeviceAction(DeviceBase device, bool value)
 {
     Device = device;
     Value = value;
     Level = value ? 1.0f : 0.0f;
 }
Example #16
0
        public bool SwitchDevice(DeviceBase device, bool value)
        {
            if (!mSerialHelper.IsConnected)
            {
                Log.Warning("Disregarding SwitchDevice() request for device {0} since we're not connected", device.Name);
                return false;
            }

            lock (mActionQueue)
            {
                // Double send to try avoid failed sends
                mActionQueue.Enqueue(new DeviceAction(device, value));
                mActionQueue.Enqueue(new DeviceAction(device, value));
            }

            // Notify thread that there's stuff to do
            mActionEvent.Set();

            return true;
        }