pantherale0 / ha-nintendoparentalcontrols

Home Assistant integration for Nintendo Switch Parental Controls
MIT License
69 stars 6 forks source link

Switch integrations sends updates every minute #100

Open sevorl opened 2 months ago

sevorl commented 2 months ago

System Health details

System Information

version core-2024.3.3
installation_type Home Assistant OS
dev false
hassio true
docker true
user root
virtualenv false
python_version 3.12.2
os_name Linux
os_version 6.1.73-haos-raspi
arch aarch64
timezone Europe/Berlin
config_dir /config
Home Assistant Community Store GitHub API | ok -- | -- GitHub Content | ok GitHub Web | ok GitHub API Calls Remaining | 5000 Installed Version | 1.34.0 Stage | running Available Repositories | 1484 Downloaded Repositories | 61
Home Assistant Cloud logged_in | false -- | -- can_reach_cert_server | ok can_reach_cloud_auth | ok can_reach_cloud | ok
Home Assistant Supervisor host_os | Home Assistant OS 12.1 -- | -- update_channel | stable supervisor_version | supervisor-2024.03.0 agent_version | 1.6.0 docker_version | 24.0.7 disk_total | 116.7 GB disk_used | 42.9 GB healthy | true supported | true board | rpi4-64 supervisor_api | ok version_api | ok installed_addons | Node-RED (17.0.10), File editor (5.8.0), Terminal & SSH (9.10.0), NGINX Home Assistant SSL proxy (3.9.0), Duck DNS (1.16.0), Home Assistant Google Drive Backup (0.112.1), Samba share (12.3.1), Bookstack (2.0.3), Nginx Proxy Manager (1.0.1), deCONZ (6.23.0), AdGuard Home (5.0.5), AppDaemon (0.16.4), Vaultwarden (Bitwarden) (0.21.2), ESPHome (2024.3.0), SQLite Web (4.1.2), Advanced SSH & Web Terminal (17.2.0), Mosquitto broker (6.4.0), phpMyAdmin (0.9.1), Cloudflared (5.1.7), MariaDB (2.6.1), Studio Code Server (5.15.0)
Dashboards dashboards | 6 -- | -- resources | 39 views | 42 mode | storage
Recorder oldest_recorder_run | 15. März 2024 um 06:44 -- | -- current_recorder_run | 24. März 2024 um 11:59 estimated_db_size | 1219.52 MiB database_engine | sqlite database_version | 3.44.2
Spotify api_endpoint_reachable | ok -- | --

Checklist

Nintendo Parental Controls mobile app

Describe the issue

On my phone, I get a notification every minute. It reads in German: "Switch (Altersbeschränkungen) - Die von dir festgelegten Altersbeschränkungen wurden auf Switch #1 übernommen" Translated: "Switch (age restrictions) - The age restrictions you set have been applied to Switch #1

This started tonight, after I installed the latest version 17.0.1

This seems to happen if the mobile app is configured to "set daiys individually". When I turn this switch off in the mobile app, the notifications seem to disappear.

Reproduction steps

  1. Update to 17.0.1
  2. in the mobile app, turn on "Set days individually"
  3. Nintendo parental control Smartphone app shows Notifications every Minute

Debug logs

Logger: pynintendoparental
Quelle: runner.py:188
Erstmals aufgetreten: 24. März 2024 um 16:29:08 (4 Vorkommnisse)
Zuletzt protokolliert: 09:16:52

Error updating device 5393090071dacc71: ('HTTP Exception', 'HTTP Error', 401)
Unable to update applications for device Switch #1: Application not found.

Diagnostics dump

No response

pantherale0 commented 2 months ago

Hi,

Please enable debug logs and send, not sure what could be causing this as the integration currently does not touch age restrictions

Thanks

bsc1576 commented 2 months ago

I have the same issue. It is not related to age restrictions but to time limits.

bsc1576 commented 2 months ago

Furthermore in my case the issue started yesterday, not right after the integration last upgrade. Therefore I suspect it could come from a change on Nintendo server side.

bsc1576 commented 2 months ago

This repeats every minute in the logs : 2024-04-02 07:06:29.651 DEBUG (MainThread) [pynintendoparental] >> Device._update_parental_control_setting()

FutureGUIs commented 2 months ago

I'm having the same issue and same pattern where it started sometime after an update. I've had to turn off for now unfortunately.

pantherale0 commented 2 months ago

