milo526 / homebridge-tuya-web

Hoobs and Homebridge plugin for Tuya devices using Home Assistant Tuya Web Api
MIT License
217 stars 93 forks source link

[TuyaWebPlatform] Authentication error: you cannot auth exceed once in 180 seconds #536

Closed rmfalco89 closed 1 year ago

rmfalco89 commented 1 year ago

I get [TuyaWebPlatform] Authentication error: you cannot auth exceed once in 180 seconds

After which, the plugin doesn't try to re-authenticate, as far as I can tell. At least not in a short time span (i.e. minutes, not hours). As a consequence the tuya accessories are not operable through homebridge.

Steps To Reproduce I am not entirely sure what the steps would be, other than a frequent restart of homebridge as I am developing on it.

Plugin Version v1.1.3

Homebridge Config

        {
            "name": "TuyaWebPlatform",
            "options": {
                "username": REDACTED,
                "password": REDACTED,
                "countryCode": "1",
                "platform": "smart_life"
            },
            "defaults": [
                {
                    "id": "d63fb462-a193-4a90-a24b-f3705990a0f9",
                    "device_type": "switch"
                }
            ],
            "scenes": false,
            "_bridge": {
                "username": "0E:BE:65:C9:D3:A1",
                "port": 50405
            },
            "platform": "TuyaWebPlatform"
        },

Device Config N/A as it's not a problem with any device, it's a problem with tuya authentication

Additional Context I think that the problem comes from https://github.com/milo526/homebridge-tuya-web/blob/9ba39bd8fccb94a5fc24b2367e088b241e069d53/src/api/service.ts#L198

Here you check for an exact error match. I am not sure whether they changed the Tuya API behavior in terms of error string returned, but now I'm seeing 180 instead of 60 in that same error string (as per title of this Issue).

Something I didn't get to understand is why throwing an error if there isn't a valid token, rather than getting a new one or refreshing it. E.g. here: https://github.com/milo526/homebridge-tuya-web/blob/9ba39bd8fccb94a5fc24b2367e088b241e069d53/src/api/service.ts#L41

This is more for my personal understanding than anything else.

I also have a potential fix ready. Sorry I don't speak typescript or javascript and I'm sure my fix sucks but I hope it gives you a good pointer and a potential solution to a more general problem with authentication. I'll link the PR here as soon as I can test it out.

Thanks!!

jjeaton commented 1 year ago

I run into this same issue frequently

rmfalco89 commented 1 year ago

https://github.com/milo526/homebridge-tuya-web/pull/537/files

rmfalco89 commented 1 year ago

@jjeaton

I run into this same issue frequently

Can you please try out my fix? https://github.com/milo526/homebridge-tuya-web/pull/537

Let me know if you need help on how to do that. You'll need to get my branch, build the plugin, install it in your homebridge's directory and restart homebridge

github-actions[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.