franklinwh-modbus-bridge integration plan¶
Status: waiting. Agreed with the "Modbus Bridge HA" session on 2026-10-07: no edits to
franklinwh-modbus-bridge or its worktrees until its branches have merged. Those branches are
fix/no-phantom-default-gateway, feat/honest-mock-gateways,
feat/ha-supervisor-instance, feat/mqtt-optional-broker and PR #1. The swap is then done on
a fresh worktree from main, either by the emulator side or by the bridge side; the owner
decides.
The change¶
Replace the bridge's wire-less MockPoller / synthetic_points with an in-process emulator,
following the pattern franklinwh-local-bridge's mockgw.py uses for Direct Connect. Mocks then
exercise the real poller, catalog, franklinwh-modbus, command handler and MQTT path, and the
bridge's copy of the synthetic model can be deleted.
from franklinwh_emulator import Gateway, GatewayConfig, SiteConfig
gw = Gateway(GatewayConfig(
id=gw_id, seed=n,
setup="in-service", # Modbus TCP on from the start (#40)
quirks={"tou_reserve_mirrors_self": False}, # 15509 holds the TOU reserve
site=SiteConfig(ac_type=ac_type, apower_units=units)))
host, port = gw.start() # register 127.0.0.1:<port> as the gateway host
...
gw.stop()
# inside the bridge's event loop: await gw.start_async() / await gw.stop_async()
Files on the bridge side (theirs): gateway/mock_gateway.py, gateway/instance.py,
gateway/registry.py, and possibly api/gateways_api.py and main.py.
Modbus TCP starts off on a factory aGate (2026-10-30, #40). Use setup="in-service" for a
gateway that is already set up, or test the real path: a factory gateway serves only Direct
Connect until a 1205 sunsMdEn write turns Modbus TCP on (about 3 s later).
Acceptance checks (behaviour the bridge's mock has today, which must be kept)¶
- HA select/number controls for mode and reserves: the emulator acknowledges and discards the
15507–15509 writes, as the aGate does (franklinwh-modbus firmware_quirks
ext_15507_15509_writes), so the bridge must show the setting as not applied. To test a mode or reserve change, set it from the test side (gw.site.set_native_mode,set_reserves). - Force Charge depends on the profile. On the default profile (
agate-v12r02b60d00-candidate) the aGate refuses every charge setpoint with exception 3 (refuse_charge), so the bridge must report the command as rejected and the battery carries on. Onagate-v10r01b04d00(or withquirks: {refuse_charge: false, wsetpct_max_abs_raw: null}) it reaches −5 kW at max power (WSetPct −1000 →714.DCW−5000 → bridgebattery_power_w−5000). - Force Release results in no dispatch: WSetEna 0, and the battery returns to native behaviour.
- Discharge stops at the active mode's reserve, including under VPP.
loc_rem_ctl_namereads Local.- MQTT
franklinwh/<sid>/control/<slug>/setis routed per device. - The Controls tab and Force Release post to
/api/gateways/<viewed>/commandand hit the viewed gateway, not the default one. - One Modbus TCP client per gateway: the default profile serves
max_connections=1(Direct Connect has no limit unlessdc_max_connectionsis set). If anything other than the poller probes a mock, usequirks={"max_connections": None}.
Semantics the two sides agreed¶
send_command(BatteryCommand(power_watts=W)): positive = charge. The bridge then writesWSetRvrtTmsto hold VPP. Release =reset_control_state(handshake_wait_s=0), thenWSetRvrtTms=0,WSetEnaRvrt=0.- Native modes: 1 Emergency Backup, 2 Self-Consumption, 3 TOU. No other 15507 value has been read (franklinwh-modbus#75).
- Bridge sample convention:
battery_power_wnegative = charging. ac_type: 0 single (230 V / 50 Hz), 1 split L1+L2 (240 V / 60 Hz, US aGate), 2 three phase (not on AU/NZ aGates, which are single phase: one aGate per phase, #242).- The bridge's planned LAN setup wizard should probe PDU 0, then 40000, then 50000, and cope
with "port open but session held". The emulator's
quirks={"busy_behaviour": "hang"}plusfaults.session_heldreproduces that.
Known consumers of the emulator's behaviour (keep stable)¶
- franklinwh-modbus
discovery(probe/scan), PR david2069/franklinwh-modbus#15. It was verified against this emulator on 2026-10-07 (10/10 checks), by the Modbus Bridge HA session in a scratch venv, without changes to this repo. The checks were: - base 0, and a re-probe straight afterwards (the session is released);
- a second client while the session is held → no response;
- the
session_heldandofflinefaults; busy_behaviour: hang(the probe returns within 1 s);base_aliases: [40000];- a closed port.
The probe holds the session for two reads (the marker, then one 64-register nameplate read). The bridge's setup wizard will use it, so these fault modes are its test fixtures. Changes to session handling, busy behaviour, aliases or fault semantics must be coordinated.