This repeats every minute in the logs : 2024-04-02 07:06:29.651 DEBUG (MainThread) [pynintendoparental] >> Device._update_parental_control_setting()

Do you have any automations running? This isn't something I've experienced to be honest, but at the same time, I no longer even have the Nintendo app installed on my phone anymore.

pantherale0 commented 2 months ago

In fact, if all you are seeing in the debug logs is a call to Device._update_parental_control_setting() then the integration is actually working fine.

Its name isn't quite right, but its part of the updater functions that fetches the latest data from Nintendo. This integration is a polling based integration and by default will retrieve data every minute. This can be configured though in the configuration flow.

https://developers.home-assistant.io/docs/integration_fetching_data/#polling-api-endpoints

FutureGUIs commented 2 months ago

The problem is I get notifications every minute on my phone from the nintendo app saying the parental controls settings have been synced to my switches... so it's not just a problem on the HA side.

pantherale0 commented 2 months ago

I understand that, but need some complete debug logs to be able to pinpoint where the problem is. Its not something I've been able to replicate with a fresh HA install and new sign in on a phone.

C0teDeP0rc commented 2 months ago

I've been having this issue since the "Play Time Limit" was changed to a number. I updated my automation to set the time to 0 in the evening and reset it to 45 at 8:30 in the morning. After my automation set it to 0 the first evening, I got continuous notifications from the Nintendo Switch app on my phone. I never had this problem when using the old entity based on time rather than a number.

I'll see if I have time to check the logs, but I noticed that my automation was only triggered once.

Lastly, thank you for this integration. It makes my life easier to properly manage my son's playtime. The official app isn't comprehensive enough 👍.

pantherale0 commented 2 months ago

I've just released 2024.4.0, please can you try that?

Thanks

C0teDeP0rc commented 2 months ago

Thank you for this update. I quickly tested it last night and I still have the problem. It seems to only occur when I set the time to 0 minutes. But I didn't have time to do more tests. I'll see this weekend if I can conduct more thorough tests.

pantherale0 commented 2 months ago

@C0teDeP0rc ok, I set number.play_time_limit to 0 and enabled debug logging for the past hour. can't see any requests to update any data on the Nintendo side that I believe would trigger the notification, just requests to retrieve data:

2024-04-12 12:32:26.876 DEBUG (MainThread) [pynintendoparental] Received request to update data.
2024-04-12 12:32:26.876 DEBUG (MainThread) [pynintendoparental] Sending request to get_account_devices
2024-04-12 12:32:26.876 DEBUG (MainThread) [pynintendoparental] Built URL https://api-lp1.pctl.srv.nintendo.net/moon/v1/users/f589704b373c50e6/devices?filter.device.activated.$eq=true
2024-04-12 12:32:27.185 DEBUG (MainThread) [pynintendoparental] Request to https://api-lp1.pctl.srv.nintendo.net/moon/v1/users/f589704b373c50e6/devices?filter.device.activated.$eq=true status code 200
2024-04-12 12:32:27.187 DEBUG (MainThread) [pynintendoparental] Parsing device response
2024-04-12 12:32:27.187 DEBUG (MainThread) [pynintendoparental] Device init complete for None
2024-04-12 12:32:27.187 DEBUG (MainThread) [pynintendoparental] >> Device.update()
2024-04-12 12:32:27.187 DEBUG (MainThread) [pynintendoparental] >> Device._update_daily_summaries()
2024-04-12 12:32:27.187 DEBUG (MainThread) [pynintendoparental] Sending request to get_device_daily_summaries
2024-04-12 12:32:27.187 DEBUG (MainThread) [pynintendoparental] Built URL https://api-lp1.pctl.srv.nintendo.net/moon/v1/devices/58fd8d614befcacf/daily_summaries
2024-04-12 12:32:27.187 DEBUG (MainThread) [pynintendoparental] >> Device._update_parental_control_setting()
2024-04-12 12:32:27.187 DEBUG (MainThread) [pynintendoparental] Sending request to get_device_parental_control_setting
2024-04-12 12:32:27.187 DEBUG (MainThread) [pynintendoparental] Built URL https://api-lp1.pctl.srv.nintendo.net/moon/v1/devices/58fd8d614befcacf/parental_control_setting
2024-04-12 12:32:27.188 DEBUG (MainThread) [pynintendoparental] >> Device.get_monthly_summary(search_date=None)
2024-04-12 12:32:27.188 DEBUG (MainThread) [pynintendoparental] Sending request to get_device_monthly_summaries
2024-04-12 12:32:27.188 DEBUG (MainThread) [pynintendoparental] Built URL https://api-lp1.pctl.srv.nintendo.net/moon/v1/devices/58fd8d614befcacf/monthly_summaries
2024-04-12 12:32:27.188 DEBUG (MainThread) [pynintendoparental] >> Device._update_extras()
2024-04-12 12:32:27.188 DEBUG (MainThread) [pynintendoparental] Sending request to get_account_device
2024-04-12 12:32:27.188 DEBUG (MainThread) [pynintendoparental] Built URL https://api-lp1.pctl.srv.nintendo.net/moon/v1/users/f589704b373c50e6/devices/58fd8d614befcacf
2024-04-12 12:32:27.463 DEBUG (MainThread) [pynintendoparental] Request to https://api-lp1.pctl.srv.nintendo.net/moon/v1/users/f589704b373c50e6/devices/58fd8d614befcacf status code 200
2024-04-12 12:32:27.466 DEBUG (MainThread) [pynintendoparental] Set alarms enabled to state True for device 58fd8d614befcacf
2024-04-12 12:32:27.474 DEBUG (MainThread) [pynintendoparental] Request to https://api-lp1.pctl.srv.nintendo.net/moon/v1/devices/58fd8d614befcacf/daily_summaries status code 200

