diff --git a/homeassistant/components/nyt_games/coordinator.py b/homeassistant/components/nyt_games/coordinator.py index 75aa79f62ba602d439863101029e2806fdbdd3bf..3b6955747505dd7d5b3622157dc1203a1975d730 100644 --- a/homeassistant/components/nyt_games/coordinator.py +++ b/homeassistant/components/nyt_games/coordinator.py @@ -22,7 +22,7 @@ class NYTGamesData: """Class for NYT Games data.""" wordle: Wordle - spelling_bee: SpellingBee + spelling_bee: SpellingBee | None connections: Connections diff --git a/homeassistant/components/nyt_games/manifest.json b/homeassistant/components/nyt_games/manifest.json index 922a29a489b3faf1c3526912683979949cad38dc..1cdc5988e382bee7472e8bf9421f800580c1346f 100644 --- a/homeassistant/components/nyt_games/manifest.json +++ b/homeassistant/components/nyt_games/manifest.json @@ -6,5 +6,5 @@ "documentation": "https://www.home-assistant.io/integrations/nyt_games", "integration_type": "service", "iot_class": "cloud_polling", - "requirements": ["nyt_games==0.4.0"] + "requirements": ["nyt_games==0.4.2"] } diff --git a/homeassistant/components/nyt_games/sensor.py b/homeassistant/components/nyt_games/sensor.py index 6e243a908b451e2557bdd2dfadb7f177d5faa9e6..6e19a4c21dc6bd5780989cbce339a988ecbef8fb 100644 --- a/homeassistant/components/nyt_games/sensor.py +++ b/homeassistant/components/nyt_games/sensor.py @@ -156,10 +156,11 @@ async def async_setup_entry( entities: list[SensorEntity] = [ NYTGamesWordleSensor(coordinator, description) for description in WORDLE_SENSORS ] - entities.extend( - NYTGamesSpellingBeeSensor(coordinator, description) - for description in SPELLING_BEE_SENSORS - ) + if coordinator.data.spelling_bee is not None: + entities.extend( + NYTGamesSpellingBeeSensor(coordinator, description) + for description in SPELLING_BEE_SENSORS + ) entities.extend( NYTGamesConnectionsSensor(coordinator, description) for description in CONNECTIONS_SENSORS @@ -211,6 +212,7 @@ class NYTGamesSpellingBeeSensor(SpellingBeeEntity, SensorEntity): @property def native_value(self) -> StateType: """Return the state of the sensor.""" + assert self.coordinator.data.spelling_bee is not None return self.entity_description.value_fn(self.coordinator.data.spelling_bee) diff --git a/requirements_all.txt b/requirements_all.txt index f67bcc08faee9f160da4f149e357187d068a54f8..0ed8a3da84ead41f538d3a0b2721e1a705fa407f 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -1484,7 +1484,7 @@ numato-gpio==0.13.0 numpy==1.26.4 # homeassistant.components.nyt_games -nyt_games==0.4.0 +nyt_games==0.4.2 # homeassistant.components.oasa_telematics oasatelematics==0.3 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index 5f2a645c552bb2ab621a83585f5cdfb9b9f24be6..d08378b37cb36bd8f4f3d34f01619caf7e4dd2f9 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -1232,7 +1232,7 @@ numato-gpio==0.13.0 numpy==1.26.4 # homeassistant.components.nyt_games -nyt_games==0.4.0 +nyt_games==0.4.2 # homeassistant.components.google oauth2client==4.1.3 diff --git a/tests/components/nyt_games/fixtures/new_account.json b/tests/components/nyt_games/fixtures/new_account.json new file mode 100644 index 0000000000000000000000000000000000000000..ad4d8e2e4164ea69b52e1cf3be323f479f474d1c --- /dev/null +++ b/tests/components/nyt_games/fixtures/new_account.json @@ -0,0 +1,51 @@ +{ + "states": [], + "user_id": 260705259, + "player": { + "user_id": 260705259, + "last_updated": 1727358123, + "stats": { + "wordle": { + "legacyStats": { + "gamesPlayed": 1, + "gamesWon": 1, + "guesses": { + "1": 0, + "2": 0, + "3": 0, + "4": 0, + "5": 1, + "6": 0, + "fail": 0 + }, + "currentStreak": 0, + "maxStreak": 1, + "lastWonDayOffset": 1118, + "hasPlayed": true, + "autoOptInTimestamp": 1727357874700, + "hasMadeStatsChoice": false, + "timestamp": 1727358123 + }, + "calculatedStats": { + "gamesPlayed": 0, + "gamesWon": 0, + "guesses": { + "1": 0, + "2": 0, + "3": 0, + "4": 0, + "5": 0, + "6": 0, + "fail": 0 + }, + "currentStreak": 0, + "maxStreak": 1, + "lastWonPrintDate": "", + "lastCompletedPrintDate": "", + "hasPlayed": false, + "generation": 1 + } + } + } + } +} diff --git a/tests/components/nyt_games/snapshots/test_sensor.ambr b/tests/components/nyt_games/snapshots/test_sensor.ambr index 7c4c2b57253f05e86737d271392f9f5e3311b477..fdec7d58d9d3196988d3385da2d4682d9e7f5d0b 100644 --- a/tests/components/nyt_games/snapshots/test_sensor.ambr +++ b/tests/components/nyt_games/snapshots/test_sensor.ambr @@ -547,7 +547,7 @@ 'last_changed': <ANY>, 'last_reported': <ANY>, 'last_updated': <ANY>, - 'state': '33', + 'state': '70', }) # --- # name: test_all_entities[sensor.wordle_won-entry] @@ -597,6 +597,6 @@ 'last_changed': <ANY>, 'last_reported': <ANY>, 'last_updated': <ANY>, - 'state': '26', + 'state': '51', }) # --- diff --git a/tests/components/nyt_games/test_sensor.py b/tests/components/nyt_games/test_sensor.py index 3866b6afab0cafe2233391d65f4f7a1739940677..f35caf20b572117683c386f6cc8a4b493ba41e16 100644 --- a/tests/components/nyt_games/test_sensor.py +++ b/tests/components/nyt_games/test_sensor.py @@ -4,17 +4,23 @@ from datetime import timedelta from unittest.mock import AsyncMock from freezegun.api import FrozenDateTimeFactory -from nyt_games import NYTGamesError +from nyt_games import NYTGamesError, WordleStats import pytest from syrupy import SnapshotAssertion +from homeassistant.components.nyt_games.const import DOMAIN from homeassistant.const import STATE_UNAVAILABLE from homeassistant.core import HomeAssistant from homeassistant.helpers import entity_registry as er from . import setup_integration -from tests.common import MockConfigEntry, async_fire_time_changed, snapshot_platform +from tests.common import ( + MockConfigEntry, + async_fire_time_changed, + load_fixture, + snapshot_platform, +) @pytest.mark.usefixtures("entity_registry_enabled_by_default") @@ -55,3 +61,17 @@ async def test_updating_exception( await hass.async_block_till_done() assert hass.states.get("sensor.wordle_played").state != STATE_UNAVAILABLE + + +async def test_new_account( + hass: HomeAssistant, + mock_nyt_games_client: AsyncMock, + mock_config_entry: MockConfigEntry, +) -> None: + """Test handling an exception during update.""" + mock_nyt_games_client.get_latest_stats.return_value = WordleStats.from_json( + load_fixture("new_account.json", DOMAIN) + ).player.stats + await setup_integration(hass, mock_config_entry) + + assert hass.states.get("sensor.spelling_bee_played") is None