Skip to content

Pin a stable Plex client identity to stop New Device notifications (#190)#192

Merged
Brandon-Haney merged 1 commit into
StudioNirin:mainfrom
Brandon-Haney:fix/issue-190-plex-device-identity
Jun 27, 2026
Merged

Pin a stable Plex client identity to stop New Device notifications (#190)#192
Brandon-Haney merged 1 commit into
StudioNirin:mainfrom
Brandon-Haney:fix/issue-190-plex-device-identity

Conversation

@Brandon-Haney

Copy link
Copy Markdown
Collaborator

Summary

Fixes #190. Plex was firing "New Device" security notifications attributed to PlexCache, often in the middle of the night, because PlexCache connected with the plexapi default X-Plex-Client-Identifier. That default is derived from the container's MAC/hostname (hex(uuid.getnode())), so Plex sees an unrecognized device whenever the container is recreated or after Plex ages the headless client out, and re-registers it.

This pins a stable identity for every Plex connection by reusing the plexcache_client_id that's already persisted for the OAuth login. The device now also reports as the PlexCache-D product/device name at the app version, instead of "PlexAPI" at the plexapi library version.

What changed

  • core/plex_api.pyapply_plex_client_identity() sets the plexapi header globals and rebuilds BASE_HEADERS in place (so modules that imported it by name pick up the change). ensure_plex_client_identity() loads, or creates and persists, the id from settings and applies it. It leaves a missing (pre-setup) or unparseable settings file untouched rather than writing a stub.
  • core/app.py — applies the identity right after config load, before any Plex connection, and keeps the in-memory config in sync so a later settings save can't drop the id.
  • web/main.py — applies the identity in the web lifespan before the startup Plex prefetch.
  • tests/test_plex_client_identity.py — covers header mutation, in-place BASE_HEADERS update, reuse of an existing id, create-and-persist, and the missing/unparseable-file guards.

Installs configured by OAuth already have plexcache_client_id; installs configured by manual token get one minted and saved once on first run.

How to test

  1. In Plex, make sure new-device notifications are enabled, and confirm PlexCache currently shows up in your authorized devices with a random hex id (e.g. 68fdc57b2575) and the PlexAPI product.
  2. Run PlexCache (CLI or Web). With --verbose you'll see a debug line: Plex client identity set: id=… product=PlexCache-D version=….
  3. In Plex authorized devices, confirm a single device now shows the persisted id with product/name PlexCache-D at the PlexCache version.
  4. Recreate the container and run again. The device id stays the same and no new-device notification fires. Before this change, a recreate produced a fresh id and another notification.

Confirmed working in the field by the reporter on #190 (no further notifications after switching to the build with this fix).

Reuse the persisted plexcache_client_id as the X-Plex-Client-Identifier for
all runtime Plex connections (CLI and web), tagged as the PlexCache-D product
and device name at the app version. Without this, plexapi derives the
identifier from the container MAC/hostname, so Plex registers PlexCache as a
new device whenever that value changes (container recreation) or after the
headless device is aged out, firing a New Device notification (issue StudioNirin#190).

ensure_plex_client_identity() creates and persists the id once for installs
configured by manual token rather than OAuth, leaving an existing or
unparseable settings file untouched otherwise.
@Brandon-Haney Brandon-Haney merged commit 66750ff into StudioNirin:main Jun 27, 2026
2 checks passed
@Brandon-Haney Brandon-Haney deleted the fix/issue-190-plex-device-identity branch June 27, 2026 19:19
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.

Getting New Device Access Notifications from Plex triggered by PlexCache-D

2 participants