Skip to content
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

Can't fetch data when token expires #17

Open
3 tasks done
PatrikPihrt opened this issue Jan 2, 2025 · 2 comments
Open
3 tasks done

Can't fetch data when token expires #17

PatrikPihrt opened this issue Jan 2, 2025 · 2 comments
Assignees
Labels
Bug Something isn't working

Comments

@PatrikPihrt
Copy link

System Health details

System Information

version core-2024.12.5
installation_type Home Assistant OS
dev false
hassio true
docker true
user root
virtualenv false
python_version 3.13.0
os_name Linux
os_version 6.6.66-haos
arch x86_64
timezone Europe/Prague
config_dir /config
Home Assistant Community Store
GitHub API ok
GitHub Content ok
GitHub Web ok
HACS Data ok
GitHub API Calls Remaining 5000
Installed Version 2.0.1
Stage running
Available Repositories 1495
Downloaded Repositories 48
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 14.1
update_channel stable
supervisor_version supervisor-2024.12.0
agent_version 1.6.0
docker_version 27.2.0
disk_total 30.8 GB
disk_used 10.3 GB
healthy true
supported true
host_connectivity true
supervisor_connectivity true
ntp_synchronized true
virtualization kvm
board ova
supervisor_api ok
version_api ok
installed_addons Matter Server (6.6.1), Advanced SSH & Web Terminal (19.0.0), RTSPtoWeb - WebRTC (1.4.0), Studio Code Server (5.18.0), Samba share (12.3.2), ESPHome Device Builder (2024.12.2), Govee to MQTT Bridge (2025.01.01-ae1f0cc1), go2rtc (1.9.7)
Dashboards
dashboards 7
resources 35
views 26
mode storage
Recorder
oldest_recorder_run December 22, 2024 at 13:36
current_recorder_run December 31, 2024 at 15:49
estimated_db_size 444.70 MiB
database_engine sqlite
database_version 3.45.3
Sonoff
version 3.8.1 (ffa7e22)
cloud_online 2 / 2
local_online 2 / 2
Spotify
api_endpoint_reachable ok

Integration version ?

v1.3.7

In which region is your Petkit application registered?

France

Device type

All devices

Checklist

  • I have enabled debug logging for my installation.
  • This issue only contains 1 issue (if you have multiple issues, open one issue for each issue).
  • This issue is not a duplicate issue of any previous issues..

Describe the issue

I see that sometimes around 3am token expires and integration is not capable of recovering from it. It's not happening every day. Here are logs from the time when it happens:

