public ControllerCommandDlg(ZWManager _manager, UInt32 homeId, ZWControllerCommand _op, Byte nodeId)
        {
            m_manager = _manager;
            _homeid = homeId;
            _zwcontrollercommand = _op;
            _nodeid = nodeId;
            _controllercommanddlg = this;

            InitializeComponent();

            switch (_zwcontrollercommand)
            {
                case ZWControllerCommand.AddController:
                    {
                        this.Text =  " - Add Controller";
                        this.label1.Text = "Put the target controller into receive configuration mode.\nThe PC Z-Wave Controller must be within 2m of the controller being added.";
                        break;
                    }
                case ZWControllerCommand.AddDevice:
                    {
                        this.Text = " - Add Device";
                        this.label1.Text = "Press the program button on the Z-Wave device to add it to the network.\nFor security reasons, the PC Z-Wave Controller must be close to the device being added.";
                        break;
                    }
                case ZWControllerCommand.CreateNewPrimary:
                    {
                        this.Text =  " - Create New Primary Controller";
                        this.label1.Text = "Put the target controller into receive configuration mode.\nThe PC Z-Wave Controller must be within 2m of the controller that is being made the primary.";
                        break;
                    }
                case ZWControllerCommand.ReceiveConfiguration:
                    {
                        this.Text =  " - Receive Configuration";
                        this.label1.Text = "Transfering the network configuration\nfrom another controller.\n\nPlease bring the other controller within 2m of the PC controller and set it to send its network configuration.";
                        break;
                    }
                case ZWControllerCommand.RemoveController:
                    {
                        this.Text = " - RemoveController";
                        this.label1.Text = "Put the target controller into receive configuration mode.\nThe PC Z-Wave Controller must be within 2m of the controller being added.";
                        break;
                    }
                case ZWControllerCommand.RemoveDevice:
                    {
                        this.Text =  " - Remove Device";
                        this.label1.Text = "Press the program button on the Z-Wave device to remove it from the network.\nFor security reasons, the PC Z-Wave Controller must be close to the device being removed.";
                        break;
                    }
                case ZWControllerCommand.TransferPrimaryRole:
                    {
                        this.Text =  " - Transfer Primary Role";
                        this.label1.Text = "Transfering the primary role\nto another controller.\n\nPlease bring the new controller within 2m of the PC controller and set it to receive the network configuration.";
                        break;
                    }
                case ZWControllerCommand.HasNodeFailed:
                    {
                        this.ButtonCancel.Enabled = false;
                        this.Text = " - Has Node Failed";
                        this.label1.Text = "Testing whether the node has failed.\nThis command cannot be cancelled.";
                        break;
                    }
                case ZWControllerCommand.RemoveFailedNode:
                    {
                        this.ButtonCancel.Enabled = false;
                        this.Text = " - Remove Failed Node";
                        this.label1.Text = "Removing the failed node from the controller's list.\nThis command cannot be cancelled.";
                        break;
                    }
                case ZWControllerCommand.ReplaceFailedNode:
                    {
                        this.ButtonCancel.Enabled = false;
                        this.Text = " - Replacing Failed Node";
                        this.label1.Text = "Testing the failed node.\nThis command cannot be cancelled.";
                        break;
                    }
            }

            m_manager.OnControllerStateChanged += m_controllerStateChangedHandler;
            if (!m_manager.BeginControllerCommand(_homeid, _zwcontrollercommand, false, _nodeid))
            {
                m_manager.OnControllerStateChanged -= m_controllerStateChangedHandler;
            }
        }
