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

            device.DoDeviceOperation(wrappedOperation);
        }
Example #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);
        }
Example #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;
        }
Example #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);
        }
Example #5
0
        public ZWaveSetpointCollection(ZWaveDevice device)
        {
            _device     = device;
            _thermostat = device.BackingObject as GeneralThermostatV2;

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

            if (_thermostat == null)
            {
                return;
            }

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

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

            if (_thermostat == null)
            {
                return;
            }

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

            SupportedModes = new List<ThermostatFanMode>();

            if (_thermostat == null)
            {
                return;
            }

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

            SupportedModes = new List <ThermostatFanMode>();

            if (_thermostat == null)
            {
                return;
            }

            SetCallbacks();
        }
Example #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();
        }
Example #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();
        }
Example #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);
        }
Example #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;
        }
Example #13
0
 public ZWaveToggleSwitch(ZWaveDevice device)
 {
     _device = device;
 }
Example #14
0
 public ZWaveBinarySensor(ZWaveDevice device)
 {
     _device = device;
 }
Example #15
0
 public ZWaveTemperatureSensor(ZWaveDevice device)
 {
     _device = device;
 }
Example #16
0
 public ZWaveDimmerSwitch(ZWaveDevice device)
 {
     _device = device;
 }
Example #17
0
 public ZWaveToggleSwitch(ZWaveDevice device)
 {
     _device = device;
 }
Example #18
0
 public ZWaveBinarySensor(ZWaveDevice device)
 {
     _device = device;
 }
Example #19
0
 public ZWaveDimmerSwitch(ZWaveDevice device)
 {
     _device = device;
 }