2025-01-02 03:49:14.470 DEBUG (MainThread) [pypetkitapi.client] Token still OK, but refreshing session
2025-01-02 03:49:14.470 DEBUG (MainThread) [pypetkitapi.client] Refreshing session
2025-01-02 03:49:14.470 DEBUG (MainThread) [pypetkitapi.client] Request: POST https://api.eu-pet.com/latest/user/refreshsession
2025-01-02 03:49:14.594 DEBUG (MainThread) [pypetkitapi.client] List devices data for account: device_list=[] expired=False group_id=300309966 name='My Family' owner=200082375 pet_list=[] user_list=[User(avatar='https://sandbox-img5.petkit.cn/banner/2022/10/13/6347d75a44ad08000b011e7dDzwc693i5', created_at=1734865925390, is_owner=1, user_id=200082375, user_name='User010640')]
2025-01-02 03:49:14.594 DEBUG (MainThread) [pypetkitapi.client] List devices data for account: device_list=[Device(created_at=1730472947656, device_id=300009176, device_name='Snezenka Feeder', device_type='D4sh', group_id=300277568, type=25, type_code=0, unique_id='300009176-25'), Device(created_at=1733342269803, device_id=300010329, device_name='Konvalinka Feeder', device_type='D4sh', group_id=300277568, type=25, type_code=0, unique_id='300010329-25')] expired=False group_id=300277568 name='Patrik & Wendy' owner=200052532 pet_list=[Pet(avatar='https://img2.petkit.cn/dogavatar/111.png', created_at=1730494092650, pet_id=101066365, pet_name='Sněženka', id=101066365, sn='101066365', name='Sněženka', device_type='pet', firmware=None, last_litter_usage=0, last_device_used=None, last_duration_usage=0, last_measured_weight=0), Pet(avatar='https://img2.petkit.cn/dogavatar/111.png', created_at=1730494144209, pet_id=101066366, pet_name='Konvalinka', id=101066366, sn='101066366', name='Konvalinka', device_type='pet', firmware=None, last_litter_usage=0, last_device_used=None, last_duration_usage=0, last_measured_weight=0)] user_list=[User(avatar='https://sandbox-img5.petkit.cn/banner/2022/10/13/6347d75a44ad08000b011e7dDzwc693i5', created_at=1730472852480, is_owner=1, user_id=200052532, user_name='Patrik'), User(avatar='https://petkit-storage-image-prod-eu.oss-eu-central-1.aliyuncs.com/uavatar/2024/12/5/1733343034200071035', created_at=1733342964215, is_owner=0, user_id=200071035, user_name='Weninky'), User(avatar='https://sandbox-img5.petkit.cn/banner/2022/10/13/6347d75a44ad08000b011e7dDzwc693i5', created_at=1734866079624, is_owner=0, user_id=200082375, user_name='User010640')]
2025-01-02 03:49:14.594 DEBUG (MainThread) [pypetkitapi.client] Devices in account: [Device(created_at=1730472947656, device_id=300009176, device_name='Snezenka Feeder', device_type='D4sh', group_id=300277568, type=25, type_code=0, unique_id='300009176-25'), Device(created_at=1733342269803, device_id=300010329, device_name='Konvalinka Feeder', device_type='D4sh', group_id=300277568, type=25, type_code=0, unique_id='300010329-25')]
2025-01-02 03:49:14.594 DEBUG (MainThread) [pypetkitapi.client] Found 2 devices
2025-01-02 03:49:14.594 DEBUG (MainThread) [pypetkitapi.client] Reading device type : d4sh (id=300009176)
2025-01-02 03:49:14.595 DEBUG (MainThread) [pypetkitapi.client] Request: POST https://api.eu-pet.com/latest/d4sh/device_detail
2025-01-02 03:49:14.596 DEBUG (MainThread) [pypetkitapi.client] Reading device type : d4sh (id=300010329)
2025-01-02 03:49:14.596 DEBUG (MainThread) [pypetkitapi.client] Request: POST https://api.eu-pet.com/latest/d4sh/device_detail
2025-01-02 03:49:14.633 DEBUG (MainThread) [pypetkitapi.client] Device data fetched OK for d4sh
2025-01-02 03:49:14.702 DEBUG (MainThread) [pypetkitapi.client] Device data fetched OK for d4sh
2025-01-02 03:49:14.703 DEBUG (MainThread) [pypetkitapi.client] Reading device type : d4sh (id=300009176)
2025-01-02 03:49:14.703 DEBUG (MainThread) [pypetkitapi.client] Request: POST https://api.eu-pet.com/latest/d4sh/getDeviceRecord
2025-01-02 03:49:14.704 DEBUG (MainThread) [pypetkitapi.client] Reading device type : d4sh (id=300010329)
2025-01-02 03:49:14.704 DEBUG (MainThread) [pypetkitapi.client] Request: POST https://api.eu-pet.com/latest/d4sh/getDeviceRecord
2025-01-02 03:49:14.752 DEBUG (MainThread) [pypetkitapi.client] Device records fetched OK for d4sh
2025-01-02 03:49:14.761 DEBUG (MainThread) [pypetkitapi.client] Device records fetched OK for d4sh
2025-01-02 03:49:14.762 DEBUG (MainThread) [pypetkitapi.client] Petkit data fetched successfully in: 0:00:00.167693
2025-01-02 03:49:14.762 DEBUG (MainThread) [custom_components.petkit] Finished fetching petkit data in 0.292 seconds (success: True)
2025-01-02 03:49:44.470 DEBUG (MainThread) [pypetkitapi.client] Token expired, re-logging in
2025-01-02 03:49:44.470 DEBUG (MainThread) [pypetkitapi.client] Getting API server list
2025-01-02 03:49:44.470 DEBUG (MainThread) [pypetkitapi.client] Request: GET https://api.eu-pet.com/latest/v1/regionservers
2025-01-02 03:49:44.574 ERROR (MainThread) [custom_components.petkit] Error fetching petkit data: Request failed with status code 404
2025-01-02 03:49:44.574 DEBUG (MainThread) [custom_components.petkit] Finished fetching petkit data in 0.104 seconds (success: False)
2025-01-02 03:49:47.938 INFO (MainThread) [custom_components.hacs] Loading known repositories
2025-01-02 03:50:14.470 DEBUG (MainThread) [pypetkitapi.client] Token expired, re-logging in
2025-01-02 03:50:14.470 DEBUG (MainThread) [pypetkitapi.client] Getting API server list
2025-01-02 03:50:14.470 DEBUG (MainThread) [pypetkitapi.client] Request: GET https://api.eu-pet.com/latest/v1/regionservers
2025-01-02 03:50:14.579 DEBUG (MainThread) [custom_components.petkit] Finished fetching petkit data in 0.110 seconds (success: False)
2025-01-02 03:50:44.469 DEBUG (MainThread) [pypetkitapi.client] Token expired, re-logging in
2025-01-02 03:50:44.470 DEBUG (MainThread) [pypetkitapi.client] Getting API server list
2025-01-02 03:50:44.470 DEBUG (MainThread) [pypetkitapi.client] Request: GET https://api.eu-pet.com/latest/v1/regionservers
2025-01-02 03:50:44.568 DEBUG (MainThread) [custom_components.petkit] Finished fetching petkit data in 0.099 seconds (success: False)
2025-01-02 03:51:14.469 DEBUG (MainThread) [pypetkitapi.client] Token expired, re-logging in
2025-01-02 03:51:14.469 DEBUG (MainThread) [pypetkitapi.client] Getting API server list
2025-01-02 03:51:14.470 DEBUG (MainThread) [pypetkitapi.client] Request: GET https://api.eu-pet.com/latest/v1/regionservers
2025-01-02 03:51:14.579 DEBUG (MainThread) [custom_components.petkit] Finished fetching petkit data in 0.110 seconds (success: False)

Reproduction steps

  1. Wait for token to expire

Debug logs

Wait for token to expire. Workaround: Reload integration.

Diagnostics dump

home-assistant_2025-01-02T19-25-32.365Z.log

@PatrikPihrt PatrikPihrt added the Bug Something isn't working label Jan 2, 2025
@Jezza34000
Copy link
Owner

I reproduce same problem on my side.
I investigate this...

@Jezza34000
Copy link
Owner

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants