protected void ToggleSwitchState()
        {
            if (_switch == null)
            {
                return;
            }

            Belkin.WeMo.WeMoSwitchReponse state = _switch.GetState();

            if (!state.Success || !state.BinaryState.HasValue)
            {
                return;
            }

            SetSwitchState(!state.BinaryState.Value, state.BinaryState.Value);
        }
        private void connectBtn_Click(object sender, EventArgs e)
        {
            if (_switch == null)
            {
                //connect
                string host = hostTxt.Text;
                string port = portTxt.Text;

                if (String.IsNullOrWhiteSpace(host) || String.IsNullOrWhiteSpace(port))
                {
                    return;
                }

                _switch = new Belkin.WeMo.WeMoSwitch(new IPEndPoint(IPAddress.Parse(host), int.Parse(port)));

                Cursor = Cursors.WaitCursor;
                try
                {
                    //check this switch is alive
                    Belkin.WeMo.WeMoSwitchReponse response = _switch.GetState();

                    if (!response.Success || !response.BinaryState.HasValue)
                    {
                        _switch = null;
                    }
                    else
                    {
                        SetSwitchImageState(response.BinaryState.Value);
                    }
                }catch {
                    _switch = null;
                }

                Cursor = Cursors.Default;
            }
            else
            {
                //disconnect
                _switch = null;
            }

            UpdateControls();

            connectBtn.Text = _switch == null ? "Connect" : "Disconnect";
        }