mirror of
https://github.com/home-assistant/core.git
synced 2026-09-09 07:01:41 +01:00
Add puzzles to Lichess integration (#171987)
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com> Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
This commit is contained in:
co-authored by
Claude Opus 4.7
Joost Lekkerkerker
parent
4afb7c0997
commit
cfbd0f3217
@@ -19,6 +19,12 @@
|
||||
"classical_rating": {
|
||||
"default": "mdi:chart-line"
|
||||
},
|
||||
"puzzle_games": {
|
||||
"default": "mdi:puzzle"
|
||||
},
|
||||
"puzzle_rating": {
|
||||
"default": "mdi:chart-line"
|
||||
},
|
||||
"rapid_games": {
|
||||
"default": "mdi:chess-pawn"
|
||||
},
|
||||
|
||||
@@ -79,6 +79,21 @@ SENSORS: tuple[LichessEntityDescription, ...] = (
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
value_fn=lambda state: state.classical_games,
|
||||
),
|
||||
LichessEntityDescription(
|
||||
key="puzzle_rating",
|
||||
translation_key="puzzle_rating",
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
entity_registry_enabled_default=False,
|
||||
value_fn=lambda state: state.puzzle_rating,
|
||||
),
|
||||
LichessEntityDescription(
|
||||
key="puzzle_games",
|
||||
translation_key="puzzle_games",
|
||||
state_class=SensorStateClass.TOTAL_INCREASING,
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
entity_registry_enabled_default=False,
|
||||
value_fn=lambda state: state.puzzle_games,
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -42,6 +42,13 @@
|
||||
"classical_rating": {
|
||||
"name": "Classical rating"
|
||||
},
|
||||
"puzzle_games": {
|
||||
"name": "Puzzle games",
|
||||
"unit_of_measurement": "[%key:component::lichess::entity::sensor::bullet_games::unit_of_measurement%]"
|
||||
},
|
||||
"puzzle_rating": {
|
||||
"name": "Puzzle rating"
|
||||
},
|
||||
"rapid_games": {
|
||||
"name": "Rapid games",
|
||||
"unit_of_measurement": "[%key:component::lichess::entity::sensor::bullet_games::unit_of_measurement%]"
|
||||
|
||||
@@ -27,7 +27,7 @@ def mock_config_entry() -> MockConfigEntry:
|
||||
return MockConfigEntry(
|
||||
domain=DOMAIN,
|
||||
title="DrNykterstein",
|
||||
unique_id="drnykterstien",
|
||||
unique_id="drnykterstein",
|
||||
data={CONF_API_TOKEN: "my_secret_token"},
|
||||
)
|
||||
|
||||
@@ -47,22 +47,24 @@ def mock_lichess_client() -> Generator[AsyncMock]:
|
||||
):
|
||||
client = mock_client.return_value
|
||||
client.get_all.return_value = LichessUser(
|
||||
id="drnykterstien",
|
||||
id="drnykterstein",
|
||||
username="DrNykterstein",
|
||||
url="https://lichess.org/@/DrNykterstein",
|
||||
created_at=1420502920988,
|
||||
seen_at=1747342929853,
|
||||
play_time=999999,
|
||||
)
|
||||
client.get_user_id.return_value = "drnykterstien"
|
||||
client.get_user_id.return_value = "drnykterstein"
|
||||
client.get_statistics.return_value = LichessStatistics(
|
||||
blitz_rating=944,
|
||||
rapid_rating=1050,
|
||||
bullet_rating=1373,
|
||||
classical_rating=888,
|
||||
puzzle_rating=2500,
|
||||
blitz_games=31,
|
||||
rapid_games=324,
|
||||
bullet_games=7,
|
||||
classical_games=1,
|
||||
puzzle_games=50,
|
||||
)
|
||||
yield client
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
'identifiers': set({
|
||||
tuple(
|
||||
'lichess',
|
||||
'drnykterstien',
|
||||
'drnykterstein',
|
||||
),
|
||||
}),
|
||||
'labels': set({
|
||||
|
||||
@@ -34,7 +34,7 @@
|
||||
'suggested_object_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': 'blitz_games',
|
||||
'unique_id': 'drnykterstien.blitz_games',
|
||||
'unique_id': 'drnykterstein.blitz_games',
|
||||
'unit_of_measurement': 'games',
|
||||
})
|
||||
# ---
|
||||
@@ -88,7 +88,7 @@
|
||||
'suggested_object_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': 'blitz_rating',
|
||||
'unique_id': 'drnykterstien.blitz_rating',
|
||||
'unique_id': 'drnykterstein.blitz_rating',
|
||||
'unit_of_measurement': None,
|
||||
})
|
||||
# ---
|
||||
@@ -141,7 +141,7 @@
|
||||
'suggested_object_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': 'bullet_games',
|
||||
'unique_id': 'drnykterstien.bullet_games',
|
||||
'unique_id': 'drnykterstein.bullet_games',
|
||||
'unit_of_measurement': 'games',
|
||||
})
|
||||
# ---
|
||||
@@ -195,7 +195,7 @@
|
||||
'suggested_object_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': 'bullet_rating',
|
||||
'unique_id': 'drnykterstien.bullet_rating',
|
||||
'unique_id': 'drnykterstein.bullet_rating',
|
||||
'unit_of_measurement': None,
|
||||
})
|
||||
# ---
|
||||
@@ -248,7 +248,7 @@
|
||||
'suggested_object_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': 'classical_games',
|
||||
'unique_id': 'drnykterstien.classical_games',
|
||||
'unique_id': 'drnykterstein.classical_games',
|
||||
'unit_of_measurement': 'games',
|
||||
})
|
||||
# ---
|
||||
@@ -302,7 +302,7 @@
|
||||
'suggested_object_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': 'classical_rating',
|
||||
'unique_id': 'drnykterstien.classical_rating',
|
||||
'unique_id': 'drnykterstein.classical_rating',
|
||||
'unit_of_measurement': None,
|
||||
})
|
||||
# ---
|
||||
@@ -320,6 +320,113 @@
|
||||
'state': '888',
|
||||
})
|
||||
# ---
|
||||
# name: test_all_entities[sensor.drnykterstein_puzzle_games-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': list([
|
||||
None,
|
||||
]),
|
||||
'area_id': None,
|
||||
'capabilities': dict({
|
||||
'state_class': <SensorStateClass.TOTAL_INCREASING: 'total_increasing'>,
|
||||
}),
|
||||
'config_entry_id': <ANY>,
|
||||
'config_subentry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'sensor',
|
||||
'entity_category': <EntityCategory.DIAGNOSTIC: 'diagnostic'>,
|
||||
'entity_id': 'sensor.drnykterstein_puzzle_games',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'labels': set({
|
||||
}),
|
||||
'name': None,
|
||||
'object_id_base': 'Puzzle games',
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': None,
|
||||
'original_icon': None,
|
||||
'original_name': 'Puzzle games',
|
||||
'platform': 'lichess',
|
||||
'previous_unique_id': None,
|
||||
'suggested_object_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': 'puzzle_games',
|
||||
'unique_id': 'drnykterstein.puzzle_games',
|
||||
'unit_of_measurement': 'games',
|
||||
})
|
||||
# ---
|
||||
# name: test_all_entities[sensor.drnykterstein_puzzle_games-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'friendly_name': 'DrNykterstein Puzzle games',
|
||||
'state_class': <SensorStateClass.TOTAL_INCREASING: 'total_increasing'>,
|
||||
'unit_of_measurement': 'games',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'sensor.drnykterstein_puzzle_games',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': '50',
|
||||
})
|
||||
# ---
|
||||
# name: test_all_entities[sensor.drnykterstein_puzzle_rating-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': list([
|
||||
None,
|
||||
]),
|
||||
'area_id': None,
|
||||
'capabilities': dict({
|
||||
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
|
||||
}),
|
||||
'config_entry_id': <ANY>,
|
||||
'config_subentry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'sensor',
|
||||
'entity_category': None,
|
||||
'entity_id': 'sensor.drnykterstein_puzzle_rating',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'labels': set({
|
||||
}),
|
||||
'name': None,
|
||||
'object_id_base': 'Puzzle rating',
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': None,
|
||||
'original_icon': None,
|
||||
'original_name': 'Puzzle rating',
|
||||
'platform': 'lichess',
|
||||
'previous_unique_id': None,
|
||||
'suggested_object_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': 'puzzle_rating',
|
||||
'unique_id': 'drnykterstein.puzzle_rating',
|
||||
'unit_of_measurement': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_all_entities[sensor.drnykterstein_puzzle_rating-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'friendly_name': 'DrNykterstein Puzzle rating',
|
||||
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'sensor.drnykterstein_puzzle_rating',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': '2500',
|
||||
})
|
||||
# ---
|
||||
# name: test_all_entities[sensor.drnykterstein_rapid_games-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': list([
|
||||
@@ -355,7 +462,7 @@
|
||||
'suggested_object_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': 'rapid_games',
|
||||
'unique_id': 'drnykterstien.rapid_games',
|
||||
'unique_id': 'drnykterstein.rapid_games',
|
||||
'unit_of_measurement': 'games',
|
||||
})
|
||||
# ---
|
||||
@@ -409,7 +516,7 @@
|
||||
'suggested_object_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': 'rapid_rating',
|
||||
'unique_id': 'drnykterstien.rapid_rating',
|
||||
'unique_id': 'drnykterstein.rapid_rating',
|
||||
'unit_of_measurement': None,
|
||||
})
|
||||
# ---
|
||||
|
||||
@@ -30,7 +30,7 @@ async def test_full_flow(hass: HomeAssistant, mock_setup_entry: AsyncMock) -> No
|
||||
assert result["type"] is FlowResultType.CREATE_ENTRY
|
||||
assert result["title"] == "DrNykterstein"
|
||||
assert result["data"] == {CONF_API_TOKEN: "my_secret_token"}
|
||||
assert result["result"].unique_id == "drnykterstien"
|
||||
assert result["result"].unique_id == "drnykterstein"
|
||||
assert len(mock_setup_entry.mock_calls) == 1
|
||||
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ async def test_device(
|
||||
"""Test the Lichess device."""
|
||||
await setup_integration(hass, mock_config_entry)
|
||||
|
||||
device = device_registry.async_get_device({(DOMAIN, "drnykterstien")})
|
||||
device = device_registry.async_get_device({(DOMAIN, "drnykterstein")})
|
||||
assert device
|
||||
assert device == snapshot
|
||||
|
||||
|
||||
Reference in New Issue
Block a user