Exemplo n.º 2
0
        public override bool ProcessDeviceTypeCommand(device_type_command_que cmd)
        {
            if(cmd.device.device_types.name == "CONTROLLER")
            {
                switch (cmd.device_type_commands.name)
                {
                    case "RESET":
                        {
                            m_manager.ResetController(m_homeId);
                            return true;
                        }
                    case "ADDDEVICE":
                        {
                            ControllerCommandDlg dlg = new ControllerCommandDlg(m_manager, m_homeId, ZWControllerCommand.AddDevice, (byte)cmd.device.node_id);
                            dlg.ShowDialog();
                            dlg.Dispose();
                            return true;
                        }
                    case "AddController":
                        {
                            ControllerCommandDlg dlg = new ControllerCommandDlg(m_manager, m_homeId, ZWControllerCommand.AddController, (byte)cmd.device.node_id);
                            dlg.ShowDialog();
                            dlg.Dispose();
                            return true;
                        }
                    case "CreateNewPrimary":
                        {
                            ControllerCommandDlg dlg = new ControllerCommandDlg(m_manager, m_homeId, ZWControllerCommand.CreateNewPrimary, (byte)cmd.device.node_id);
                            dlg.ShowDialog();
                            dlg.Dispose();
                            return true;
                        }
                    case "ReceiveConfiguration":
                        {
                            ControllerCommandDlg dlg = new ControllerCommandDlg(m_manager, m_homeId, ZWControllerCommand.ReceiveConfiguration, (byte)cmd.device.node_id);
                            dlg.ShowDialog();
                            dlg.Dispose();
                            return true;
                        }
                    case "RemoveController":
                        {
                            ControllerCommandDlg dlg = new ControllerCommandDlg(m_manager, m_homeId, ZWControllerCommand.RemoveController, (byte)cmd.device.node_id);
                            dlg.ShowDialog();
                            dlg.Dispose();
                            return true;
                        }
                    case "RemoveDevice":
                        {
                            ControllerCommandDlg dlg = new ControllerCommandDlg(m_manager, m_homeId, ZWControllerCommand.RemoveDevice, (byte)cmd.device.node_id);
                            dlg.ShowDialog();
                            dlg.Dispose();
                            return true;
                        }
                    case "TransferPrimaryRole":
                        {
                            ControllerCommandDlg dlg = new ControllerCommandDlg(m_manager, m_homeId, ZWControllerCommand.TransferPrimaryRole, (byte)cmd.device.node_id);
                            dlg.ShowDialog();
                            dlg.Dispose();
                            return true;
                        }
                    case "HasNodeFailed":
                        {
                            ControllerCommandDlg dlg = new ControllerCommandDlg(m_manager, m_homeId, ZWControllerCommand.HasNodeFailed, (byte)cmd.device.node_id);
                            dlg.ShowDialog();
                            dlg.Dispose();
                            return true;
                        }
                    case "RemoveFailedNode":
                        {
                            ControllerCommandDlg dlg = new ControllerCommandDlg(m_manager, m_homeId, ZWControllerCommand.RemoveFailedNode, (byte)cmd.device.node_id);
                            dlg.ShowDialog();
                            dlg.Dispose();
                            return true;
                        }
                    case "ReplaceFailedNode":
                        {
                            ControllerCommandDlg dlg = new ControllerCommandDlg(m_manager, m_homeId, ZWControllerCommand.ReplaceFailedNode, (byte)cmd.device.node_id);
                            dlg.ShowDialog();
                            dlg.Dispose();
                            return true;
                        }
                }
            }
            else if (cmd.device.device_types.name == "SWITCH")
            {
                switch (cmd.device_type_commands.name)
                {
                    case "MOMENTARY":
                        {
                            int delay = 1000;
                            int.TryParse(cmd.arg, out delay);

                            m_manager.SetNodeOn(m_homeId, (byte)cmd.device.node_id);
                            System.Timers.Timer t = new System.Timers.Timer();
                            t.Interval = delay;
                            t.Elapsed += (sender, e) =>
                            {
                                m_manager.SetNodeOff(m_homeId, (byte)cmd.device.node_id);
                                t.Enabled = false;
                                t.Dispose();
                            };
                            t.Enabled = true;
                            return true;

                        }
                    case "TURNON":
                        {
                            m_manager.SetNodeOn(m_homeId, (byte)cmd.device.node_id);
                            return true;
                        }
                    case "TURNOFF":
                        {
                            m_manager.SetNodeOff(m_homeId, (byte)cmd.device.node_id);
                            break;
                        }
                }
            }
            else if (cmd.device.device_types.name == "DIMMER")
            {
                switch (cmd.device_type_commands.name)
                {
                    case "TURNON":
                        {
                            byte defaultonlevel = 99;
                            byte.TryParse(device_property_values.GetDevicePropertyValue(cmd.device_id, "DEFAULONLEVEL"), out defaultonlevel);
                            m_manager.SetNodeLevel(m_homeId, (byte)cmd.device.node_id, defaultonlevel);
                            return true;
                        }
                    case "TURNOFF":
                        {
                            m_manager.SetNodeOff(m_homeId, (byte)cmd.device.node_id);
                            return true;
                        }
                    case "SETPRESETLEVEL":
                        {
                            switch (cmd.arg)
                            {
                                case "0%":
                                    m_manager.SetNodeLevel(m_homeId, (byte)cmd.device.node_id, Convert.ToByte(0));
                                    break;
                                case "20%":
                                    m_manager.SetNodeLevel(m_homeId, (byte)cmd.device.node_id, Convert.ToByte(20));
                                    break;
                                case "40%":
                                    m_manager.SetNodeLevel(m_homeId, (byte)cmd.device.node_id, Convert.ToByte(40));
                                    break;
                                case "60%":
                                    m_manager.SetNodeLevel(m_homeId, (byte)cmd.device.node_id, Convert.ToByte(60));
                                    break;
                                case "80%":
                                    m_manager.SetNodeLevel(m_homeId, (byte)cmd.device.node_id, Convert.ToByte(80));
                                    break;
                                case "100%":
                                    m_manager.SetNodeLevel(m_homeId, (byte)cmd.device.node_id, Convert.ToByte(100));
                                    break;
                                case "255":
                                    m_manager.SetNodeLevel(m_homeId, (byte)cmd.device.node_id, Convert.ToByte(255));
                                    break;
                            }
                            return true;
                        }
                }
            }
            else if (cmd.device.device_types.name == "THERMOSTAT")
            {
                switch (cmd.device_type_commands.name)
                {
                    case "SETENERGYMODE":
                        {
                            m_manager.SetNodeOff(m_homeId, (byte)cmd.device.node_id);
                            return true;
                        }
                    case "SETCONFORTMODE":
                        {
                            m_manager.SetNodeOn(m_homeId, (byte)cmd.device.node_id);
                            return true;
                        }
                }
            }

            return false;
        }
