示例#1
0
        internal static void DoDeviceOperation(this ZWaveDevice device, Action operation)
        {
            Func <int> wrappedOperation = () =>
            {
                operation();
                return(0);
            };

            device.DoDeviceOperation(wrappedOperation);
        }
示例#2
0
        internal static TResult DoDeviceOperation <TResult>(this ZWaveDevice device, Func <TResult> operation)
        {
            var wasConnected = device.IsConnected;
            var network      = (ZWaveNetwork)device.Network;
            var workQueue    = network.WorkQueue;

            var retries = wasConnected == true ? InitiallyConnectedRetries : InitiallyDisconnectedRetries;

            var result = default(TResult);

            var work = new WorkQueueItem(() =>
            {
                result = operation();
            }, retries, typeof(ControlThink.ZWave.ZWaveException));

            workQueue.Add(work);

            var workResult = work.Result;

            if (workResult.Success)
            {
                device.IsConnected = true;

                if (wasConnected != true)
                {
                    var @event = DeviceEvent.Found(device, null);
                    device.AddEvent(@event);
                }

                return(result);
            }

            device.IsConnected = false;

            if (wasConnected == true)
            {
                var @event = DeviceEvent.Lost(device, null);
                device.AddEvent(@event);
            }

            var exception = workResult.Exception;

            if (exception is ControlThink.ZWave.DeviceNotRespondingException)
            {
                throw new DeviceNotRespondingException(device, exception);
            }

            if (exception is ControlThink.ZWave.CommandTimeoutException)
            {
                throw new CommandTimedOutException(device, exception);
            }

            throw new HomeAutomationException("Unexpected Z-Wave error: " + exception.Message, exception);
        }
示例#3
0
        public override Device AddDevice()
        {
            var backingDevice = ZWaveController.AddDevice();
            if (backingDevice == null)
                return null; //TODO: throw exception?

            var device = new ZWaveDevice(this, backingDevice);

            Devices.Add(device);
            return device;
        }
示例#4
0
        public override Device AddDevice()
        {
            var backingDevice = ZWaveController.AddDevice();

            if (backingDevice == null)
            {
                return(null); //TODO: throw exception?
            }
            var device = new ZWaveDevice(this, backingDevice);

            Devices.Add(device);
            return(device);
        }
示例#5
0
        public ZWaveSetpointCollection(ZWaveDevice device)
        {
            _device     = device;
            _thermostat = device.BackingObject as GeneralThermostatV2;

            _setpoints = new Dictionary <ThermostatSetpointType, ITemperature>();

            if (_thermostat == null)
            {
                return;
            }

            SetCallbacks();
        }
示例#6
0
        public ZWaveSetpointCollection(ZWaveDevice device)
        {
            _device = device;
            _thermostat = device.BackingObject as GeneralThermostatV2;

            _setpoints = new Dictionary<ThermostatSetpointType, ITemperature>();

            if (_thermostat == null)
            {
                return;
            }

            SetCallbacks();
        }
示例#7
0
        public ZWaveThermostatFan(ZWaveDevice device)
        {
            _device = device;
            _thermostat = device.BackingObject as GeneralThermostatV2;

            SupportedModes = new List<ThermostatFanMode>();

            if (_thermostat == null)
            {
                return;
            }

            SetCallbacks();
        }
示例#8
0
        public ZWaveThermostatFan(ZWaveDevice device)
        {
            _device     = device;
            _thermostat = device.BackingObject as GeneralThermostatV2;

            SupportedModes = new List <ThermostatFanMode>();

            if (_thermostat == null)
            {
                return;
            }

            SetCallbacks();
        }
示例#9
0
        public ZWaveThermostat(ZWaveDevice device)
        {
            _device = device;
            _thermostat = device.BackingObject as GeneralThermostatV2;

            Core = new ZWaveThermostatCore(device);
            Fan = new ZWaveThermostatFan(device);
            _setpoints = new ZWaveSetpointCollection(device);

            if (_thermostat == null)
            {
                return;
            }

            SetCallbacks();
        }
示例#10
0
        public ZWaveThermostat(ZWaveDevice device)
        {
            _device     = device;
            _thermostat = device.BackingObject as GeneralThermostatV2;

            Core       = new ZWaveThermostatCore(device);
            Fan        = new ZWaveThermostatFan(device);
            _setpoints = new ZWaveSetpointCollection(device);

            if (_thermostat == null)
            {
                return;
            }

            SetCallbacks();
        }
示例#11
0
        public override Device RemoveDevice()
        {
            var    removedDevice = ZWaveController.RemoveDevice();
            Device result;

            if (Devices.Contains(removedDevice))
            {
                result = Devices[removedDevice];
                Devices.Remove(result);
            }
            else
            {
                result = new ZWaveDevice(null, removedDevice);
            }

            return(result);
        }
示例#12
0
        public override Device RemoveDevice()
        {
            var removedDevice = ZWaveController.RemoveDevice();
            Device result;
            if (Devices.Contains(removedDevice))
            {
                result = Devices[removedDevice];
                Devices.Remove(result);
            }
            else
            {
                result = new ZWaveDevice(null, removedDevice);
            }

            return result;
        }
示例#13
0
 public ZWaveToggleSwitch(ZWaveDevice device)
 {
     _device = device;
 }
示例#14
0
 public ZWaveBinarySensor(ZWaveDevice device)
 {
     _device = device;
 }
示例#15
0
 public ZWaveTemperatureSensor(ZWaveDevice device)
 {
     _device = device;
 }
示例#16
0
 public ZWaveDimmerSwitch(ZWaveDevice device)
 {
     _device = device;
 }
示例#17
0
 public ZWaveToggleSwitch(ZWaveDevice device)
 {
     _device = device;
 }
示例#18
0
 public ZWaveBinarySensor(ZWaveDevice device)
 {
     _device = device;
 }
示例#19
0
 public ZWaveDimmerSwitch(ZWaveDevice device)
 {
     _device = device;
 }