cdnninja/yoto_ha

1.12.0 authenticate error

Closed this issue · 11 comments

can't authenticate after updating to 1.12.0 via HACS

Log details (ERROR)
This error originated from a custom integration.
Logger: custom_components.yoto.coordinator
Source: helpers/update_coordinator.py:368
integration: Yoto ([documentation](https://github.com/cdnninja/yoto_ha), [issues](https://github.com/cdnninja/yoto_ha/issues))
First occurred: 10:38:37 AM (2 occurrences)
Last logged: 11:20:41 AM

Authentication failed while fetching yoto data: type object 'datetime.datetime' has no attribute 'datetime'
2024-05-29 11:20:41.212 ERROR (MainThread) [custom_components.yoto.coordinator] Authentication failed while fetching yoto data: type object 'datetime.datetime' has no attribute 'datetime'
2024-05-29 11:20:41.215 DEBUG (MainThread) [custom_components.yoto.coordinator] Finished fetching yoto data in 0.004 seconds (success: False)
2024-05-29 11:30:29.692 DEBUG (SyncWorker_9) [yoto_api.YotoAPI] yoto_api - Sign In Response dict_keys(['error', 'error_description'])
2024-05-29 11:30:29.695 ERROR (MainThread) [custom_components.yoto.config_flow] Unexpected exception
Traceback (most recent call last):
File "/config/custom_components/yoto/config_flow.py", line 104, in async_step_user
await validate_input(self.hass, user_input)
File "/config/custom_components/yoto/config_flow.py", line 45, in validate_input
await hass.async_add_executor_job(ym.check_and_refresh_token)
File "/usr/local/lib/python3.12/concurrent/futures/thread.py", line 58, in run
result = self.fn(*self.args, **self.kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/yoto_api/YotoManager.py", line 100, in check_and_refresh_token
self.initialize()
File "/usr/local/lib/python3.12/site-packages/yoto_api/YotoManager.py", line 28, in initialize
self.token: Token = self.api.login(self.username, self.password)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/yoto_api/YotoAPI.py", line 42, in login
seconds=response["expires_in"]
~~~~~~~~^^^^^^^^^^^^^^
KeyError: 'expires_in'

Odd. I have confirmed okay on my side. Can you reload integration and let me know if okay? Maybe it was an outage.

Reloading didn't throw an error, in fact it triggered lots of good MQTT calls, but the request to re-authenticate didn't go away.

I've attempted to re-authenticate as it requested, and it took quite some time. No errors in the log, and it eventually came up with a message that says "reauth_successful".

HA was still prompting me to re-auth, and clicking on the button generate a message: "Config flow could not be loaded: {"message":"Invalid flow specified"}".

Refreshing the page made the re-auth mesasge go away and it appears to be working properly.

Yoto may be having some issues as re-loading the integration now takes a lot longer than it used to.

This version added loading all card data. That takes a long time to run. Maybe home assistant doesn't like that.

I'll see if I can change that logic to be done after initial data is done. We don't need card, chapter or track details right away.

I assume you have a lot of cards?

Well, it's working fine for me now. It must have been something intermittent. Feel free to close the issue on that basis.

I don't have a ton of cards but some of my MYO have a LOT of tracks.
When I loaded it, the 42 seconds of waiting felt like an eternity ha!

2024-05-29 19:07:06.720 DEBUG (MainThread) [custom_components.yoto.coordinator] Finished fetching yoto data in 42.477 seconds (success: True)

From the debug log, the Get Device Response, Get Device, Get Device Config Response loop occurs twice. Maybe something there could be streamlined?

image

Yes it only current loads cards and tracks at startup and never refreshes. I figure people don't buy cards too often. One day I'll change that.

Let's keep this open. I see a few things this points out.

  1. Re auth flow isn't built yet in case of password change.
  2. Card loading can happen after startup. No need to hold things up while that's done.
  3. The duplicate calls are because it validates login followed by a data refresh. No sure I can fix that but I'll see.

I spoke too soon. Just got this:

Integration requires reconfiguration
At least one of your integrations requires reconfiguration to continue functioning. [Check it out](http://ha-dev.local:8123/config/integrations).

image

I assume you have a lot of cards?

About 25-30. I would call that a lot, but my partner says it's a perfectly reasonable amount...

I spoke too soon

Confirmed. Re-auth is back for me too. Looks like it happened within an hour of me last authorising.

I fixed the date time error the latest. I will dig into others in the future.

Just fixed it pulling card data on startup. Now it does it on first update scan so authentication can be confirmed to work quickly. Let me know if you see more issues. I haven't chased to re-auth flow build out yet but in theory you shouldn't see that error either now.

I've been running 1.12.1/2 since release and I haven't had to reauth since. Thank you.