Skip to content

Commit

Permalink
Trophy percent (#12)
Browse files Browse the repository at this point in the history
* add game trophy percentage

* bump version

* add game trophy percentage
  • Loading branch information
JackJPowell authored Aug 4, 2024
1 parent 40d2dbd commit bef486d
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 32 deletions.
50 changes: 36 additions & 14 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,58 @@
"postCreateCommand": ".devcontainer/setup",
"postAttachCommand": ".devcontainer/setup",
"forwardPorts": [8123],
"runArgs": ["-e", "GIT_EDITOR=code --wait"],
"containerEnv": {
"PYTHONASYNCIODEBUG": "1"
},
"customizations": {
"vscode": {
"extensions": [
"ms-python.python",
"ms-python.black-formatter",
"ms-python.isort",
"charliermarsh.ruff",
"ms-python.pylint",
"ms-python.vscode-pylance",
"visualstudioexptteam.vscodeintellicode",
"redhat.vscode-yaml",
"esbenp.prettier-vscode",
"github.vscode-pull-request-github",
"ryanluker.vscode-coverage-gutters"
"GitHub.vscode-pull-request-github",
"GitHub.copilot"
],
"settings": {
"files.eol": "\n",
"editor.tabSize": 4,
"python.pythonPath": "/usr/bin/python3",
"python.analysis.autoSearchPaths": false,
"python.formatting.provider": "black",
"python.experiments.optOutFrom": ["pythonTestAdapter"],
"python.defaultInterpreterPath": "/home/vscode/.local/ha-venv/bin/python",
"python.pythonPath": "/home/vscode/.local/ha-venv/bin/python",
"python.terminal.activateEnvInCurrentTerminal": true,
"python.testing.pytestArgs": ["--no-cov"],
"pylint.importStrategy": "fromEnvironment",
"editor.formatOnPaste": false,
"editor.formatOnSave": true,
"editor.formatOnType": true,
"editor.codeActionsOnSave": {
"source.organizeImports": true
"files.trimTrailingWhitespace": true,
"terminal.integrated.profiles.linux": {
"zsh": {
"path": "/usr/bin/zsh"
}
},
"terminal.integrated.defaultProfile.linux": "zsh",
"yaml.customTags": [
"!input scalar",
"!secret scalar",
"!include_dir_named scalar",
"!include_dir_list scalar",
"!include_dir_merge_list scalar",
"!include_dir_merge_named scalar"
],
"[python]": {
"editor.defaultFormatter": "charliermarsh.ruff",
"editor.formatOnSave": true
},
"files.trimTrailingWhitespace": true
"ruff.organizeImports": true
}
}
},
"remoteUser": "vscode",
"features": {
"rust": "latest"
"rust": "latest",
"ghcr.io/devcontainers/features/github-cli:1": {}
}
}
19 changes: 14 additions & 5 deletions custom_components/playstation_network/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@

from homeassistant.core import HomeAssistant
from homeassistant.exceptions import ConfigEntryAuthFailed
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
from homeassistant.helpers.update_coordinator import (
DataUpdateCoordinator,
UpdateFailed,
)
from psnawp_api.core.psnawp_exceptions import PSNAWPAuthenticationError

from .const import DEVICE_SCAN_INTERVAL, DOMAIN
Expand Down Expand Up @@ -59,7 +62,9 @@ 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 @@ -71,7 +76,9 @@ 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 @@ -83,7 +90,9 @@ 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(
self.data[
"title_details"
] = await self.hass.async_add_executor_job(
lambda: title.get_details()
)

Expand All @@ -97,7 +106,7 @@ async def _async_update_data(self) -> dict[str, Any]:
)

titles_with_stats = await self.hass.async_add_executor_job(
lambda: self.client.title_stats(limit=5)
lambda: self.client.title_stats(limit=3, page_size=3)
)
await self.hass.async_add_executor_job(
lambda: self.get_titles(titles_with_stats)
Expand Down
4 changes: 2 additions & 2 deletions 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.0.1"],
"requirements": ["PSNAWP-HA==2.1.0"],
"ssdp": [],
"version": "0.4.0"
"version": "0.5.0"
}
2 changes: 2 additions & 0 deletions custom_components/playstation_network/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ def get_status_attr(coordinator_data: any) -> dict[str, str]:
"silver": 0,
"bronze": 0,
},
"trophy_progress": 0,
}

title = coordinator_data.get("title_details")[0]
Expand All @@ -83,6 +84,7 @@ def get_status_attr(coordinator_data: any) -> dict[str, str]:
attrs["star_rating"] = title.get("starRating").get("score")
attrs["trophies"] = title_trophies.defined_trophies
attrs["earned_trophies"] = title_trophies.earned_trophies
attrs["trophy_progress"] = title_trophies.progress

for t in coordinator_data["recent_titles"]:
if t.title_id == coordinator_data.get("title_metadata").get("npTitleId"):
Expand Down
58 changes: 47 additions & 11 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,17 +1,53 @@
# Home Assistant
homeassistant>=2024.6.4
home-assistant-frontend

# Integration
PSNAWP-HA==2.0.1
homeassistant>=2024.7.4
home-assistant-frontend==20240719.0

# Development
black==24.4.2
colorlog==6.7.0
pip>=24.0
pylint>=3.0.3
ruff==0.4.4
rel~=0.4.9.6
requests~=2.32.3
voluptuous~=0.13.1
ha-ffmpeg
zeroconf~=0.131.0
websockets~=12.0
ha-ffmpeg==3.2.0
ruff>=0.5.3
PyTurboJPEG==1.7.1
aiodns==3.2.0
aiohttp==3.9.5
aiohttp_cors==0.7.0
aiohttp-fast-url-dispatcher==0.3.0
aiohttp-fast-zlib==0.1.1
aiozoneinfo==0.2.1
astral==2.2
async-interrupt==1.1.2
attrs==23.2.0
atomicwrites-homeassistant==1.4.1
awesomeversion==24.2.0
bcrypt==4.1.2
certifi>=2021.5.30
ciso8601==2.3.1
fnv-hash-fast==0.5.0
hass-nabucasa==0.81.1
httpx==0.27.0
home-assistant-bluetooth==1.12.2
ifaddr==0.2.0
Jinja2==3.1.4
lru-dict==1.3.0
PyJWT==2.8.0
cryptography==42.0.8
Pillow==10.3.0
pyOpenSSL==24.1.0
orjson==3.9.15
packaging>=23.1
pip>=21.3.1
psutil-home-assistant==0.0.1
python-slugify==8.0.4
PyYAML==6.0.1
requests==2.32.3
SQLAlchemy==2.0.31
typing-extensions>=4.12.2,<5.0
ulid-transform==0.9.0
urllib3>=1.26.5,<2
voluptuous==0.13.1
voluptuous-serialize==2.6.0
voluptuous-openapi==0.0.4
yarl==1.9.4

0 comments on commit bef486d

Please sign in to comment.