Skip to content

Commit

Permalink
Merge pull request #22 from JackJPowell:multi-language-support
Browse files Browse the repository at this point in the history
Multi language support
  • Loading branch information
JackJPowell authored Nov 9, 2024
2 parents 8e84bed + 89e2ee1 commit 7f3a590
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
22 changes: 12 additions & 10 deletions custom_components/playstation_network/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"] = (
Expand All @@ -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()
)

Expand All @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion custom_components/playstation_network/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
6 changes: 3 additions & 3 deletions custom_components/playstation_network/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand Down

0 comments on commit 7f3a590

Please sign in to comment.