# powermon patches Drop-in replacements for files inside a `uv tool install powermon==1.0.18` tree. Each file below lands at the indicated path — the top-level `install.sh` does the copy. | Snapshot here | Target (inside `$POWERMON_SITE`) | Purpose | |--------------------------|---------------------------------------|---------| | `pi18.py` | `protocols/pi18.py` | (a) rename `"DC/AC power direction"` → `"DC-AC power direction"` so the slash doesn't create a bogus MQTT topic level. (d) add `FWS` (fault + warning status) and `PGS` (parallel general status) query commands; bump `check_definitions_count(expected=24)` → `26`. | | `usbport.py` | `ports/usbport.py` | (b) drain leftover bytes from the hidraw fd before sending (non-blocking read loop swallowing `BlockingIOError`); wrap the main `os.read` in the retry loop so an empty first read doesn't abort. Otherwise late HID bytes from a prior command get parsed as the next reply → `KeyError`. | | `mqttbroker.py` | `libs/mqttbroker.py` | (c) broaden `connect()`'s `except ConnectionRefusedError` to `(ConnectionRefusedError, OSError)` and narrow `publish()`'s bare `except Exception` to `(OSError, RuntimeError, ValueError)`. Otherwise any broker blip (HA restart, `Errno 113 No route to host`) crashes the daemon. | | `port_config_model.py` | `configmodel/port_config_model.py` | (e) add `serial_number: None \| str \| int = Field(default=None)` to `UsbPortConfig`. The model is `NoExtraBaseModel`, so powermon rejects `serial_number:` at the port level without this. | | `ports_init.py` | `ports/__init__.py` | (f) in `from_config()`, make `port_config['serial_number'] = serial_number` a fallback (`if port_config.get('serial_number') is None:`). Device-level `serial_number` is the HA identifier (e.g. `lvx6048_1`); the port-level one is the hardware PI18 serial — they must not be conflated. | Patches (a)–(d) are load-bearing for the live setup. Patches (e) and (f) enable powermon's native wildcard-path + serial-matching flow for a single-daemon setup; we don't currently exercise that because two services probing independently at startup race each other — the external `lvx-resolve-links` oneshot handles identification instead. (e)/(f) are kept applied for future flexibility. ## Upgrade path These patches are pinned against **powermon 1.0.18**. Before bumping powermon: 1. Install the new version in a scratch location: `uv tool install --prefix /tmp/pm-next 'powermon==X.Y.Z'` 2. Diff each of the five files against the pristine upstream copy. 3. Re-apply each patch by hand into the new files (they're short — see descriptions above). 4. Drop the new files into this folder and re-run `./install.sh` on the target.