Skip to content

UniFi export: YAML config, fingerprint names, and code mapping - #15

Merged
ShaneCurcuru merged 1 commit into
mainfrom
claude/project-thread-v60p25
Nov 30, 2026
Merged

ShaneCurcuru merged 1 commit into
mainfrom
claude/project-thread-v60p25

Conversation

@ShaneCurcuru

Copy link
Copy Markdown
Contributor

Requested by Shane · project thread

Follow-up to #14, from Shane's message in the project thread.

Changes to scripts/unifi_export.py

  1. YAML config. Settings now come from a flat YAML file, by default ~/.config/unifi_export.yml (--config; --credentials still works as an alias). Keys: host, username, password, fingerprint. The old key = value ~/unifi.txt format is no longer read.
  2. Fingerprint names. After the export, the script reads the console's fingerprint table from GET /proxy/network/v2/api/fingerprint_devices/0 and adds a computed <field>_name column next to each code: dev_cat_name, dev_family_name, dev_id_name, dev_id_override_name, dev_vendor_name, os_name_name.
  3. Code mapping export. The codes that appear in the export, with their names, are written:
    • for CSV, as a separate field,id,name file: --mapping-output, or by default <output stem>-dev-mapping.csv next to --output (skipped with a note when CSV goes to stdout and no path is given);
    • for JSON, as a dev_mapping object: {"dev_cat": {"44": "Smartphone", "999": null}, ...}. A code the table doesn't know maps to null.
  4. PREFERRED_COLUMNS gains fixed_ip, last_ip, last_uplink_name, last_uplink_mac at the end.

Readings I chose

  • No YAML dependency. PyYAML would need a maintainer OK under AGENTS.md, so I wrote a small stdlib parser for the subset the config needs: top-level key: value with plain, single-, or double-quoted strings and # comments. Nesting, lists, anchors, and block scalars are refused with a line number (never echoing the line). Every value is read as a string, so password: 1234 stays "1234". Happy to switch to PyYAML (MIT) if you prefer.
  • Column names. Your example said dev_cat_; I used a _name suffix (dev_cat_name) so each name column sorts right after its code. Easy to rename.
  • dev_id_override is mapped too, since it is a dev_ids code (the device type a user picked in the UniFi app).
  • Table key names. The endpoint is undocumented. Table keys follow the Art-of-WiFi UniFi-API-client (dev_ids, dev_type_ids, family_ids, vendor_ids, os_name_ids) and the parser in tmanmidwest/automation-dashboard (which also accepts dev_cat_ids, dev_family_ids, dev_vendor_ids, and entries that are either a name string or an object with name/display_name). I read it the same tolerant way.
  • Failure is soft. If the fingerprint request fails (404, timeout, unexpected shape), the script warns and exports without names or mapping.

Tests

tests/test_unifi_export.py now has 140 tests (no network). ruff check, ruff format --check, pyright strict, and the full suite pass (575 passed, 1 skipped as before). I also ran it end to end against a throwaway local HTTPS server serving the v2 path: the CSV got dev_cat_name/dev_vendor_name columns and out-dev-mapping.csv was written.

Not verified

  • Not run against a real UDM Pro, so the real table's key names are unconfirmed. If names come out empty, the stderr warning or the dev_mapping nulls will show it, and the raw JSON from that endpoint is what I'd need to adjust.

Posted by Claude on behalf of @ShaneCurcuru


Generated by Claude Code

- Read settings from a flat YAML file, by default ~/.config/unifi_export.yml
  (--config; --credentials kept as an alias). A small stdlib parser reads
  only top-level string scalars, so no YAML dependency is added.
- Read the console's fingerprint table (/proxy/network/v2/api/fingerprint_devices/0)
  and add a <field>_name column for dev_cat, dev_family, dev_id,
  dev_id_override, dev_vendor, and os_name. Export the codes seen as a
  separate field,id,name CSV, or as dev_mapping in JSON. If the
  undocumented endpoint fails, warn and export without names.
- Add fixed_ip, last_ip, last_uplink_name, last_uplink_mac to the end of
  PREFERRED_COLUMNS.

Posted by Claude on behalf of @ShaneCurcuru

Generated-by: Claude Code
@ShaneCurcuru ShaneCurcuru self-assigned this Nov 30, 2026
@ShaneCurcuru
ShaneCurcuru marked this pull request as ready for review November 30, 2026 22:21
@ShaneCurcuru
ShaneCurcuru merged commit bd24b76 into main Nov 30, 2026
7 checks passed
@ShaneCurcuru
ShaneCurcuru deleted the claude/project-thread-v60p25 branch November 30, 2026 22:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants