mirror of
https://github.com/pyMC-dev/pyMC_Repeater.git
synced 2026-07-26 19:42:46 +02:00
fix(cli): point txdelay settings at the delays config section
The mesh CLI's get/set txdelay and direct.txdelay read and wrote repeater.tx_delay_factor / repeater.direct_tx_delay_factor, but the engine and web API use the delays section, so the CLI knobs were silently dead: set appeared to succeed while changing nothing, and get echoed the unused value back. Same defect and same fix as the recent rxdelay repoint.
This commit is contained in:
@@ -576,11 +576,15 @@ class MeshCLI:
|
||||
return f"> {delay}"
|
||||
|
||||
elif param == "txdelay":
|
||||
delay = self.repeater_config.get("tx_delay_factor", 1.0)
|
||||
# The TX delay factor lives in the delays section (the value the
|
||||
# engine consumes), not the repeater section.
|
||||
delay = self.config.get("delays", {}).get("tx_delay_factor", 1.0)
|
||||
return f"> {delay}"
|
||||
|
||||
elif param == "direct.txdelay":
|
||||
delay = self.repeater_config.get("direct_tx_delay_factor", 0.5)
|
||||
# The direct TX delay factor lives in the delays section (the
|
||||
# value the engine consumes), not the repeater section.
|
||||
delay = self.config.get("delays", {}).get("direct_tx_delay_factor", 0.5)
|
||||
return f"> {delay}"
|
||||
|
||||
elif param == "multi.acks":
|
||||
@@ -752,7 +756,7 @@ class MeshCLI:
|
||||
delay = float(value)
|
||||
if delay < 0:
|
||||
return "Error: cannot be negative"
|
||||
self.repeater_config["tx_delay_factor"] = delay
|
||||
self.config.setdefault("delays", {})["tx_delay_factor"] = delay
|
||||
saved, _ = self.config_manager.save_to_file()
|
||||
self.config_manager.live_update_daemon(["repeater", "delays"])
|
||||
return "OK"
|
||||
@@ -761,7 +765,7 @@ class MeshCLI:
|
||||
delay = float(value)
|
||||
if delay < 0:
|
||||
return "Error: cannot be negative"
|
||||
self.repeater_config["direct_tx_delay_factor"] = delay
|
||||
self.config.setdefault("delays", {})["direct_tx_delay_factor"] = delay
|
||||
saved, _ = self.config_manager.save_to_file()
|
||||
self.config_manager.live_update_daemon(["repeater", "delays"])
|
||||
return "OK"
|
||||
|
||||
@@ -210,6 +210,47 @@ def test_cmd_set_updates_and_validation_errors():
|
||||
assert cli._cmd_set("unknown.key 1") == "unknown config: unknown.key"
|
||||
|
||||
|
||||
def test_cmd_set_txdelay_writes_delays_section():
|
||||
cfg = _base_config()
|
||||
stale_repeater_value = cfg["repeater"]["tx_delay_factor"]
|
||||
mgr = _cfg_mgr()
|
||||
cli = MeshCLI("/tmp/cfg.yaml", cfg, mgr)
|
||||
|
||||
assert cli._cmd_set("txdelay 2.0") == "OK"
|
||||
assert cfg["delays"]["tx_delay_factor"] == 2.0
|
||||
assert cfg["repeater"]["tx_delay_factor"] == stale_repeater_value
|
||||
mgr.live_update_daemon.assert_called_with(["repeater", "delays"])
|
||||
|
||||
|
||||
def test_cmd_set_direct_txdelay_writes_delays_section():
|
||||
cfg = _base_config()
|
||||
stale_repeater_value = cfg["repeater"]["direct_tx_delay_factor"]
|
||||
mgr = _cfg_mgr()
|
||||
cli = MeshCLI("/tmp/cfg.yaml", cfg, mgr)
|
||||
|
||||
assert cli._cmd_set("direct.txdelay 0.75") == "OK"
|
||||
assert cfg["delays"]["direct_tx_delay_factor"] == 0.75
|
||||
assert cfg["repeater"]["direct_tx_delay_factor"] == stale_repeater_value
|
||||
mgr.live_update_daemon.assert_called_with(["repeater", "delays"])
|
||||
|
||||
|
||||
def test_cmd_get_txdelay_and_direct_txdelay_prefer_delays_section():
|
||||
cfg = _base_config()
|
||||
# repeater section still carries stale values; the delays section wins.
|
||||
cfg["delays"] = {"tx_delay_factor": 4.4, "direct_tx_delay_factor": 0.9}
|
||||
cli = MeshCLI("/tmp/cfg.yaml", cfg, _cfg_mgr())
|
||||
|
||||
assert cli._cmd_get("txdelay") == "> 4.4"
|
||||
assert cli._cmd_get("direct.txdelay") == "> 0.9"
|
||||
|
||||
|
||||
def test_cmd_get_txdelay_and_direct_txdelay_default_without_delays_section():
|
||||
cli = MeshCLI("/tmp/cfg.yaml", _base_config(), _cfg_mgr())
|
||||
|
||||
assert cli._cmd_get("txdelay") == "> 1.0"
|
||||
assert cli._cmd_get("direct.txdelay") == "> 0.5"
|
||||
|
||||
|
||||
def test_misc_commands_and_routes():
|
||||
cli = MeshCLI("/tmp/cfg.yaml", _base_config(), _cfg_mgr(), enable_regions=True)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user