Exemplo n.º 3
0
        public ControllerCommandDlg(ZWManager _manager, UInt32 homeId, ZWControllerCommand _op, Byte nodeId)
        {
            m_manager             = _manager;
            _homeid               = homeId;
            _zwcontrollercommand  = _op;
            _nodeid               = nodeId;
            _controllercommanddlg = this;

            InitializeComponent();

            switch (_zwcontrollercommand)
            {
            case ZWControllerCommand.AddDevice:
            {
                Text        = " - Add Device";
                label1.Text = "Press the program button on the Z-Wave device to add it to the network.\nFor security reasons, the PC Z-Wave Controller must be close to the device being added.";
                break;
            }

            case ZWControllerCommand.CreateNewPrimary:
            {
                Text        = " - Create New Primary Controller";
                label1.Text = "Put the target controller into receive configuration mode.\nThe PC Z-Wave Controller must be within 2m of the controller that is being made the primary.";
                break;
            }

            case ZWControllerCommand.ReceiveConfiguration:
            {
                Text        = " - Receive Configuration";
                label1.Text = "Transfering the network configuration\nfrom another controller.\n\nPlease bring the other controller within 2m of the PC controller and set it to send its network configuration.";
                break;
            }

            case ZWControllerCommand.RemoveDevice:
            {
                Text        = " - Remove Device";
                label1.Text = "Press the program button on the Z-Wave device to remove it from the network.\nFor security reasons, the PC Z-Wave Controller must be close to the device being removed.";
                break;
            }

            case ZWControllerCommand.TransferPrimaryRole:
            {
                Text        = " - Transfer Primary Role";
                label1.Text = "Transfering the primary role\nto another controller.\n\nPlease bring the new controller within 2m of the PC controller and set it to receive the network configuration.";
                break;
            }

            case ZWControllerCommand.HasNodeFailed:
            {
                ButtonCancel.Enabled = false;
                Text        = " - Has Node Failed";
                label1.Text = "Testing whether the node has failed.\nThis command cannot be cancelled.";
                break;
            }

            case ZWControllerCommand.RemoveFailedNode:
            {
                ButtonCancel.Enabled = false;
                Text        = " - Remove Failed Node";
                label1.Text = "Removing the failed node from the controller's list.\nThis command cannot be cancelled.";
                break;
            }

            case ZWControllerCommand.ReplaceFailedNode:
            {
                ButtonCancel.Enabled = false;
                Text        = " - Replacing Failed Node";
                label1.Text = "Testing the failed node.\nThis command cannot be cancelled.";
                break;
            }
            }

            m_manager.OnControllerStateChanged += m_controllerStateChangedHandler;
            if (!m_manager.BeginControllerCommand(_homeid, _zwcontrollercommand, false, _nodeid))
            {
                m_manager.OnControllerStateChanged -= m_controllerStateChangedHandler;
            }
        }
