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;
        }
        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
            }
        }