-
-
Notifications
You must be signed in to change notification settings - Fork 33.8k
Add new Nintendo Parental Controls integration #145343
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Add new Nintendo Parental Controls integration #145343
Conversation
Please run |
And please also add the link to the library source (github) to the PR description |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't mock the internals of the library, instead mock only the front-facing methods you access in the config flow
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I don't mock the internals of the library, the tests won't pass because:
- The authentication methods require valid responses from either a user input (and what is mocked is not valid), or the OAuth service itself.
- The verifier code is generated on each new instance of a config flow
- Data is needed inside the library itself to allow other functions to work (which will be more important for future PRs)
mock_request_handler.return_value = { | ||
"status": 400, | ||
"text": "ERROR", | ||
"json": {}, | ||
"headers": {"Content-Type": "application/json"}, | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just let the client raise instead of mocking the http request. Parametrize to also test the other exceptions.
mock_authenticator_client.complete_login.side_effect = InvalidSessionTokenException
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See my reply above, this won't work because of the validation done in the library.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did just attempt this again, tests fail -
2025-05-21 10:26:13.542 INFO MainThread homeassistant.setup:setup.py:394 Setting up nintendo_parental
2025-05-21 10:26:13.545 DEBUG MainThread pynintendoparental.authenticator:__init__.py:65 >> Init authenticator.
2025-05-21 10:26:13.545 DEBUG MainThread pynintendoparental.authenticator:__init__.py:135 Refreshing access token.
2025-05-21 10:26:13.546 DEBUG MainThread pynintendoparental:__init__.py:49 Received request to update data.
2025-05-21 10:26:13.547 DEBUG MainThread pynintendoparental:api.py:46 Sending request to get_account_devices
2025-05-21 10:26:13.547 DEBUG MainThread pynintendoparental:api.py:57 Built URL https://api-lp1.pctl.srv.nintendo.net/moon/v1/users/aabbccddee112233/devices?filter.device.activated.$eq=true
2025-05-21 10:26:13.573 ERROR MainThread homeassistant.components.nintendo_parental.coordinator:update_coordinator.py:451 Unexpected error fetching nintendo_parental data
Traceback (most recent call last):
File "/home/jordan/Documents/repos/home-assistant/homeassistant/helpers/update_coordinator.py", line 380, in _async_refresh
self.data = await self._async_update_data()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/jordan/Documents/repos/home-assistant/homeassistant/components/nintendo_parental/coordinator.py", line 58, in _async_update_data
return await self.api.update()
^^^^^^^^^^^^^^^^^^^^^^^
File "/home/jordan/Documents/repos/home-assistant/venv/lib64/python3.13/site-packages/pynintendoparental/__init__.py", line 50, in update
await self._get_devices()
File "/home/jordan/Documents/repos/home-assistant/venv/lib64/python3.13/site-packages/pynintendoparental/__init__.py", line 33, in _get_devices
response = await self._api.send_request(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...<2 lines>...
)
^
File "/home/jordan/Documents/repos/home-assistant/venv/lib64/python3.13/site-packages/pynintendoparental/api.py", line 78, in send_request
async with session.request(
~~~~~~~~~~~~~~~^
method=e_point.get("method"),
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
url=url,
^^^^^^^^
json=body
^^^^^^^^^
) as response:
^
File "/home/jordan/Documents/repos/home-assistant/venv/lib64/python3.13/site-packages/aiohttp/client.py", line 1425, in __aenter__
self._resp: _RetType = await self._coro
^^^^^^^^^^^^^^^^
File "/home/jordan/Documents/repos/home-assistant/venv/lib64/python3.13/site-packages/aiohttp/client.py", line 703, in _request
conn = await self._connector.connect(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
req, traces=traces, timeout=real_timeout
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
)
^
File "/home/jordan/Documents/repos/home-assistant/venv/lib64/python3.13/site-packages/aiohttp/connector.py", line 548, in connect
proto = await self._create_connection(req, traces, timeout)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/jordan/Documents/repos/home-assistant/venv/lib64/python3.13/site-packages/aiohttp/connector.py", line 1056, in _create_connection
_, proto = await self._create_direct_connection(req, traces, timeout)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/jordan/Documents/repos/home-assistant/venv/lib64/python3.13/site-packages/aiohttp/connector.py", line 1375, in _create_direct_connection
transp, proto = await self._wrap_create_connection(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...<7 lines>...
)
^
File "/home/jordan/Documents/repos/home-assistant/venv/lib64/python3.13/site-packages/aiohttp/connector.py", line 1115, in _wrap_create_connection
sock = await aiohappyeyeballs.start_connection(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...<5 lines>...
)
^
File "/home/jordan/Documents/repos/home-assistant/venv/lib64/python3.13/site-packages/aiohappyeyeballs/impl.py", line 127, in start_connection
raise first_exception
File "/home/jordan/Documents/repos/home-assistant/venv/lib64/python3.13/site-packages/aiohappyeyeballs/_staggered.py", line 132, in run_one_coro
result = await coro_fn()
^^^^^^^^^^^^^^^
File "/home/jordan/Documents/repos/home-assistant/venv/lib64/python3.13/site-packages/aiohappyeyeballs/impl.py", line 183, in _connect_sock
sock = socket.socket(family=family, type=type_, proto=proto)
File "/home/jordan/Documents/repos/home-assistant/venv/lib64/python3.13/site-packages/pytest_socket.py", line 89, in __new__
raise SocketBlockedError()
pytest_socket.SocketBlockedError: A test tried to use socket.socket.
2025-05-21 10:26:13.578 DEBUG MainThread homeassistant.components.nintendo_parental.coordinator:update_coordinator.py:460 Finished fetching nintendo_parental data in 0.032 seconds (success: False)
2025-05-21 10:26:13.578 DEBUG MainThread homeassistant.config_entries:config_entries.py:802 Config entry 'aabbccddee112233' for nintendo_parental integration not ready yet: A test tried to use socket.socket.; Retrying in 5 seconds
2025-05-21 10:26:13.581 DEBUG MainThread homeassistant.core:core.py:1546 Bus:Handling <Event component_loaded[L]: component=nintendo_parental>
tests/components/nintendo_parental/test_config_flow.py::test_invalid_api_token ⨯ 75% ███████▌
tests/components/nintendo_parental/test_config_flow.py::test_general_error ✓ 100% ██████████
---------- coverage: platform linux, python 3.13.3-final-0 -----------
Name Stmts Miss Cover Missing
-----------------------------------------------------------------------------------------
homeassistant/components/nintendo_parental/__init__.py 22 7 68% 31-34, 39-41, 48
homeassistant/components/nintendo_parental/config_flow.py 27 1 96% 38
homeassistant/components/nintendo_parental/const.py 3 0 100%
homeassistant/components/nintendo_parental/coordinator.py 27 1 96% 60
homeassistant/components/nintendo_parental/entity.py 16 16 0% 3-34
homeassistant/components/nintendo_parental/sensor.py 33 33 0% 3-102
-----------------------------------------------------------------------------------------
TOTAL 128 58 55%
================================================================================================================================ short test summary info =================================================================================================================================
FAILED tests/components/nintendo_parental/test_config_flow.py::test_invalid_api_token - AssertionError: assert <FlowResultType.CREATE_ENTRY: 'create_entry'> is <FlowResultType.FORM: 'form'>
+ where <FlowResultType.FORM: 'form'> = FlowResultType.FORM
Results (1.69s):
3 passed
1 failed
- tests/components/nintendo_parental/test_config_flow.py:65 test_invalid_api_token
mock_request_handler.return_value = { | ||
"status": 200, | ||
"text": "OK", | ||
"json": { | ||
"session_token": "valid_token", | ||
"expires_in": 3500, | ||
"id": "aabbccddee112233", | ||
"name": "Home Assistant Tester", | ||
}, | ||
"headers": {"Content-Type": "application/json"}, | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and to clear the exception...
mock_authenticator_client.complete_login.side_effect = None
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As above
Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍 |
Thanks both for your reviews and feedback. I think we might be close now? Only thing left that is outstanding is regarding patching internals. |
This can be marked as a draft again - adding some further tests and changing how the python module handles API calls so internals don't need to be patched (pantherale0/pynintendoparental#29) |
…ntendo parental controls integration
Co-authored-by: Manu <4445816+tr4nt0r@users.noreply.github.com>
Co-authored-by: Manu <4445816+tr4nt0r@users.noreply.github.com>
Co-authored-by: Manu <4445816+tr4nt0r@users.noreply.github.com>
Co-authored-by: Manu <4445816+tr4nt0r@users.noreply.github.com>
Co-authored-by: Manu <4445816+tr4nt0r@users.noreply.github.com>
Co-authored-by: Manu <4445816+tr4nt0r@users.noreply.github.com>
Co-authored-by: Manu <4445816+tr4nt0r@users.noreply.github.com>
Co-authored-by: Manu <4445816+tr4nt0r@users.noreply.github.com>
Co-authored-by: Manu <4445816+tr4nt0r@users.noreply.github.com>
Co-authored-by: Manu <4445816+tr4nt0r@users.noreply.github.com>
Co-authored-by: Manu <4445816+tr4nt0r@users.noreply.github.com>
Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
1ee9218
to
56ae08b
Compare
Breaking change
Proposed change
This PR adds a new Nintendo Parental Controls integration, at the moment this is very basic, however future PRs will update the integration to support the platforms and features available in my custom integration (https://github.com/pantherale0/ha-nintendoparentalcontrols)
Library: https://github.com/pantherale0/pynintendoparental
Type of change
Additional information
Checklist
ruff format homeassistant tests
)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest
.requirements_all.txt
.Updated by running
python3 -m script.gen_requirements_all
.To help with the load of incoming pull requests: