jbergler / hass-ttlock

Home Assistant integration for TTLock locks
54 stars 12 forks source link

Error fetching ttlock data: API returned: {'errcode': 10004, 'errmsg': 'invalid grant', 'description': 'token无授权,token已失效或被撤销授权'} #54

Closed luisgarcia87 closed 1 year ago

luisgarcia87 commented 1 year ago

Describe the bug

I am unable to use the app due to the following message: Error fetching ttlock data: API returned: {'errcode': 10004, 'errmsg': 'invalid grant', 'description': 'token无授权,token已失效或被撤销授权'}

Im guessing the authorization token has expired and I have to refresh that information. Is there a way to update it without deleting the integration and re-adding it again?

To Reproduce

Steps to reproduce the behavior:

As soon as the integration starts the error appear on the logs

Expected behavior

Integration just starts without any input from the user.

Diagnostic info

The three dots are not showing up on the integration page.

Error setting up entry Front Door TT Lock for ttlock Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/config_entries.py", line 387, in async_setup result = await component.async_setup_entry(hass, self) File "/config/custom_components/ttlock/__init__.py", line 68, in async_setup_entry for lock_id in await client.get_locks() File "/config/custom_components/ttlock/api.py", line 124, in get_locks res = await self.get("lock/list", pageNo=1, pageSize=1000) File "/config/custom_components/ttlock/api.py", line 107, in get return await self._parse_resp(resp, log_id) File "/config/custom_components/ttlock/api.py", line 92, in _parse_resp raise RequestFailed(f"API returned: {res}") custom_components.ttlock.api.RequestFailed: API returned: {'errcode': 10004, 'errmsg': 'invalid grant', 'description': 'token无授权,token已失效或被撤销授权'}

luisgarcia87 commented 1 year ago

Never mind solved by calling TTLock API to refresh my access token https://euopen.ttlock.com/document/doc?urlName=cloud%2Foauth2%2FrefreshAccessTokenEn.html It says on the documentation

When access token expired, you can refresh it by this api, the refresh_token is returned by Get Access Token, the valid period of refresh token is 10 years since it's created.

But in reality the response from the server says that the token expires in 7776000 (guessing that's seconds) so that equals to 90 days.