We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
pymodbus.server does not start with its default parameters
<!--

Before opening a new issue, make sure you do the following:
    * check that your issue isn't already filed: https://github.com/pymodbus-dev/pymodbus/issues
    * check the discussions forum https://github.com/pymodbus-dev/pymodbus/discussions
    * prepare a short, runnable example that reproduce the issue with the latest development version of Pymodbus

    Before opening a new issue, make sure you do the following
-->

### Versions

* Python: 3.10.9
* OS: Fedora 36
* Pymodbus: 3.1.3

### Description

- starting "pymodbus.server run" fails, but starting it with "pymodbus.server run -s tcp" works ("-s tcp" should not be needed, it is the default)
- might be related to #1118 and #1139 
- it looks like that in https://github.com/pymodbus-dev/pymodbus/blob/dev/pymodbus/repl/server/main.py#L124 there is a mismatch between the expected type for that option ("str") and the used default parameter (the enum  ModbusServerTypes.tcp (which evaluates to "ModbusServerTypes.tcp" in a string context))




### Code and Logs
```
$ pymodbus.server run
20:21:10 ERROR logging:92 Invalid server ModbusServerTypes.tcp
$
$ pymodbus.server run -s tcp

__________                          .______.                    _________
\______   \___.__. _____   ____   __| _/\_ |__  __ __  ______  /   _____/ ______________  __ ___________
 |     ___<   |  |/     \ /  _ \ / __ |  | __ \|  |  \/  ___/  \_____  \_/ __ \_  __ \  \/ // __ \_  __ \\
 |    |    \___  |  Y Y  (  <_> ) /_/ |  | \_\ \  |  /\___ \   /        \  ___/|  | \/\   /\  ___/|  | \/
 |____|    / ____|__|_|  /\____/\____ |  |___  /____//____  > /_______  /\___  >__|    \_/  \___  >__|
           \/          \/            \/      \/           \/          \/     \/                 \/


SERVER >
```


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `pymodbus/repl/server/main.py`
Content:
```
1 """Repl server main."""
2 import asyncio
3 import json
4 import sys
5 from enum import Enum
6 from pathlib import Path
7 from typing import List
8 
9 import typer
10 
11 from pymodbus import pymodbus_apply_logging_config
12 from pymodbus.framer.socket_framer import ModbusSocketFramer
13 from pymodbus.logging import Log
14 from pymodbus.repl.server.cli import run_repl
15 from pymodbus.server.reactive.default_config import DEFAULT_CONFIG
16 from pymodbus.server.reactive.main import (
17     DEFAULT_FRAMER,
18     DEFUALT_HANDLERS,
19     ReactiveServer,
20 )
21 
22 
23 CANCELLED_ERROR = asyncio.exceptions.CancelledError
24 CONTEXT_SETTING = {"allow_extra_args": True, "ignore_unknown_options": True}
25 
26 
27 # TBD class ModbusServerConfig:
28 
29 
30 class ModbusServerTypes(str, Enum):
31     """Server types."""
32 
33     # ["tcp", "serial", "tls", "udp"]
34     tcp = "tcp"  # pylint: disable=invalid-name
35     serial = "serial"  # pylint: disable=invalid-name
36     tls = "tls"  # pylint: disable=invalid-name
37     udp = "udp"  # pylint: disable=invalid-name
38 
39 
40 class ModbusFramerTypes(str, Enum):
41     """Framer types."""
42 
43     # ["socket", "rtu", "tls", "ascii", "binary"]
44     socket = "socket"  # pylint: disable=invalid-name
45     rtu = "rtu"  # pylint: disable=invalid-name
46     tls = "tls"  # pylint: disable=invalid-name
47     ascii = "ascii"  # pylint: disable=invalid-name
48     binary = "binary"  # pylint: disable=invalid-name
49 
50 
51 def _completer(incomplete: str, valid_values: List[str]) -> List[str]:
52     """Complete value."""
53     completion = []
54     for name in valid_values:
55         if name.startswith(incomplete):
56             completion.append(name)
57     return completion
58 
59 
60 def framers(incomplete: str) -> List[str]:
61     """Return an autocompleted list of supported clouds."""
62     _framers = ["socket", "rtu", "tls", "ascii", "binary"]
63     return _completer(incomplete, _framers)
64 
65 
66 def servers(incomplete: str) -> List[str]:
67     """Return an autocompleted list of supported clouds."""
68     _servers = ["tcp", "serial", "tls", "udp"]
69     return _completer(incomplete, _servers)
70 
71 
72 def process_extra_args(extra_args: List[str], modbus_config: dict) -> dict:
73     """Process extra args passed to server."""
74     options_stripped = [x.strip().replace("--", "") for x in extra_args[::2]]
75     extra_args_dict = dict(list(zip(options_stripped, extra_args[1::2])))
76     for option, value in extra_args_dict.items():
77         if option in modbus_config:
78             try:
79                 modbus_config[option] = type(modbus_config[option])(value)
80             except ValueError as err:
81                 Log.error(
82                     "Error parsing extra arg {} with value '{}'. {}", option, value, err
83                 )
84                 sys.exit(1)
85     return modbus_config
86 
87 
88 app = typer.Typer(
89     no_args_is_help=True,
90     context_settings=CONTEXT_SETTING,
91     help="Reactive Modbus server",
92 )
93 
94 
95 @app.callback()
96 def server(
97     ctx: typer.Context,
98     host: str = typer.Option("localhost", "--host", help="Host address"),
99     web_port: int = typer.Option(8080, "--web-port", help="Web app port"),
100     broadcast_support: bool = typer.Option(
101         False, "-b", help="Support broadcast messages"
102     ),
103     repl: bool = typer.Option(True, help="Enable/Disable repl for server"),
104     verbose: bool = typer.Option(
105         False, help="Run with debug logs enabled for pymodbus"
106     ),
107 ):
108     """Run server code."""
109     log_level = Log.DEBUG if verbose else Log.ERROR
110     pymodbus_apply_logging_config(log_level)
111 
112     ctx.obj = {
113         "repl": repl,
114         "host": host,
115         "web_port": web_port,
116         "broadcast": broadcast_support,
117     }
118 
119 
120 @app.command("run", context_settings=CONTEXT_SETTING)
121 def run(
122     ctx: typer.Context,
123     modbus_server: str = typer.Option(
124         ModbusServerTypes.tcp,
125         "--modbus-server",
126         "-s",
127         case_sensitive=False,
128         autocompletion=servers,
129         help="Modbus Server",
130     ),
131     modbus_framer: str = typer.Option(
132         ModbusFramerTypes.socket,
133         "--framer",
134         "-f",
135         case_sensitive=False,
136         autocompletion=framers,
137         help="Modbus framer to use",
138     ),
139     modbus_port: int = typer.Option(5020, "--modbus-port", "-p", help="Modbus port"),
140     modbus_unit_id: List[int] = typer.Option(
141         None, "--unit-id", "-u", help="Supported Modbus unit id's"
142     ),
143     modbus_config_path: Path = typer.Option(
144         None, help="Path to additional modbus server config"
145     ),
146     randomize: int = typer.Option(
147         0,
148         "--random",
149         "-r",
150         help="Randomize every `r` reads. 0=never, 1=always,2=every-second-read"
151         ", and so on. Applicable IR and DI.",
152     ),
153     change_rate: int = typer.Option(
154         0,
155         "--change-rate",
156         "-c",
157         help="Rate in % registers to change. 0=none, 100=all, 12=12% of registers"
158         ", and so on. Applicable IR and DI.",
159     ),
160 ):
161     """Run Reactive Modbus server.
162 
163     Exposing REST endpoint for response manipulation.
164     """
165     repl = ctx.obj.pop("repl")
166     # TBD extra_args = ctx.args
167     web_app_config = ctx.obj
168     loop = asyncio.get_event_loop()
169     framer = DEFAULT_FRAMER.get(modbus_framer, ModbusSocketFramer)
170     if modbus_config_path:
171         with open(modbus_config_path, encoding="utf-8") as my_file:
172             modbus_config = json.load(my_file)
173     else:
174         modbus_config = DEFAULT_CONFIG
175 
176     extra_args = ctx.args
177     data_block_settings = modbus_config.pop("data_block_settings", {})
178     modbus_config = modbus_config.get(modbus_server, {})
179     modbus_config = process_extra_args(extra_args, modbus_config)
180     if modbus_server != "serial":
181         handler = modbus_config.pop("handler", "ModbusConnectedRequestHandler")
182     else:
183         handler = modbus_config.pop("handler", "ModbusSingleRequestHandler")
184     handler = DEFUALT_HANDLERS.get(handler.strip())
185 
186     modbus_config["handler"] = handler
187     modbus_config["randomize"] = randomize
188     modbus_config["change_rate"] = change_rate
189     app = ReactiveServer.factory(
190         modbus_server,
191         framer,
192         modbus_port=modbus_port,
193         unit=modbus_unit_id,
194         loop=loop,
195         single=False,
196         data_block_settings=data_block_settings,
197         **web_app_config,
198         **modbus_config,
199     )
200     try:
201         loop.run_until_complete(app.run_async(repl))
202         if repl:
203             loop.run_until_complete(run_repl(app))
204         loop.run_forever()
205 
206     except CANCELLED_ERROR:
207         print("Done!!!!!")
208 
209 
210 if __name__ == "__main__":
211     app()
212
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/pymodbus/repl/server/main.py b/pymodbus/repl/server/main.py
--- a/pymodbus/repl/server/main.py
+++ b/pymodbus/repl/server/main.py
@@ -121,7 +121,7 @@
 def run(
     ctx: typer.Context,
     modbus_server: str = typer.Option(
-        ModbusServerTypes.tcp,
+        ModbusServerTypes.tcp.value,
         "--modbus-server",
         "-s",
         case_sensitive=False,
@@ -129,7 +129,7 @@
         help="Modbus Server",
     ),
     modbus_framer: str = typer.Option(
-        ModbusFramerTypes.socket,
+        ModbusFramerTypes.socket.value,
         "--framer",
         "-f",
         case_sensitive=False,

{"golden_diff": "diff --git a/pymodbus/repl/server/main.py b/pymodbus/repl/server/main.py\n--- a/pymodbus/repl/server/main.py\n+++ b/pymodbus/repl/server/main.py\n@@ -121,7 +121,7 @@\n def run(\n     ctx: typer.Context,\n     modbus_server: str = typer.Option(\n-        ModbusServerTypes.tcp,\n+        ModbusServerTypes.tcp.value,\n         \"--modbus-server\",\n         \"-s\",\n         case_sensitive=False,\n@@ -129,7 +129,7 @@\n         help=\"Modbus Server\",\n     ),\n     modbus_framer: str = typer.Option(\n-        ModbusFramerTypes.socket,\n+        ModbusFramerTypes.socket.value,\n         \"--framer\",\n         \"-f\",\n         case_sensitive=False,\n", "issue": "pymodbus.server does not start with its default parameters\n<!--\r\n\r\nBefore opening a new issue, make sure you do the following:\r\n    * check that your issue isn't already filed: https://github.com/pymodbus-dev/pymodbus/issues\r\n    * check the discussions forum https://github.com/pymodbus-dev/pymodbus/discussions\r\n    * prepare a short, runnable example that reproduce the issue with the latest development version of Pymodbus\r\n\r\n    Before opening a new issue, make sure you do the following\r\n-->\r\n\r\n### Versions\r\n\r\n* Python: 3.10.9\r\n* OS: Fedora 36\r\n* Pymodbus: 3.1.3\r\n\r\n### Description\r\n\r\n- starting \"pymodbus.server run\" fails, but starting it with \"pymodbus.server run -s tcp\" works (\"-s tcp\" should not be needed, it is the default)\r\n- might be related to #1118 and #1139 \r\n- it looks like that in https://github.com/pymodbus-dev/pymodbus/blob/dev/pymodbus/repl/server/main.py#L124 there is a mismatch between the expected type for that option (\"str\") and the used default parameter (the enum  ModbusServerTypes.tcp (which evaluates to \"ModbusServerTypes.tcp\" in a string context))\r\n\r\n\r\n\r\n\r\n### Code and Logs\r\n```\r\n$ pymodbus.server run\r\n20:21:10 ERROR logging:92 Invalid server ModbusServerTypes.tcp\r\n$\r\n$ pymodbus.server run -s tcp\r\n\r\n__________                          .______.                    _________\r\n\\______   \\___.__. _____   ____   __| _/\\_ |__  __ __  ______  /   _____/ ______________  __ ___________\r\n |     ___<   |  |/     \\ /  _ \\ / __ |  | __ \\|  |  \\/  ___/  \\_____  \\_/ __ \\_  __ \\  \\/ // __ \\_  __ \\\\\r\n |    |    \\___  |  Y Y  (  <_> ) /_/ |  | \\_\\ \\  |  /\\___ \\   /        \\  ___/|  | \\/\\   /\\  ___/|  | \\/\r\n |____|    / ____|__|_|  /\\____/\\____ |  |___  /____//____  > /_______  /\\___  >__|    \\_/  \\___  >__|\r\n           \\/          \\/            \\/      \\/           \\/          \\/     \\/                 \\/\r\n\r\n\r\nSERVER >\r\n```\r\n\n", "before_files": [{"content": "\"\"\"Repl server main.\"\"\"\nimport asyncio\nimport json\nimport sys\nfrom enum import Enum\nfrom pathlib import Path\nfrom typing import List\n\nimport typer\n\nfrom pymodbus import pymodbus_apply_logging_config\nfrom pymodbus.framer.socket_framer import ModbusSocketFramer\nfrom pymodbus.logging import Log\nfrom pymodbus.repl.server.cli import run_repl\nfrom pymodbus.server.reactive.default_config import DEFAULT_CONFIG\nfrom pymodbus.server.reactive.main import (\n    DEFAULT_FRAMER,\n    DEFUALT_HANDLERS,\n    ReactiveServer,\n)\n\n\nCANCELLED_ERROR = asyncio.exceptions.CancelledError\nCONTEXT_SETTING = {\"allow_extra_args\": True, \"ignore_unknown_options\": True}\n\n\n# TBD class ModbusServerConfig:\n\n\nclass ModbusServerTypes(str, Enum):\n    \"\"\"Server types.\"\"\"\n\n    # [\"tcp\", \"serial\", \"tls\", \"udp\"]\n    tcp = \"tcp\"  # pylint: disable=invalid-name\n    serial = \"serial\"  # pylint: disable=invalid-name\n    tls = \"tls\"  # pylint: disable=invalid-name\n    udp = \"udp\"  # pylint: disable=invalid-name\n\n\nclass ModbusFramerTypes(str, Enum):\n    \"\"\"Framer types.\"\"\"\n\n    # [\"socket\", \"rtu\", \"tls\", \"ascii\", \"binary\"]\n    socket = \"socket\"  # pylint: disable=invalid-name\n    rtu = \"rtu\"  # pylint: disable=invalid-name\n    tls = \"tls\"  # pylint: disable=invalid-name\n    ascii = \"ascii\"  # pylint: disable=invalid-name\n    binary = \"binary\"  # pylint: disable=invalid-name\n\n\ndef _completer(incomplete: str, valid_values: List[str]) -> List[str]:\n    \"\"\"Complete value.\"\"\"\n    completion = []\n    for name in valid_values:\n        if name.startswith(incomplete):\n            completion.append(name)\n    return completion\n\n\ndef framers(incomplete: str) -> List[str]:\n    \"\"\"Return an autocompleted list of supported clouds.\"\"\"\n    _framers = [\"socket\", \"rtu\", \"tls\", \"ascii\", \"binary\"]\n    return _completer(incomplete, _framers)\n\n\ndef servers(incomplete: str) -> List[str]:\n    \"\"\"Return an autocompleted list of supported clouds.\"\"\"\n    _servers = [\"tcp\", \"serial\", \"tls\", \"udp\"]\n    return _completer(incomplete, _servers)\n\n\ndef process_extra_args(extra_args: List[str], modbus_config: dict) -> dict:\n    \"\"\"Process extra args passed to server.\"\"\"\n    options_stripped = [x.strip().replace(\"--\", \"\") for x in extra_args[::2]]\n    extra_args_dict = dict(list(zip(options_stripped, extra_args[1::2])))\n    for option, value in extra_args_dict.items():\n        if option in modbus_config:\n            try:\n                modbus_config[option] = type(modbus_config[option])(value)\n            except ValueError as err:\n                Log.error(\n                    \"Error parsing extra arg {} with value '{}'. {}\", option, value, err\n                )\n                sys.exit(1)\n    return modbus_config\n\n\napp = typer.Typer(\n    no_args_is_help=True,\n    context_settings=CONTEXT_SETTING,\n    help=\"Reactive Modbus server\",\n)\n\n\n@app.callback()\ndef server(\n    ctx: typer.Context,\n    host: str = typer.Option(\"localhost\", \"--host\", help=\"Host address\"),\n    web_port: int = typer.Option(8080, \"--web-port\", help=\"Web app port\"),\n    broadcast_support: bool = typer.Option(\n        False, \"-b\", help=\"Support broadcast messages\"\n    ),\n    repl: bool = typer.Option(True, help=\"Enable/Disable repl for server\"),\n    verbose: bool = typer.Option(\n        False, help=\"Run with debug logs enabled for pymodbus\"\n    ),\n):\n    \"\"\"Run server code.\"\"\"\n    log_level = Log.DEBUG if verbose else Log.ERROR\n    pymodbus_apply_logging_config(log_level)\n\n    ctx.obj = {\n        \"repl\": repl,\n        \"host\": host,\n        \"web_port\": web_port,\n        \"broadcast\": broadcast_support,\n    }\n\n\n@app.command(\"run\", context_settings=CONTEXT_SETTING)\ndef run(\n    ctx: typer.Context,\n    modbus_server: str = typer.Option(\n        ModbusServerTypes.tcp,\n        \"--modbus-server\",\n        \"-s\",\n        case_sensitive=False,\n        autocompletion=servers,\n        help=\"Modbus Server\",\n    ),\n    modbus_framer: str = typer.Option(\n        ModbusFramerTypes.socket,\n        \"--framer\",\n        \"-f\",\n        case_sensitive=False,\n        autocompletion=framers,\n        help=\"Modbus framer to use\",\n    ),\n    modbus_port: int = typer.Option(5020, \"--modbus-port\", \"-p\", help=\"Modbus port\"),\n    modbus_unit_id: List[int] = typer.Option(\n        None, \"--unit-id\", \"-u\", help=\"Supported Modbus unit id's\"\n    ),\n    modbus_config_path: Path = typer.Option(\n        None, help=\"Path to additional modbus server config\"\n    ),\n    randomize: int = typer.Option(\n        0,\n        \"--random\",\n        \"-r\",\n        help=\"Randomize every `r` reads. 0=never, 1=always,2=every-second-read\"\n        \", and so on. Applicable IR and DI.\",\n    ),\n    change_rate: int = typer.Option(\n        0,\n        \"--change-rate\",\n        \"-c\",\n        help=\"Rate in % registers to change. 0=none, 100=all, 12=12% of registers\"\n        \", and so on. Applicable IR and DI.\",\n    ),\n):\n    \"\"\"Run Reactive Modbus server.\n\n    Exposing REST endpoint for response manipulation.\n    \"\"\"\n    repl = ctx.obj.pop(\"repl\")\n    # TBD extra_args = ctx.args\n    web_app_config = ctx.obj\n    loop = asyncio.get_event_loop()\n    framer = DEFAULT_FRAMER.get(modbus_framer, ModbusSocketFramer)\n    if modbus_config_path:\n        with open(modbus_config_path, encoding=\"utf-8\") as my_file:\n            modbus_config = json.load(my_file)\n    else:\n        modbus_config = DEFAULT_CONFIG\n\n    extra_args = ctx.args\n    data_block_settings = modbus_config.pop(\"data_block_settings\", {})\n    modbus_config = modbus_config.get(modbus_server, {})\n    modbus_config = process_extra_args(extra_args, modbus_config)\n    if modbus_server != \"serial\":\n        handler = modbus_config.pop(\"handler\", \"ModbusConnectedRequestHandler\")\n    else:\n        handler = modbus_config.pop(\"handler\", \"ModbusSingleRequestHandler\")\n    handler = DEFUALT_HANDLERS.get(handler.strip())\n\n    modbus_config[\"handler\"] = handler\n    modbus_config[\"randomize\"] = randomize\n    modbus_config[\"change_rate\"] = change_rate\n    app = ReactiveServer.factory(\n        modbus_server,\n        framer,\n        modbus_port=modbus_port,\n        unit=modbus_unit_id,\n        loop=loop,\n        single=False,\n        data_block_settings=data_block_settings,\n        **web_app_config,\n        **modbus_config,\n    )\n    try:\n        loop.run_until_complete(app.run_async(repl))\n        if repl:\n            loop.run_until_complete(run_repl(app))\n        loop.run_forever()\n\n    except CANCELLED_ERROR:\n        print(\"Done!!!!!\")\n\n\nif __name__ == \"__main__\":\n    app()\n", "path": "pymodbus/repl/server/main.py"}], "after_files": [{"content": "\"\"\"Repl server main.\"\"\"\nimport asyncio\nimport json\nimport sys\nfrom enum import Enum\nfrom pathlib import Path\nfrom typing import List\n\nimport typer\n\nfrom pymodbus import pymodbus_apply_logging_config\nfrom pymodbus.framer.socket_framer import ModbusSocketFramer\nfrom pymodbus.logging import Log\nfrom pymodbus.repl.server.cli import run_repl\nfrom pymodbus.server.reactive.default_config import DEFAULT_CONFIG\nfrom pymodbus.server.reactive.main import (\n    DEFAULT_FRAMER,\n    DEFUALT_HANDLERS,\n    ReactiveServer,\n)\n\n\nCANCELLED_ERROR = asyncio.exceptions.CancelledError\nCONTEXT_SETTING = {\"allow_extra_args\": True, \"ignore_unknown_options\": True}\n\n\n# TBD class ModbusServerConfig:\n\n\nclass ModbusServerTypes(str, Enum):\n    \"\"\"Server types.\"\"\"\n\n    # [\"tcp\", \"serial\", \"tls\", \"udp\"]\n    tcp = \"tcp\"  # pylint: disable=invalid-name\n    serial = \"serial\"  # pylint: disable=invalid-name\n    tls = \"tls\"  # pylint: disable=invalid-name\n    udp = \"udp\"  # pylint: disable=invalid-name\n\n\nclass ModbusFramerTypes(str, Enum):\n    \"\"\"Framer types.\"\"\"\n\n    # [\"socket\", \"rtu\", \"tls\", \"ascii\", \"binary\"]\n    socket = \"socket\"  # pylint: disable=invalid-name\n    rtu = \"rtu\"  # pylint: disable=invalid-name\n    tls = \"tls\"  # pylint: disable=invalid-name\n    ascii = \"ascii\"  # pylint: disable=invalid-name\n    binary = \"binary\"  # pylint: disable=invalid-name\n\n\ndef _completer(incomplete: str, valid_values: List[str]) -> List[str]:\n    \"\"\"Complete value.\"\"\"\n    completion = []\n    for name in valid_values:\n        if name.startswith(incomplete):\n            completion.append(name)\n    return completion\n\n\ndef framers(incomplete: str) -> List[str]:\n    \"\"\"Return an autocompleted list of supported clouds.\"\"\"\n    _framers = [\"socket\", \"rtu\", \"tls\", \"ascii\", \"binary\"]\n    return _completer(incomplete, _framers)\n\n\ndef servers(incomplete: str) -> List[str]:\n    \"\"\"Return an autocompleted list of supported clouds.\"\"\"\n    _servers = [\"tcp\", \"serial\", \"tls\", \"udp\"]\n    return _completer(incomplete, _servers)\n\n\ndef process_extra_args(extra_args: List[str], modbus_config: dict) -> dict:\n    \"\"\"Process extra args passed to server.\"\"\"\n    options_stripped = [x.strip().replace(\"--\", \"\") for x in extra_args[::2]]\n    extra_args_dict = dict(list(zip(options_stripped, extra_args[1::2])))\n    for option, value in extra_args_dict.items():\n        if option in modbus_config:\n            try:\n                modbus_config[option] = type(modbus_config[option])(value)\n            except ValueError as err:\n                Log.error(\n                    \"Error parsing extra arg {} with value '{}'. {}\", option, value, err\n                )\n                sys.exit(1)\n    return modbus_config\n\n\napp = typer.Typer(\n    no_args_is_help=True,\n    context_settings=CONTEXT_SETTING,\n    help=\"Reactive Modbus server\",\n)\n\n\n@app.callback()\ndef server(\n    ctx: typer.Context,\n    host: str = typer.Option(\"localhost\", \"--host\", help=\"Host address\"),\n    web_port: int = typer.Option(8080, \"--web-port\", help=\"Web app port\"),\n    broadcast_support: bool = typer.Option(\n        False, \"-b\", help=\"Support broadcast messages\"\n    ),\n    repl: bool = typer.Option(True, help=\"Enable/Disable repl for server\"),\n    verbose: bool = typer.Option(\n        False, help=\"Run with debug logs enabled for pymodbus\"\n    ),\n):\n    \"\"\"Run server code.\"\"\"\n    log_level = Log.DEBUG if verbose else Log.ERROR\n    pymodbus_apply_logging_config(log_level)\n\n    ctx.obj = {\n        \"repl\": repl,\n        \"host\": host,\n        \"web_port\": web_port,\n        \"broadcast\": broadcast_support,\n    }\n\n\n@app.command(\"run\", context_settings=CONTEXT_SETTING)\ndef run(\n    ctx: typer.Context,\n    modbus_server: str = typer.Option(\n        ModbusServerTypes.tcp.value,\n        \"--modbus-server\",\n        \"-s\",\n        case_sensitive=False,\n        autocompletion=servers,\n        help=\"Modbus Server\",\n    ),\n    modbus_framer: str = typer.Option(\n        ModbusFramerTypes.socket.value,\n        \"--framer\",\n        \"-f\",\n        case_sensitive=False,\n        autocompletion=framers,\n        help=\"Modbus framer to use\",\n    ),\n    modbus_port: int = typer.Option(5020, \"--modbus-port\", \"-p\", help=\"Modbus port\"),\n    modbus_unit_id: List[int] = typer.Option(\n        None, \"--unit-id\", \"-u\", help=\"Supported Modbus unit id's\"\n    ),\n    modbus_config_path: Path = typer.Option(\n        None, help=\"Path to additional modbus server config\"\n    ),\n    randomize: int = typer.Option(\n        0,\n        \"--random\",\n        \"-r\",\n        help=\"Randomize every `r` reads. 0=never, 1=always,2=every-second-read\"\n        \", and so on. Applicable IR and DI.\",\n    ),\n    change_rate: int = typer.Option(\n        0,\n        \"--change-rate\",\n        \"-c\",\n        help=\"Rate in % registers to change. 0=none, 100=all, 12=12% of registers\"\n        \", and so on. Applicable IR and DI.\",\n    ),\n):\n    \"\"\"Run Reactive Modbus server.\n\n    Exposing REST endpoint for response manipulation.\n    \"\"\"\n    repl = ctx.obj.pop(\"repl\")\n    # TBD extra_args = ctx.args\n    web_app_config = ctx.obj\n    loop = asyncio.get_event_loop()\n    framer = DEFAULT_FRAMER.get(modbus_framer, ModbusSocketFramer)\n    if modbus_config_path:\n        with open(modbus_config_path, encoding=\"utf-8\") as my_file:\n            modbus_config = json.load(my_file)\n    else:\n        modbus_config = DEFAULT_CONFIG\n\n    extra_args = ctx.args\n    data_block_settings = modbus_config.pop(\"data_block_settings\", {})\n    modbus_config = modbus_config.get(modbus_server, {})\n    modbus_config = process_extra_args(extra_args, modbus_config)\n    if modbus_server != \"serial\":\n        handler = modbus_config.pop(\"handler\", \"ModbusConnectedRequestHandler\")\n    else:\n        handler = modbus_config.pop(\"handler\", \"ModbusSingleRequestHandler\")\n    handler = DEFUALT_HANDLERS.get(handler.strip())\n\n    modbus_config[\"handler\"] = handler\n    modbus_config[\"randomize\"] = randomize\n    modbus_config[\"change_rate\"] = change_rate\n    app = ReactiveServer.factory(\n        modbus_server,\n        framer,\n        modbus_port=modbus_port,\n        unit=modbus_unit_id,\n        loop=loop,\n        single=False,\n        data_block_settings=data_block_settings,\n        **web_app_config,\n        **modbus_config,\n    )\n    try:\n        loop.run_until_complete(app.run_async(repl))\n        if repl:\n            loop.run_until_complete(run_repl(app))\n        loop.run_forever()\n\n    except CANCELLED_ERROR:\n        print(\"Done!!!!!\")\n\n\nif __name__ == \"__main__\":\n    app()\n", "path": "pymodbus/repl/server/main.py"}]}