Repository navigation
UniFi export: YAML config, fingerprint names, and code mapping - #15
Merged
Merged
Conversation
- 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Requested by Shane · project thread
Follow-up to #14, from Shane's message in the project thread.
Changes to
scripts/unifi_export.py~/.config/unifi_export.yml(--config;--credentialsstill works as an alias). Keys:host,username,password,fingerprint. The oldkey = value~/unifi.txtformat is no longer read.GET /proxy/network/v2/api/fingerprint_devices/0and adds a computed<field>_namecolumn next to each code:dev_cat_name,dev_family_name,dev_id_name,dev_id_override_name,dev_vendor_name,os_name_name.field,id,namefile:--mapping-output, or by default<output stem>-dev-mapping.csvnext to--output(skipped with a note when CSV goes to stdout and no path is given);dev_mappingobject:{"dev_cat": {"44": "Smartphone", "999": null}, ...}. A code the table doesn't know maps tonull.fixed_ip,last_ip,last_uplink_name,last_uplink_macat the end.Readings I chose
key: valuewith 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, sopassword: 1234stays"1234". Happy to switch to PyYAML (MIT) if you prefer.dev_cat_; I used a_namesuffix (dev_cat_name) so each name column sorts right after its code. Easy to rename.dev_id_overrideis mapped too, since it is adev_idscode (the device type a user picked in the UniFi app).dev_ids,dev_type_ids,family_ids,vendor_ids,os_name_ids) and the parser in tmanmidwest/automation-dashboard (which also acceptsdev_cat_ids,dev_family_ids,dev_vendor_ids, and entries that are either a name string or an object withname/display_name). I read it the same tolerant way.Tests
tests/test_unifi_export.pynow has 140 tests (no network).ruff check,ruff format --check,pyrightstrict, 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 gotdev_cat_name/dev_vendor_namecolumns andout-dev-mapping.csvwas written.Not verified
dev_mappingnulls 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