apetrycki / daikinskyport

API for accessing a DaikinOne+ Thermostat
59 stars 26 forks source link

Unable to request token Periodically #79

Closed LeaderbotX400 closed 8 months ago

LeaderbotX400 commented 8 months ago

I have noticed this issue has shown up in several other issues.

Steps tried:

2023-10-16 11:19:40.447 WARNING (SyncWorker_4) [homeassistant.loader] We found a custom integration daikinskyport which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you experience issues with Home Assistant
2023-10-16 11:20:14.571 ERROR (SyncWorker_6) [daikinskyport] Error while requesting tokens from daikinskyport.com. Status code: 400
2023-10-16 11:20:17.897 WARNING (SyncWorker_9) [daikinskyport] Could not refresh tokens: 400 Trying to re-request
2023-10-16 11:20:18.170 ERROR (SyncWorker_9) [daikinskyport] Error while requesting tokens from daikinskyport.com. Status code: 400
2023-10-16 11:20:18.173 ERROR (MainThread) [custom_components.daikinskyport] Error refreshing Daikin Skyport tokens
2023-10-16 11:20:21.280 ERROR (MainThread) [homeassistant.config_entries] Error setting up entry Daikin for daikinskyport
File "/config/custom_components/daikinskyport/__init__.py", line 161, in _async_update_data
current = await self.hass.async_add_executor_job(self.daikinskyport.update)
File "/config/custom_components/daikinskyport/daikinskyport.py", line 258, in update
File "/config/custom_components/daikinskyport/daikinskyport.py", line 171, in get_thermostats
raise ExpiredTokenError ("Daikin Skyport token expired")
custom_components.daikinskyport.daikinskyport.ExpiredTokenError: Daikin Skyport token expired
File "/config/custom_components/daikinskyport/__init__.py", line 79, in async_setup_entry
File "/config/custom_components/daikinskyport/__init__.py", line 165, in _async_update_data
await self.hass.async_add_executor_job(self.daikinskyport.update)
File "/config/custom_components/daikinskyport/daikinskyport.py", line 258, in update
File "/config/custom_components/daikinskyport/daikinskyport.py", line 171, in get_thermostats
raise ExpiredTokenError ("Daikin Skyport token expired")
custom_components.daikinskyport.daikinskyport.ExpiredTokenError: Daikin Skyport token expired
2023-10-16 11:28:48.273 DEBUG (MainThread) [custom_components.daikinskyport] Using email: accounts@singerfamily.ca
2023-10-16 11:28:51.619 DEBUG (MainThread) [custom_components.daikinskyport] Daikin Skyport tokens expired
2023-10-16 11:28:51.619 DEBUG (MainThread) [custom_components.daikinskyport] Refreshing Daikin Skyport tokens and updating config entry
2023-10-16 11:28:51.883 WARNING (SyncWorker_6) [daikinskyport] Could not refresh tokens: 400 Trying to re-request
2023-10-16 11:28:52.193 ERROR (SyncWorker_6) [daikinskyport] Error while requesting tokens from daikinskyport.com. Status code: 400
2023-10-16 11:28:52.196 ERROR (MainThread) [custom_components.daikinskyport] Error refreshing Daikin Skyport tokens
2023-10-16 11:28:55.312 ERROR (MainThread) [homeassistant.config_entries] Error setting up entry Daikin for daikinskyport
File "/config/custom_components/daikinskyport/__init__.py", line 161, in _async_update_data
current = await self.hass.async_add_executor_job(self.daikinskyport.update)
File "/config/custom_components/daikinskyport/daikinskyport.py", line 258, in update
File "/config/custom_components/daikinskyport/daikinskyport.py", line 171, in get_thermostats
raise ExpiredTokenError ("Daikin Skyport token expired")
custom_components.daikinskyport.daikinskyport.ExpiredTokenError: Daikin Skyport token expired
File "/config/custom_components/daikinskyport/__init__.py", line 79, in async_setup_entry
File "/config/custom_components/daikinskyport/__init__.py", line 165, in _async_update_data
await self.hass.async_add_executor_job(self.daikinskyport.update)
File "/config/custom_components/daikinskyport/daikinskyport.py", line 258, in update
File "/config/custom_components/daikinskyport/daikinskyport.py", line 171, in get_thermostats
raise ExpiredTokenError ("Daikin Skyport token expired")
custom_components.daikinskyport.daikinskyport.ExpiredTokenError: Daikin Skyport token expired
LeaderbotX400 commented 8 months ago

Issue persists every day, same error.

I have to resetup the integration every day in the morning so far because it is unable to request a token.

apetrycki commented 8 months ago

Have you checked to see if your thermostat is going offline? Another user had this issue and that was the reason.

I have added some additional debugging to the code.

Add debug to your configuration.yaml to show more info:

logger:
  default: error
  logs:
    custom_components.daikinskyport: debug
    daikinskyport: debug
    daikinskyport.daikin_set_thermostat_schedule: debug
    climate.daikinskyport: debug
LeaderbotX400 commented 8 months ago

Reviewing the logs this morning and it seems to not have an issue thus far. My thermostat seems to go unavalible on occasion so maybe that is overlapping when it requests a new token causing it to fail?

apetrycki commented 8 months ago

That would be my guess. There is an updated check in the latest version (I think I fixed it) to see if the device is offline which may have fixed it as well. Look through your logs and see if it says the device is offline anywhere.

apetrycki commented 8 months ago

I'm assuming since there's no update that this issue is closed.

otherwish commented 4 months ago

I think this issue might be related to what I am seeing. Currently have two Amana thermostats and all entities from both go offline once every hour then come back seconds later. Enabled debug and error logging and will update when I have more info.

otherwish commented 4 months ago

2024-02-19 12:36:31.307 DEBUG (SyncWorker_0) [daikinskyport] Error connecting to Daikin Skyport while attempting to get thermostat data. Status code: 401 Message: {"message":"Unauthorized"} 2024-02-19 12:36:31.308 DEBUG (MainThread) [custom_components.daikinskyport] Daikin Skyport tokens expired 2024-02-19 12:36:31.308 DEBUG (MainThread) [custom_components.daikinskyport] Refreshing Daikin Skyport tokens and updating config entry 2024-02-19 12:36:31.725 DEBUG (MainThread) [custom_components.daikinskyport] Update listener: 2024-02-19 12:36:31.725 DEBUG (MainThread) [custom_components.daikinskyport] Unload Entry: 2024-02-19 12:36:31.734 INFO (MainThread) [custom_components.daikinskyport] Daikin Skyport Starting 2024-02-19 12:36:31.734 DEBUG (MainThread) [custom_components.daikinskyport] Using email: REDACTED 2024-02-19 12:36:36.247 DEBUG (MainThread) [custom_components.daikinskyport] Daikin Skyport data updated successfully

Getting 401 Unauthorized then recovers

apetrycki commented 4 months ago

For now that is normal behavior. It happens when the token expires and the integration needs to request a new one. I haven't had a chance to look into why it goes offline

LeaderbotX400 commented 4 months ago

For now that is normal behavior. It happens when the token expires and the integration needs to request a new one. I haven't had a chance to look into why it goes offline

If this has a known interval for timeout, could the integration potentially request a new token before the old one expires?

No clue how this would affect the existing token