From 8d428acbbba3d770e91fbfb7241cf19de318d618 Mon Sep 17 00:00:00 2001
From: Joost Lekkerkerker <joostlek@outlook.com>
Date: Thu, 26 Sep 2024 18:03:11 +0200
Subject: [PATCH] Bump nyt_games to 0.4.2 (#126834)

* Bump nyt_games to 0.4.1

* Bump nyt_games to 0.4.1

* Bump nyt_games to 0.4.2
---
 .../components/nyt_games/coordinator.py       |  2 +-
 .../components/nyt_games/manifest.json        |  2 +-
 homeassistant/components/nyt_games/sensor.py  | 10 ++--
 requirements_all.txt                          |  2 +-
 requirements_test_all.txt                     |  2 +-
 .../nyt_games/fixtures/new_account.json       | 51 +++++++++++++++++++
 .../nyt_games/snapshots/test_sensor.ambr      |  4 +-
 tests/components/nyt_games/test_sensor.py     | 24 ++++++++-
 8 files changed, 85 insertions(+), 12 deletions(-)
 create mode 100644 tests/components/nyt_games/fixtures/new_account.json

diff --git a/homeassistant/components/nyt_games/coordinator.py b/homeassistant/components/nyt_games/coordinator.py
index 75aa79f62ba..3b695574750 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 922a29a489b..1cdc5988e38 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 6e243a908b4..6e19a4c21dc 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 f67bcc08fae..0ed8a3da84e 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 5f2a645c552..d08378b37cb 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 00000000000..ad4d8e2e416
--- /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 7c4c2b57253..fdec7d58d9d 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 3866b6afab0..f35caf20b57 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
-- 
GitLab