From 714a1cc31116e56dfcbab675708ec15fe989128f Mon Sep 17 00:00:00 2001 From: Joost Lekkerkerker Date: Mon, 23 Sep 2024 19:28:30 +0200 Subject: [PATCH] Bump nyt_games to 0.4.0 (#126564) --- homeassistant/components/nyt_games/config_flow.py | 4 ++-- homeassistant/components/nyt_games/coordinator.py | 2 +- homeassistant/components/nyt_games/entity.py | 4 +++- homeassistant/components/nyt_games/manifest.json | 2 +- requirements_all.txt | 2 +- requirements_test_all.txt | 2 +- tests/components/nyt_games/conftest.py | 7 ++++--- tests/components/nyt_games/test_config_flow.py | 4 ++-- 8 files changed, 15 insertions(+), 12 deletions(-) diff --git a/homeassistant/components/nyt_games/config_flow.py b/homeassistant/components/nyt_games/config_flow.py index b8687e58f72..fceeb5d13f1 100644 --- a/homeassistant/components/nyt_games/config_flow.py +++ b/homeassistant/components/nyt_games/config_flow.py @@ -24,7 +24,7 @@ class NYTGamesConfigFlow(ConfigFlow, domain=DOMAIN): session = async_get_clientsession(self.hass) client = NYTGamesClient(user_input[CONF_TOKEN], session=session) try: - latest_stats = await client.get_latest_stats() + user_id = await client.get_user_id() except NYTGamesAuthenticationError: errors["base"] = "invalid_auth" except NYTGamesError: @@ -32,7 +32,7 @@ class NYTGamesConfigFlow(ConfigFlow, domain=DOMAIN): except Exception: # noqa: BLE001 errors["base"] = "unknown" else: - await self.async_set_unique_id(str(latest_stats.user_id)) + await self.async_set_unique_id(str(user_id)) self._abort_if_unique_id_configured() return self.async_create_entry(title="NYT Games", data=user_input) return self.async_show_form( diff --git a/homeassistant/components/nyt_games/coordinator.py b/homeassistant/components/nyt_games/coordinator.py index 4234df2e0b1..d9e39ff814c 100644 --- a/homeassistant/components/nyt_games/coordinator.py +++ b/homeassistant/components/nyt_games/coordinator.py @@ -33,6 +33,6 @@ class NYTGamesCoordinator(DataUpdateCoordinator[Wordle]): async def _async_update_data(self) -> Wordle: try: - return (await self.client.get_latest_stats()).stats.wordle + return (await self.client.get_latest_stats()).wordle except NYTGamesError as error: raise UpdateFailed(error) from error diff --git a/homeassistant/components/nyt_games/entity.py b/homeassistant/components/nyt_games/entity.py index b5370805e27..eef1424d50b 100644 --- a/homeassistant/components/nyt_games/entity.py +++ b/homeassistant/components/nyt_games/entity.py @@ -15,7 +15,9 @@ class NYTGamesEntity(CoordinatorEntity[NYTGamesCoordinator]): def __init__(self, coordinator: NYTGamesCoordinator) -> None: """Initialize a NYT Games entity.""" super().__init__(coordinator) + unique_id = coordinator.config_entry.unique_id + assert unique_id is not None self._attr_device_info = DeviceInfo( - identifiers={(DOMAIN, str(coordinator.config_entry.unique_id))}, + identifiers={(DOMAIN, unique_id)}, manufacturer="New York Times", ) diff --git a/homeassistant/components/nyt_games/manifest.json b/homeassistant/components/nyt_games/manifest.json index 94a731c52a4..922a29a489b 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.3.0"] + "requirements": ["nyt_games==0.4.0"] } diff --git a/requirements_all.txt b/requirements_all.txt index 3257b170538..0d8cb385f4d 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -1484,7 +1484,7 @@ numato-gpio==0.13.0 numpy==1.26.0 # homeassistant.components.nyt_games -nyt_games==0.3.0 +nyt_games==0.4.0 # homeassistant.components.oasa_telematics oasatelematics==0.3 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index 5943e4b18aa..8fe9cbd42ff 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -1232,7 +1232,7 @@ numato-gpio==0.13.0 numpy==1.26.0 # homeassistant.components.nyt_games -nyt_games==0.3.0 +nyt_games==0.4.0 # homeassistant.components.google oauth2client==4.1.3 diff --git a/tests/components/nyt_games/conftest.py b/tests/components/nyt_games/conftest.py index 324327174f5..3165021bc5b 100644 --- a/tests/components/nyt_games/conftest.py +++ b/tests/components/nyt_games/conftest.py @@ -3,7 +3,7 @@ from collections.abc import Generator from unittest.mock import patch -from nyt_games.models import LatestData +from nyt_games.models import WordleStats import pytest from homeassistant.components.nyt_games.const import DOMAIN @@ -37,9 +37,10 @@ def mock_nyt_games_client() -> Generator[AsyncMock]: ), ): client = mock_client.return_value - client.get_latest_stats.return_value = LatestData.from_json( + client.get_latest_stats.return_value = WordleStats.from_json( load_fixture("latest.json", DOMAIN) - ).player + ).player.stats + client.get_user_id.return_value = 218886794 yield client diff --git a/tests/components/nyt_games/test_config_flow.py b/tests/components/nyt_games/test_config_flow.py index 0cdd22aa96e..144b3a3ad17 100644 --- a/tests/components/nyt_games/test_config_flow.py +++ b/tests/components/nyt_games/test_config_flow.py @@ -53,7 +53,7 @@ async def test_flow_errors( error: str, ) -> None: """Test flow errors.""" - mock_nyt_games_client.get_latest_stats.side_effect = exception + mock_nyt_games_client.get_user_id.side_effect = exception result = await hass.config_entries.flow.async_init( DOMAIN, @@ -70,7 +70,7 @@ async def test_flow_errors( assert result["type"] is FlowResultType.FORM assert result["errors"] == {"base": error} - mock_nyt_games_client.get_latest_stats.side_effect = None + mock_nyt_games_client.get_user_id.side_effect = None result = await hass.config_entries.flow.async_configure( result["flow_id"],