Skip to content

Fix Xbox achievements total - #182791

Open
scardus wants to merge 6 commits into
home-assistant:devfrom
scardus:xbox-achievements-total
Open

scardus wants to merge 6 commits into
home-assistant:devfrom
scardus:xbox-achievements-total

Conversation

@scardus

@scardus scardus commented Sep 20, 2026 •

Copy link
Copy Markdown
Contributor

Proposed change

The now_playing sensor has an achievements attribute that looks like "number of achieved \ total achievable".

For Xbox One titles, titlehub reports totalAchievements as 0 as soon as the player has unlocked anything. It only reports the real total in two cases:

  • when the player hasn't unlocked anything yet,
  • and for Xbox 360 titles

You can see an example in your existing test fixtures...
titlehub_titlehistory.json has Blue Dragon, an Xbox 360 title, reporting a correct "3 / 43". The same file has Assassin's Creed Syndicate, an Xbox One title, reporting "22 / 0".

The achievements API will always give the real total, so this change calls it when titlehub reports zero.

In the first commit I've fixed titlehub_titleinfo_2533274913657542.json, which had totalAchievements: 121. I edited that file by hand during the testing of the previous PR and mistakenly included that version in #182686.

The second commit adds the achievement totals fix.

The rest of the commits are following Copilot's review:

  • A failed lookup is retried on the next update. Before, it would have been skipped for as long as the player stayed in the same game.
  • A connection error from the achievements call is caught, otherwise one failed request would mark every presence entity unavailable.
  • title_data and achievement_totals are now per config entry rather than shared by all of them. They no longer survive a reload, so the totals are fetched again afterwards.

I've been running the fix live on my own dashboard, where a Minecraft session that titlehub reports as "11 / 0" now correctly shows "11 / 133".

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Deprecation (breaking change to happen in the future)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

  • This PR fixes or closes issue: fixes #
  • This PR is related to issue:
  • Link to documentation pull request:
  • Link to developer documentation pull request:
  • Link to frontend pull request:

Checklist

  • I understand the code I am submitting and can explain how it works.
  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • I have followed the perfect PR recommendations
  • The code has been formatted using Ruff (ruff format homeassistant tests)
  • Tests have been added to verify that the new code works.
  • Any generated code has been carefully reviewed for correctness and compliance with project standards.

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • For the updated dependencies a diff between library versions and ideally a link to the changelog/release notes is added to the PR description.

To help with the load of incoming pull requests:

  • I have reviewed two other [open pull requests][prs] in this repository.

Titlehub always reports totalAchievements as 0 for Xbox One titles
once any achievement has been unlocked. 121 was from a previous
version of the file before an achievement was unlocked.
Fall back to the achievements API, which reports the real total.
Copilot AI balanced review requested due to automatic review settings September 20, 2026 18:00
@home-assistant

Copy link
Copy Markdown
Contributor

Hey there @tr4nt0r, mind taking a look at this pull request as it has been labeled with an integration (xbox) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of xbox can trigger bot actions by commenting:

  • @home-assistant close Closes the pull request.
  • @home-assistant mark-draft Mark the pull request as draft.
  • @home-assistant ready-for-review Remove the draft status from the pull request.
  • @home-assistant rename Awesome new title Renames the pull request.
  • @home-assistant reopen Reopen the pull request.
  • @home-assistant unassign xbox Removes the current integration label and assignees on the pull request, add the integration domain after the command.
  • @home-assistant update-branch Update the pull request branch with the base branch.
  • @home-assistant add-label needs-more-information Add a label (needs-more-information, problem in dependency, problem in custom component, problem in config, problem in device, feature-request) to the pull request.
  • @home-assistant remove-label needs-more-information Remove a label (needs-more-information, problem in dependency, problem in custom component, problem in config, problem in device, feature-request) on the pull request.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

The fallback cache and error paths can retain an incorrect total or disrupt presence updates.

Get a fresh assessment by requesting another Copilot review.

Review effort: Balanced
Findings: 1 High severity · 2 Medium severity

Open (3)
What changed in this PR

Corrects Xbox One achievement totals by querying the achievements API when TitleHub reports zero.

Changes:

  • Adds achievement-total fallback retrieval and entity plumbing.
  • Adds API fixtures and snapshot coverage.
  • Corrects an inaccurate TitleHub fixture.
File Description
homeassistant/​components/​xbox/​coordinator.py Fetches and caches fallback totals.
homeassistant/​components/​xbox/​entity.py Exposes totals to attribute callbacks.
homeassistant/​components/​xbox/​sensor.py Uses the fallback total.
homeassistant/​components/​xbox/​binary_sensor.py Updates the callback signature.
tests/​components/​xbox/​conftest.py Mocks the achievements endpoint.
tests/​components/​xbox/​fixtures/​achievements_gameprogress.json Adds achievements response data.
tests/​components/​xbox/​fixtures/​titlehub_titleinfo_2533274913657542.json Restores the reported zero total.
tests/​components/​xbox/​snapshots/​test_diagnostics.ambr Updates expected diagnostics.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread homeassistant/components/xbox/coordinator.py Outdated
Comment thread homeassistant/components/xbox/coordinator.py
Comment thread homeassistant/components/xbox/coordinator.py Outdated
@scardus
scardus marked this pull request as draft September 20, 2026 18:06
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings September 20, 2026 18:14

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🔵 Needs a closer look

A transient fallback request failure is never retried while the same title remains active.

Review effort: Balanced
Findings: 1 High severity · 1 Medium severity

Open (2)
Resolved since last review (1)

A same-title update takes the `continue` path, so a lookup that failed
was never retried. Fetch the total on unchanged titles too and cache it
per xuid, including a zero, so a completed lookup is not repeated.
Copilot AI review requested due to automatic review settings September 20, 2026 19:38

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

The fallback behavior is contained, failure-tolerant, and covered by focused tests.

Review effort: Balanced
Findings: 1 High severity

Open (1)
Resolved since last review (1)

title_data and achievement_totals were mutable ClassVars, so every
config entry read and wrote the same two dicts. Make them instance
attributes, set up in __init__ alongside the client.
Copilot AI review requested due to automatic review settings September 21, 2026 20:00

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

The fallback behavior is scoped, resilient to API failures, and adequately tested.

Review effort: Balanced
Findings: None

Resolved since last review (1)

@scardus
scardus marked this pull request as ready for review September 21, 2026 20:25

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants