Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve simulator types #2076

Merged
merged 1 commit into from
Mar 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions pymodbus/server/simulator/http_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,13 +180,13 @@ def __init__(
)
self.web_app.on_startup.append(self.start_modbus_server)
self.web_app.on_shutdown.append(self.stop_modbus_server)
self.generator_html = {
self.generator_html: dict[str, list] = {
"log": ["", self.build_html_log],
"registers": ["", self.build_html_registers],
"calls": ["", self.build_html_calls],
"server": ["", self.build_html_server],
}
self.generator_json = {
self.generator_json: dict[str, list] = {
"log_json": [None, self.build_json_log],
"registers_json": [None, self.build_json_registers],
"calls_json": [None, self.build_json_calls],
Expand Down Expand Up @@ -344,7 +344,7 @@ def build_html_registers(self, params, html):
)
return new_html

def build_html_calls(self, params, html):
def build_html_calls(self, params: dict, html: str) -> str:
"""Build html calls page."""
result_txt, foot = self.helper_build_html_submit(params)
if not foot:
Expand Down Expand Up @@ -380,10 +380,10 @@ def build_html_calls(self, params, html):
for function in self.request_lookup.values():
selected = (
"selected"
if function.function_code == self.call_monitor.function
if function.function_code == self.call_monitor.function #type: ignore[attr-defined]
else ""
)
function_codes += f"<option value={function.function_code} {selected}>{function.function_code_name}</option>"
function_codes += f"<option value={function.function_code} {selected}>{function.function_code_name}</option>" #type: ignore[attr-defined]
simulation_action = (
"ACTIVE" if self.call_response.active != RESPONSE_INACTIVE else ""
)
Expand All @@ -394,7 +394,7 @@ def build_html_calls(self, params, html):
call_rows = ""
for entry in reversed(self.call_list):
# req_obj = self.request_lookup[entry[1]]
call_rows += f"<tr><td>{entry.call} - {entry.fc}</td><td>{entry.address}</td><td>{entry.count}</td><td>{entry.data}</td></tr>"
call_rows += f"<tr><td>{entry.call} - {entry.fc}</td><td>{entry.address}</td><td>{entry.count}</td><td>{entry.data.decode()}</td></tr>"
# line += req_obj.funcion_code_name
new_html = (
html.replace("<!--SIMULATION_ACTIVE-->", simulation_action)
Expand Down