Exemplo n.º 4
0
        public override async Task ProcessDeviceTypeCommandAsync(DeviceType deviceType, Device device, DeviceTypeCommand command, string argument)
        {
            var nodeNumber = Convert.ToByte(device.NodeNumber);
            if (!IsNodeReady(nodeNumber))
            {
                await Log.ReportInfoFormatAsync(CancellationToken, "Failed to issue command on {0}, node {1}. Node not ready.", device.Name, nodeNumber);
                return;
            }

            if (deviceType.UniqueIdentifier == OpenzWaveDeviceTypes.Controller.ToString())
            {
                #region Controller Commands
                switch (command.UniqueIdentifier)
                {
                    case "RESET":
                        {
                            MManager.ResetController(MHomeId);
                            break;
                        }
                    case "ADDDEVICE":
                        {
                            var dlg = new ControllerCommandDlg(MManager, MHomeId, ZWControllerCommand.AddDevice, (byte)device.NodeNumber);
                            dlg.ShowDialog();
                            dlg.Dispose();
                            break;
                        }

                    case "CreateNewPrimary":
                        {
                            var dlg = new ControllerCommandDlg(MManager, MHomeId, ZWControllerCommand.CreateNewPrimary, (byte)device.NodeNumber);
                            dlg.ShowDialog();
                            dlg.Dispose();
                            break;
                        }
                    case "ReceiveConfiguration":
                        {
                            var dlg = new ControllerCommandDlg(MManager, MHomeId, ZWControllerCommand.ReceiveConfiguration, (byte)device.NodeNumber);
                            dlg.ShowDialog();
                            dlg.Dispose();
                            break;
                        }

                    case "RemoveDevice":
                        {
                            var dlg = new ControllerCommandDlg(MManager, MHomeId, ZWControllerCommand.RemoveDevice, (byte)device.NodeNumber);
                            dlg.ShowDialog();
                            dlg.Dispose();
                            break;
                        }
                    case "TransferPrimaryRole":
                        {
                            var dlg = new ControllerCommandDlg(MManager, MHomeId, ZWControllerCommand.TransferPrimaryRole, (byte)device.NodeNumber);
                            dlg.ShowDialog();
                            dlg.Dispose();
                            break;
                        }
                    case "HasNodeFailed":
                        {
                            var dlg = new ControllerCommandDlg(MManager, MHomeId, ZWControllerCommand.HasNodeFailed, (byte)device.NodeNumber);
                            dlg.ShowDialog();
                            dlg.Dispose();
                            break;
                        }
                    case "RemoveFailedNode":
                        {
                            var dlg = new ControllerCommandDlg(MManager, MHomeId, ZWControllerCommand.RemoveFailedNode, (byte)device.NodeNumber);
                            dlg.ShowDialog();
                            dlg.Dispose();
                            break;
                        }
                    case "ReplaceFailedNode":
                        {
                            var dlg = new ControllerCommandDlg(MManager, MHomeId, ZWControllerCommand.ReplaceFailedNode, (byte)device.NodeNumber);
                            dlg.ShowDialog();
                            dlg.Dispose();
                            break;
                        }
                }
                #endregion
            }
            else if (deviceType.UniqueIdentifier == OpenzWaveDeviceTypes.Switch.ToString())
            {
                #region Switch command handeling
                switch (command.UniqueIdentifier)
                {
                    case "MOMENTARY":
                        {
                            int delay;
                            int.TryParse(argument, out delay);
                            var nodeId = (byte)device.NodeNumber;

                            MManager.SetNodeOn(MHomeId, nodeId);
                            await Task.Delay(delay);
                            MManager.SetNodeOff(MHomeId, nodeId);

                            break;

                        }
                    case "TURNON":
                        {
                            MManager.SetNodeOn(MHomeId, (byte)device.NodeNumber);
                            break;
                        }
                    case "TURNOFF":
                        {
                            MManager.SetNodeOff(MHomeId, (byte)device.NodeNumber);
                            break;
                        }
                }
                #endregion
            }
            else if (deviceType.UniqueIdentifier == OpenzWaveDeviceTypes.Dimmer.ToString())
            {
                #region Dimmer command handling
                switch (command.UniqueIdentifier)
                {
                    case "TURNON":
                        {
                            using (var context = new ZvsContext(EntityContextConnection))
                            {
                                var value = await device.GetDeviceTypeValueAsync(OpenzWaveDeviceTypeSettings.DefaultDimmerOnLevel.ToString(), context);

                                if (value != null)
                                {
                                    byte bValue = byte.TryParse(value, out bValue) ? bValue : (byte)99;
                                    MManager.SetNodeLevel(MHomeId, (byte)device.NodeNumber, bValue);
                                    break;
                                }
                            }

                            MManager.SetNodeOn(MHomeId, (byte)device.NodeNumber);
                            break;
                        }
                    case "TURNOFF":
                        {
                            MManager.SetNodeOff(MHomeId, (byte)device.NodeNumber);
                            break;
                        }
                    case "SETPRESETLEVEL":
                        {
                            switch (argument)
                            {
                                case "0%":
                                    MManager.SetNodeLevel(MHomeId, (byte)device.NodeNumber, Convert.ToByte(0));
                                    break;
                                case "20%":
                                    MManager.SetNodeLevel(MHomeId, (byte)device.NodeNumber, Convert.ToByte(20));
                                    break;
                                case "40%":
                                    MManager.SetNodeLevel(MHomeId, (byte)device.NodeNumber, Convert.ToByte(40));
                                    break;
                                case "60%":
                                    MManager.SetNodeLevel(MHomeId, (byte)device.NodeNumber, Convert.ToByte(60));
                                    break;
                                case "80%":
                                    MManager.SetNodeLevel(MHomeId, (byte)device.NodeNumber, Convert.ToByte(80));
                                    break;
                                case "100%":
                                    MManager.SetNodeLevel(MHomeId, (byte)device.NodeNumber, Convert.ToByte(100));
                                    break;
                                case "255":
                                    MManager.SetNodeLevel(MHomeId, (byte)device.NodeNumber, Convert.ToByte(255));
                                    break;
                            }
                            break;
                        }
                }
                #endregion
            }
            else if (deviceType.UniqueIdentifier == OpenzWaveDeviceTypes.Thermostat.ToString())
            {
                #region Thermostat Command Handling
                switch (command.UniqueIdentifier)
                {
                    case "SETENERGYMODE":
                        {
                            MManager.SetNodeOff(MHomeId, (byte)device.NodeNumber);
                            break;
                        }
                    case "SETCONFORTMODE":
                        {
                            MManager.SetNodeOn(MHomeId, (byte)device.NodeNumber);
                            break;
                        }
                }
                #endregion
            }
        }