Add PlayStation Network Integration
Proposed change
This change adds support for integrating with the PlayStation Network. In this first release (my first HA PR), I have attempted to remove all unneeded code (no entity base class since I only have a single platform) but anticipate adding it, and refactoring elsewhere to follow home assistant conventions in subsequent pull requests. The integration contains a single platform (Media Player), is setup fully via the UI, supplies unique IDs, and attempts to follow all current Home Assistant best practices.
Type of change
- [ ] Dependency upgrade
- [ ] Bugfix (non-breaking change which fixes an issue)
- [x] New integration (thank you!)
- [ ] New feature (which adds functionality to an existing integration)
- [ ] Deprecation (breaking change to happen in the future)
- [ ] Breaking change (fix/feature causing existing functionality to break)
- [ ] Code quality improvements to existing code or addition of tests
Additional information
When reviewing this integration, please keep in mind that it represents a user on the playstation network and not the PlayStation console itself. It is structured around allowing the user to associate multiple PSN accounts and the device names are setup to match this. This integration started its life as a custom component and has about ~400 users. For a look at what this may evolve into, here is a link to the custom repository.
This initial release of the PlayStation Network Integration exposes a media player based on the user's registered systems with the playstation network. One will be created for any PS4 systems and another for any PS5 systems. However, due to api limitations, it is not possible to pull data for more than a single console at a time nor do I have dates for when a console was last active. Given these limitations I'd like to discuss what the Home Assistant team believes is the best course of action to take in this regard:
- Only a single system is reported as active. If a user is active on more than one, the one with the oldest action will be misrepresented in home assistant (reported as Off).
- The api does not provide date of last access information so the integration may be creating a media player for a PS4 that the user no longer owns.
- Since this integration is a representation of the user's account on the PlayStation Network, and not a PlayStation console device, does it make sense to expose a single PlayStation Console Media Player that contains the state of whatever currently active console the API is reporting?
A quality_scale.yaml file is included and I did my best to conform to all bronze level items. Some are marked as done, like common-modules, that still have pending tasks (the creation of entity.py for instance) but was skipped for this initial release. If this is the wrong approach, please let me know.
The integration communicates with the PlayStation Network via a supplied NPSSO token that the config flow walks the user through obtaining (along with the documentation referenced in PR#36520.
This integration relies on the PSNAWP project which was reversed engineered from the PlayStation Mobile app and is not endorsed or supported by Sony.
This PR wouldn't have been possible without the amazing help and guidance from @tr4nt0r. He put in so much time and effort to ensure this first PR go smoothly.
The associated brand images were included for the custom integration and are still up to date. Brands PR
Updates
After speaking with Joost, we decided to make a few changes to the submission:
- I've reached out to the owner of the PSNAWP library and he was excited about the library's use in HA and will be updating his dependencies to come inline with HAs. (He already has them updated but has not published the release yet. He agreed to do so before the end of May) 1.1) I also submitted two PRs to his repo to integrate a couple of changes/additions I added to my fork of his repo. One of which has already been merged.
- While we wait on the official library to be updated, I have published a new version of my fork that is mimicking the current state of PSNAWP library. (Dependency updated, PRs included, but without any of my custom changes) The intent being that once he publishes 2.3.0 of the official repo, all I should need to do is update my manifest to point to his library.
- This will allow for an earlier review of this PR as time allows. 3.1) helpers.py has been added which includes the bulk of what I was maintaining in my fork. 3.2) config_flow - parse_npsso_token got some requested updates in my PR and required a change + tests in the integration
- @tr4nt0r discovered that ps3 game status is returned on a different endpoint and I have added it to the supported platforms. Vita is close but media image is currently unavailable. 4.1) If this needs to be held for another PR, just let me know.
Checklist
- [x] The code change is tested and works locally.
- [x] Local tests pass. Your PR cannot be merged unless tests pass
- [x] There is no commented out code in this PR.
- [x] I have followed the development checklist
- [x] I have followed the perfect PR recommendations
- [x] The code has been formatted using Ruff (
ruff format homeassistant tests) - [x] Tests have been added to verify that the new code works.
If user exposed functionality or configuration variables are added/changed:
- [x] Documentation added/updated for www.home-assistant.io
If the code communicates with devices, web services, or third-party tools:
- [x] The manifest file has all fields filled out correctly.
Updated and included derived files by running:python3 -m script.hassfest. - [x] New or updated dependencies have been added to
requirements_all.txt.
Updated by runningpython3 -m script.gen_requirements_all. - [x] For the updated dependencies - a link to the changelog, or at minimum a diff between library versions is added to the PR description.
To help with the load of incoming pull requests:
- [ ] I have reviewed two other open pull requests in this repository.
Fix incoming!
Confirming that the Todoist tool is working as expected now in 1.2.4. Thanks for the quick fix and the awesome agent lib! ❤
Thanks for confirming!