Skip to content

Add Lichess sensors for variants, Ultra Bullet, and correspondence games#171988

Open
rlrghb wants to merge 4 commits into
home-assistant:devfrom
rlrghb:lichess-variants
Open

Add Lichess sensors for variants, Ultra Bullet, and correspondence games#171988
rlrghb wants to merge 4 commits into
home-assistant:devfrom
rlrghb:lichess-variants

Conversation

@rlrghb
Copy link
Copy Markdown

@rlrghb rlrghb commented May 23, 2026

⚠️ Draft — depends on the aiolichess 1.3.0 release. CI will fail until aiolichess 1.3.0 is published to PyPI (tracked in aryanhasgithub/aiolichess#1). This PR also stacks on top of #171987 (puzzle/correspondence sensors).

Proposed change

Add rating and games-played sensors for every remaining perf returned by Lichess's GET /api/account endpoint:

  • Ultra Bullet — rating, games
  • Correspondence games — games count (rating shipped in Add puzzles to Lichess integration #171987)
  • Variants (rating + games each):
    • Chess960
    • Crazyhouse
    • Antichess
    • Atomic
    • Horde
    • King of the Hill
    • Racing Kings
    • Three-check

All 17 new sensors are registered with entity_registry_enabled_default=False so existing installs aren't surprised with a flood of new entities — users opt in only for the perfs they care about.

Dependency upgrade

Bumps aiolichess from 1.2.0 to 1.3.0. Diff: aryanhasgithub/aiolichess@1.2.0...1.3.0

The 1.3.0 bump is purely additive — existing LichessStatistics fields keep their names and types. The new release adds rating/games fields for every perf the account endpoint returns. See aryanhasgithub/aiolichess#1 for the source change.

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:

rlrghb and others added 2 commits May 23, 2026 12:16
aiolichess.LichessStatistics has exposed puzzle and correspondence
ratings (and puzzle games) since 1.2.0, but the integration only created
sensors for the four standard time controls. Surface the existing
library fields as three new sensors, disabled by default so existing
installations are not flooded with new entities on update.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
aiolichess 1.3.0 exposes rating and games-played counts for every perf
returned by /api/account. Add sensors for the missing perfs:

- Ultra Bullet (rating + games)
- Correspondence games (rating already added in home-assistant#171987)
- Chess960, Crazyhouse, Antichess, Atomic, Horde, King of the Hill,
  Racing Kings, Three-check (rating + games each)

All new sensors are disabled by default; users opt in via the entity
registry for the perfs they actually play.

Bumps aiolichess from 1.2.0 to 1.3.0:
aryanhasgithub/aiolichess@1.2.0...1.3.0

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@home-assistant
Copy link
Copy Markdown
Contributor

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

Code owner commands

Code owners of lichess 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 lichess 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.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Updates the Lichess integration to surface additional variant/time-control statistics as sensors, aligning with updated aiolichess data and extending test coverage via refreshed snapshots.

Changes:

  • Bump aiolichess from 1.2.0 to 1.3.0.
  • Add sensors (and translations/icons) for additional Lichess variants (e.g., UltraBullet, Chess960, Antichess, Atomic, etc.).
  • Expand test fixture statistics and update snapshots accordingly.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
homeassistant/components/lichess/sensor.py Adds many new LichessEntityDescription entries to expose additional statistics as sensors.
homeassistant/components/lichess/strings.json Adds translation entries (names/units) for the newly introduced sensors.
homeassistant/components/lichess/icons.json Adds icon mappings for the newly introduced sensors.
homeassistant/components/lichess/manifest.json Updates integration requirement to aiolichess==1.3.0.
requirements_all.txt Updates pinned dependency to aiolichess==1.3.0.
tests/components/lichess/conftest.py Extends mocked LichessStatistics to include new fields required by added sensors.
tests/components/lichess/snapshots/test_sensor.ambr Updates/expands snapshots to include the additional entities and their state.

Comment thread tests/components/lichess/conftest.py Outdated
@@ -56,13 +56,35 @@ def mock_lichess_client() -> Generator[AsyncMock]:
)
client.get_user_id.return_value = "drnykterstien"
Comment on lines +82 to +96
LichessEntityDescription(
key="ultra_bullet_rating",
translation_key="ultra_bullet_rating",
state_class=SensorStateClass.MEASUREMENT,
entity_registry_enabled_default=False,
value_fn=lambda state: state.ultra_bullet_rating,
),
LichessEntityDescription(
key="ultra_bullet_games",
translation_key="ultra_bullet_games",
state_class=SensorStateClass.TOTAL_INCREASING,
entity_category=EntityCategory.DIAGNOSTIC,
entity_registry_enabled_default=False,
value_fn=lambda state: state.ultra_bullet_games,
),
@aryanhasgithub
Copy link
Copy Markdown
Contributor

Please move correspondence rating here.

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.

Please create a separate unit of measurements for the additional ratings and games except the normal 4.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done in 3edca40 — inlined "games" as the literal unit_of_measurement on every new *_games entry (ultra_bullet, correspondence, chess960, crazyhouse, antichess, atomic, horde, king_of_the_hill, racing_kings, three_check). The four standards (blitz/rapid/classical still referencing bullet_games, plus bullet_games itself) are left alone as you indicated.

rlrghb added a commit to rlrghb/core that referenced this pull request May 24, 2026
…icon, decouple unit, fix test typo

- Remove the correspondence_rating sensor so it lands in home-assistant#171988 alongside
  the rest of the correspondence-perf surface (per code owner request).
- Use mdi:puzzle for puzzle_games so it stays visually distinct from the
  other *_games sensors that share mdi:chess-pawn.
- Inline "games" as puzzle_games' unit_of_measurement instead of referencing
  bullet_games' translation key, removing the implicit cross-entity coupling.
- Rename the test fixture's player id from "drnykterstien" to "drnykterstein"
  so unique_ids match the canonical username used everywhere else in the
  tests. Pure test-data fix — production unique_ids come from the Lichess
  API.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Mirror the puzzle_games icon swap, the unit_of_measurement decoupling, and
the drnykterstien->drnykterstein test-fixture rename from home-assistant#171987 so the
end-state of the lichess integration is identical regardless of merge
order. correspondence_rating stays on this branch per code owner request.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@rlrghb
Copy link
Copy Markdown
Author

rlrghb commented May 24, 2026

correspondence_rating is now exclusive to this PR. Removed it from #171987 in 662a3a9; this branch retains it (alongside correspondence_games) in 1c09d89, which also mirrors the puzzle_games icon/unit fixes and the test-data typo cleanup so the diffs stay consistent regardless of merge order. Still draft pending aiolichess 1.3.0 release.

@aryanhasgithub
Copy link
Copy Markdown
Contributor

v1.3.0 is released.

@aryanhasgithub
Copy link
Copy Markdown
Contributor

@home-assistant ready-for-review

@home-assistant home-assistant Bot marked this pull request as ready for review May 24, 2026 04:36
Copilot AI review requested due to automatic review settings May 24, 2026 04:36
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.

},
"puzzle_games": {
"name": "Puzzle games",
"unit_of_measurement": "games"
Comment on lines +82 to +96
LichessEntityDescription(
key="ultra_bullet_rating",
translation_key="ultra_bullet_rating",
state_class=SensorStateClass.MEASUREMENT,
entity_registry_enabled_default=False,
value_fn=lambda state: state.ultra_bullet_rating,
),
LichessEntityDescription(
key="ultra_bullet_games",
translation_key="ultra_bullet_games",
state_class=SensorStateClass.TOTAL_INCREASING,
entity_category=EntityCategory.DIAGNOSTIC,
entity_registry_enabled_default=False,
value_fn=lambda state: state.ultra_bullet_games,
),
Per code-owner request on home-assistant#171988: inline "games" as the literal
unit_of_measurement on every new *_games translation entry (ultra_bullet,
correspondence, chess960, crazyhouse, antichess, atomic, horde,
king_of_the_hill, racing_kings, three_check) so none of the additions
depend on bullet_games' translation key. The four original time-control
entries (blitz/rapid/classical referencing bullet_games' literal "games")
are intentionally left unchanged to keep this PR scoped.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.

3 participants