From caa32a247f883ac2aafbaa57f4daba239d89d971 Mon Sep 17 00:00:00 2001 From: WiFiGUY512 <339406050+WiFiGUY512@users.noreply.github.com> Date: Sun, 22 Nov 2026 20:27:14 -0600 Subject: [PATCH] Log the name you typed alongside the hostname and both MACs Co-Authored-By: Claude Fable 5.2 --- CHANGELOG.md | 6 ++++++ README.md | 2 +- src/switchback/cli.py | 1 + src/switchback/convert.py | 11 +++++++++-- tests/test_server.py | 22 ++++++++++++++++++++++ 5 files changed, 39 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4e45c69..e114cf7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ All notable changes are listed here. Versions follow [Semantic Versioning](https://semver.org/). +## Unreleased + +### Changed + +- The conversion log has a `friendly_name` column, so a named plug is recorded with the name you typed, its hostname and both MAC addresses. + ## [0.5.0] - 2026-11-22 ### Added diff --git a/README.md b/README.md index 4cbd4da..8df3d02 100644 --- a/README.md +++ b/README.md @@ -234,7 +234,7 @@ Useful options for `convert`: - `--server http://` uses a `switchback serve` running on another machine, so you can carry a laptop to the plugs. - `--fw-byte 0D` sets the update trigger's version byte. Switchback already tries 0C, 0D and 0E. - `--domain .lan` finds converted plugs by DNS name when mDNS cannot cross VLANs. -- Every converted plug is recorded in `switchback-plugs.csv` in your home folder: time, name and both MAC addresses. The file stays on your computer. `--log other.csv` picks another file and `--no-log` turns it off. +- Every converted plug is recorded in `switchback-plugs.csv` in your home folder: time, the name you gave it, and both MAC addresses. The file stays on your computer. `--log other.csv` picks another file and `--no-log` turns it off. - `--printer host:9100` prints a label on a ZPL printer. The layout is fixed for 1.5 x 0.5 inch labels at 203 dpi. On other label sizes it will print small or clipped. - `--payload my.bin` serves your own ESPHome factory image instead of the portal one. diff --git a/src/switchback/cli.py b/src/switchback/cli.py index f9f13c6..87291f5 100644 --- a/src/switchback/cli.py +++ b/src/switchback/cli.py @@ -355,6 +355,7 @@ def name_plug(plug: Any, payloads: Payloads, mode: str, ssid: str, password: str friendly = friendly[:-1] payloads.select(mode, ssid, password, name=hostname, friendly_name=friendly) plug.name = hostname + plug.friendly_name = friendly say(f"It will be {hostname!r}, shown as {friendly!r}.") diff --git a/src/switchback/convert.py b/src/switchback/convert.py index 286af0c..f765f66 100644 --- a/src/switchback/convert.py +++ b/src/switchback/convert.py @@ -187,9 +187,16 @@ def write_log(path: Path, plug: Plug, address: str) -> None: with path.open("a", newline="", encoding="utf-8") as handle: writer = csv.writer(handle) if new: - writer.writerow(["time", "name", "wifi_mac", "ble_mac", "address"]) + writer.writerow(["time", "name", "friendly_name", "wifi_mac", "ble_mac", "address"]) writer.writerow( - [datetime.datetime.now().isoformat(timespec="seconds"), plug.name, plug.wifi_mac, plug.ble_mac, address] + [ + datetime.datetime.now().isoformat(timespec="seconds"), + plug.name, + getattr(plug, "friendly_name", "") or "", + plug.wifi_mac, + plug.ble_mac, + address, + ] ) diff --git a/tests/test_server.py b/tests/test_server.py index 7150fec..f3a940e 100644 --- a/tests/test_server.py +++ b/tests/test_server.py @@ -88,3 +88,25 @@ def test_a_name_is_patched_into_either_payload(server): def test_old_firmware_cannot_be_named(flasher): payloads = Payloads(flasher, make_factory(placeholders=False, name_slots=False), None) assert not payloads.can_name("portal") + + +def test_log_records_the_name_with_both_macs(tmp_path, flasher, factory): + import csv + + from switchback import cli, convert + + class FakePlug: + name = "sbplug-a1b2c3" + wifi_mac = "aa:bb:cc:a1:b2:c3" + ble_mac = "aa:bb:cc:a1:b2:c5" + + plug = FakePlug() + payloads = Payloads(flasher, factory, factory) + cli.name_plug(plug, payloads, "portal", "", "", "Garage Freezer") + log = tmp_path / "plugs.csv" + convert.write_log(log, plug, "hotspot") + convert.write_log(log, FakePlug(), "hotspot") + rows = list(csv.DictReader(log.open(encoding="utf-8"))) + assert rows[0]["name"] == "garage-freezer" and rows[0]["friendly_name"] == "Garage Freezer" + assert rows[0]["wifi_mac"] == "aa:bb:cc:a1:b2:c3" and rows[0]["ble_mac"] == "aa:bb:cc:a1:b2:c5" + assert rows[1]["name"] == "sbplug-a1b2c3" and rows[1]["friendly_name"] == ""