apetrycki / daikinskyport

API for accessing a DaikinOne+ Thermostat
62 stars 27 forks source link

AttributeError: 'DaikinSkyport' object has no attribute 'user_password' #39

Closed lujkas closed 1 year ago

lujkas commented 2 years ago

Started receiving below error message when I restarted HA a few days ago. I removed the custom_components/daikinskyport directory and re-installed via HACS but still getting same error.

Notification:

The following integrations and platforms could not be set up:

daikinskyport Please check your config and logs.

Log Details (ERROR) This error originated from a custom integration. Logger: homeassistant.setup Source: custom_components/daikinskyport/daikinskyport.py:85 Integration: daikinskyport (documentation, issues) First occurred: 11:57:05 AM (1 occurrences) Last logged: 11:57:05 AM

Error during setup of component daikinskyport Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/setup.py", line 229, in _async_setup_component result = await task File "/usr/local/lib/python3.9/concurrent/futures/thread.py", line 52, in run result = self.fn(*self.args, **self.kwargs) File "/config/custom_components/daikinskyport/init.py", line 72, in setup data = DaikinSkyportData(hass.config.path(DAIKINSKYPORT_CONFIG_FILE)) File "/config/custom_components/daikinskyport/init.py", line 49, in init self.daikinskyport = DaikinSkyport(config_file) File "/config/custom_components/daikinskyport/daikinskyport.py", line 78, in init self.update() File "/config/custom_components/daikinskyport/daikinskyport.py", line 223, in update self.get_thermostats() File "/config/custom_components/daikinskyport/daikinskyport.py", line 148, in get_thermostats if self.refresh_tokens(): File "/config/custom_components/daikinskyport/daikinskyport.py", line 117, in refresh_tokens self.request_tokens() File "/config/custom_components/daikinskyport/daikinskyport.py", line 85, in request_tokens data = {"email": self.user_email, "password": self.user_password} AttributeError: 'DaikinSkyport' object has no attribute 'user_password'

knightjoel commented 2 years ago

This would hint the password wasn't read from the config file. Did you configure email and password as per the README, ensuring all whitespace is correct and there are no typos?

lujkas commented 2 years ago

Yeah I did configure it as per the readme and haven't touched it in months.

lujkas commented 2 years ago

It had to do with daikinskyport.conf. I deleted it and restarted HA. daikinskyport.conf got created automatically and I didn't receive any error message this time but the entities were still not available. One more restart and everything seems to work now. Closing the issue.

knightjoel commented 2 years ago

I just hit this issue.

I extracted the refreshToken value from daikinskyport.conf and used Postman to send the call to refresh my token. I received a 400 response (body had a message NotAuthorizedException). It seems that for whatever reason, my session was invalidated or just expired.

What happens in this situation is refresh_tokens() is called when the component starts because using the existing token causes an error to be returned by the API when gathering the list of thermostats. refresh_tokens() gets an error response when trying to renew the token and kicks out to request_tokens(). request_tokens() tries to send the user's email and password to the authentication endpoint but self.user_password isn't set because the password is never written to daikinskyport.conf that's where the component's configuration is loaded from. And that's where the AttributeError exception is thrown.

It looks like there is indeed a bug here. Unfortunately, I don't have cycles to fix this right now but wanted to document what I saw.

@lujkas would you mind reopening this issue so we can track this?

hume-github commented 1 year ago

I can confirm that nuking daikinskyport.conf and restarting - without changing anything in the configuration, although I was upgrading HA when I ran into this problem - cured this just now for me.

Perhaps the API key expired and the integration chokes on renewing it on a restart?

chrismaki commented 1 year ago

I lost access to my Thermostat after an upgrade-induced reboot, same error message. I renamed my old daikinskyport.conf, restarted and it got recreated. Now the integration started, but the thermostat was still unavailable. Another restart and the thermostat is once again available.

Oddly enough, I had to re-login to the iOS Daikin app as well, so I wonder if the access token expires across platforms at the same time?

apetrycki commented 1 year ago

They may have made a change that required them to refresh all API tokens. The issue with the password not being stored in the config is an easy thing to fix, but the integration really needs a facelift to allow configuration through the HA interface, which would also solve this problem. I just haven't had a chance to make that update since it's a pretty big overhaul. I don't really like the idea of storing the password in the config file.

SuzakuTheKnight commented 1 year ago

They may have made a change that required them to refresh all API tokens. The issue with the password not being stored in the config is an easy thing to fix, but the integration really needs a facelift to allow configuration through the HA interface, which would also solve this problem. I just haven't had a chance to make that update since it's a pretty big overhaul. I don't really like the idea of storing the password in the config file.

+1 vote to not storing passwords in the main configuration.yaml. It would seem that application credentials would be the better place for this. Extremely happy to have this integration! Kudos to all the work on this so far!

christoftaylor commented 1 year ago

+1 vote to not storing passwords in the main configuration.yaml. It would seem that application credentials would be the better place for this. Extremely happy to have this integration! Kudos to all the work on this so far!

There is a mechanism for this. Passwords that need to be embedded in configuration.yaml should be stored in secrets.yaml instead. Still not completely ideal, but is better than directly in configuration.yaml.

Here's the relevant documentation: https://www.home-assistant.io/docs/configuration/secrets/

apetrycki commented 1 year ago

This issue should be resolved with the new ui config flow