From 8fe0452a48ce838535d49c575ad4f0be09b6246e Mon Sep 17 00:00:00 2001 From: Jack Powell Date: Sat, 9 Nov 2024 16:17:03 -0500 Subject: [PATCH 1/3] bump psnawp dependency --- custom_components/playstation_network/manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/custom_components/playstation_network/manifest.json b/custom_components/playstation_network/manifest.json index ae7dfe9..982f7ff 100644 --- a/custom_components/playstation_network/manifest.json +++ b/custom_components/playstation_network/manifest.json @@ -9,7 +9,7 @@ "integration_type": "device", "iot_class": "cloud_polling", "issue_tracker": "https://github.com/JackJPowell/hass-psn/issues", - "requirements": ["PSNAWP-HA==2.1.2"], + "requirements": ["PSNAWP-HA==2.2.0"], "ssdp": [], "version": "0.6.0" } From b493df9f3c181df7025454f70484b6328148abb6 Mon Sep 17 00:00:00 2001 From: Jack Powell Date: Sat, 9 Nov 2024 16:17:36 -0500 Subject: [PATCH 2/3] correct earned trophy error --- custom_components/playstation_network/sensor.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/custom_components/playstation_network/sensor.py b/custom_components/playstation_network/sensor.py index 31825e5..1223510 100644 --- a/custom_components/playstation_network/sensor.py +++ b/custom_components/playstation_network/sensor.py @@ -300,7 +300,7 @@ def get_trophy_attr(coordinator_data: any) -> dict[str, str]: entity_registry_enabled_default=True, has_entity_name=True, unique_id="psn_trophy_platinum_earned_attr", - value_fn=lambda data: data.get("earned_trophies").get("bronze"), + value_fn=lambda data: data.get("earned_trophies").get("platinum"), ), PsnSensorEntityDescription( key="trophy_gold_earned", @@ -310,7 +310,7 @@ def get_trophy_attr(coordinator_data: any) -> dict[str, str]: entity_registry_enabled_default=True, has_entity_name=True, unique_id="psn_trophy_gold_earned_attr", - value_fn=lambda data: data.get("earned_trophies").get("bronze"), + value_fn=lambda data: data.get("earned_trophies").get("gold"), ), PsnSensorEntityDescription( key="trophy_silver_earned", @@ -320,7 +320,7 @@ def get_trophy_attr(coordinator_data: any) -> dict[str, str]: entity_registry_enabled_default=True, has_entity_name=True, unique_id="psn_trophy_silver_earned_attr", - value_fn=lambda data: data.get("earned_trophies").get("bronze"), + value_fn=lambda data: data.get("earned_trophies").get("silver"), ), PsnSensorEntityDescription( key="trophy_bronze_earned", From 89e2ee1145cd4fa743119aa87dd75fd99b6d79d2 Mon Sep 17 00:00:00 2001 From: Jack Powell Date: Sat, 9 Nov 2024 16:18:19 -0500 Subject: [PATCH 3/3] add support for additional languages --- .../playstation_network/coordinator.py | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/custom_components/playstation_network/coordinator.py b/custom_components/playstation_network/coordinator.py index 02f7d91..1634822 100644 --- a/custom_components/playstation_network/coordinator.py +++ b/custom_components/playstation_network/coordinator.py @@ -62,9 +62,7 @@ async def _async_update_data(self) -> dict[str, Any]: == "availableToPlay" ) self.data["platform"] = ( - self.data["presence"] - .get("basicPresence") - .get("primaryPlatformInfo") + self.data["presence"].get("basicPresence").get("primaryPlatformInfo") ) try: self.data["title_metadata"] = ( @@ -76,9 +74,7 @@ async def _async_update_data(self) -> dict[str, Any]: self.data["title_metadata"] = {} # self.data["friends"] = await self.client.available_to_play() - self.data[ - "trophy_summary" - ] = await self.hass.async_add_executor_job( + self.data["trophy_summary"] = await self.hass.async_add_executor_job( lambda: self.client.trophy_summary() ) @@ -90,11 +86,17 @@ async def _async_update_data(self) -> dict[str, Any]: title = await self.hass.async_add_executor_job( lambda: self.api.game_title(title_id, "me") ) - self.data[ - "title_details" - ] = await self.hass.async_add_executor_job( - lambda: title.get_details() + ## Attempt to pull details with user's country and language code + self.data["title_details"] = await self.hass.async_add_executor_job( + lambda: title.get_details( + self.hass.config.country, self.hass.config.language + ) ) + ## If we receive an error, fall back to english + if self.data["title_details"][0].get("errorCode") is not None: + self.data["title_details"] = await self.hass.async_add_executor_job( + lambda: title.get_details() + ) trophy_titles = await self.hass.async_add_executor_job( lambda: self.client.trophy_titles_for_title(