I wonder if Nintendo have changed something their side, and now the app sends a notification when something retrieves the data, if so there is nothing I can do about that. My personal recommendation is just to scrap the mobile app at this point as the all of (well what I consider) the core functionality is implemented in the integration, and use automations / schedules / calendars in Home Assistant to replace the functionality of what the mobile app would do.

bsc1576 commented 2 months ago

Thanks for all your efforts @pantherale0 ! I am convinced since the beginning that there has been a change in Nintendo server side and that there is not much to do about it, so I did not take the time to go through the code and the logs, instead I used a much simpler workaround : disabled notifications on the Nintendo app. I will nevertheless upgrade to your last version and check the behavior.

C0teDeP0rc commented 2 months ago

I don't think there has been a change on Nintendo's API side. I just went back to version 2024.2.0 (the version where minutes are determined through a time field, not a number) and I no longer have the problem. For now, I am sticking with this version. I encountered the problem when I moved from version 2024.2.0 to 2024.3.3. Finally, I checked the network traffic and I can indeed see traffic going to the Switch with each notification from the Android app. This shows that it is not trivial and that disabling notifications does not solve the problem of looping network traffic. If I have time, I will look at the code but I don't have experience in HA Python.

atrepca commented 1 month ago

I had the same issue where my Nintendo app would notify every minute when setting playtime to 0 from the integration.

The Nintendo app was showing "No limit" though, not 0 as expected (which kind of explains the integration's constant attempts to set it to 0 every minute).

I set the play time to 15 mins from the Nintendo app, then back to 0 from HA using the integration, and now the notifications stopped and everything is fine 🤷‍♂️

atrepca commented 1 month ago

Nevermind the above, I don't know how I managed to stop it. The Nintendo app spams every minute when the integration is set to 0 and I can't make it stop. If I set minutes to 1 it stops, but this changes the app to No Limit which I don't want.

Happy to help debug this if you need to try anything.

pantherale0 commented 1 month ago

I've been away from this integration for a little while after moving, apologies.

I still haven't been able to replicate this even on a new HA install / integration configuration. Bearing that in mind though, I have just released a new beta which strips out some functionality that wasn't ever implemented. Could anyone test this out and see if the notifications have gone please?

@atrepca the behaviour you are seeing in the mobile app ("No Limit" when set to play time limit is set to 1) is normal, its because the app only defines 15 minute intervals in the front end, yet the backend actually is granular enough to support each minute up to 6 hours.

atrepca commented 1 month ago

I downloaded version 2024.5.0b0 and it seems to be working fine so far, setting minutes to 0 from the integration doesn't trigger notifications every minute from the Nintendo app.

raldred commented 1 week ago

If you also then disable parental controls on the switch, it spams the switch every minute with "Settings have been synced" rather than something like "Daily play time limit has been changed"

This may not be related but when I set a small limit to test, 10 mins image

Nintento app shows "Not restricted" for today (Thursday) image

Switch shows 10 minutes (9 when i took shot) image