home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
72.69k stars 30.44k forks source link

Tuya Integration giving cross-region error #56873

Closed ZephireNZ closed 3 years ago

ZephireNZ commented 3 years ago

The problem

Unable to recreate Tuya integration with new setup. IoT platform set up as per instructions, but when I configure I get the error below.

My country code is 64, app is Tuya Smart, and validated these login details work in the old HA version. According to this Tuya doc I should be using America region which I am - specifically "Western America" looks to the region my devices are associated to in the IoT console.

What is version of Home Assistant Core has the issue?

core-2020.10.0b1

What was the last working version of Home Assistant Core?

core-2021.9.7

What type of installation are you running?

Home Assistant Container

Integration causing the issue

tuya

Link to integration documentation on our website

https://rc.home-assistant.io/integrations/tuya/

Example YAML snippet

No response

Anything in the logs that might be useful for us?

2021-10-01 19:30:22 DEBUG (SyncWorker_1) [homeassistant.components.tuya.config_flow] TuyaConfigFlow._try_login finish, response:, {'code': 2007, 'msg': 'your ip(x.x.x.x) cross-region access is not allowed', 'success': False, 't': 1633069822521}

Additional information

No response

probot-home-assistant[bot] commented 3 years ago

Hey there @tuya, mind taking a look at this issue as it has been labeled with an integration (tuya) you are listed as a code owner for? Thanks! (message by CodeOwnersMention)


tuya documentation tuya source (message by IssueLinks)

zlinoliver commented 3 years ago

@ZephireNZ Thanks for the feedbacks! To help us investigate the issue, could you help to provide more Home Assistant log to us? You can follow this tutorial to get the log: How to get thw log , thanks!

ZephireNZ commented 3 years ago

Hiya,

The logging mentioned above is the only thing logged. Using the below logger config, the below is all that shows in the log (IP masked as x.x.x.x for privacy):

2021-10-02 22:15:27 DEBUG (SyncWorker_5) [homeassistant.components.tuya.config_flow] TuyaConfigFlow._try_login finish, response:, {'code': 2007, 'msg': 'your ip(x.x.x.x) cross-region access is not allowed', 'success': False, 't': 1633166145543}

FYI your docs refer to the old logging name for custom component, I am using below logger config (I included the Tuya python modules just in case there was extra from them but no luck):

logger:
  default: critical
  logs:
    tuya_iot: debug
    tuya-iot-py-sdk: debug
    homeassistant.components.tuya: debug
    homeassistant.components.tuya.config_flow: debug

Settings I used: image

image

gadgetchnnel commented 3 years ago

I'm getting the same in the UK using a country code of 44. The page linked to above says that the UK is associated with the Europe availability region. However, I see two regions, Western Europe and Central Europe and my devices are under Central Europe.

axiom4 commented 3 years ago

Some issue here, from Tuya Developer platform Global error Codes (https://developer.tuya.com/en/docs/iot/error-code?id=K989ruxx88swc), 2007 is "device token expired".

gadgetchnnel commented 3 years ago

I've checked the code in the Tuya V2 custom integration against what has been released here, and found some code in config_flow.py in the custom component here:

https://github.com/tuya/tuya-home-assistant/blob/master/custom_components/tuya_v2/config_flow.py#L90

which is not present here:

https://github.com/home-assistant/core/blob/d3b1ccb66819988ec3131827bd2cdd649332b013/homeassistant/components/tuya/config_flow.py

That code uses either the China (https://openapi.tuyacn.com) or US (https://openapi.tuyaus.com) endpoints when logging on depending on whether the country code is China or not.

The code release in the beta here always uses the China endpoint.

I've tested this locally myself and it appears that it allows it to work for me in the UK.

ZephireNZ commented 3 years ago

Can confirm that above fix works for me too

zlinoliver commented 3 years ago

Thanks @ZephireNZ @gadgetchnnel for locating the issue, we have created another PR to help fix it, please check if it helps. https://github.com/home-assistant/core/pull/56973

StevusPrimus commented 3 years ago

Hey team, after upgrading to 2021.10.4, I still have the problem. image image image image image If I choose China the integration will not let me through. image Choosing Germany will fail in the above documented way.

ZephireNZ commented 3 years ago

It looks like your devices are registered in the China region, but you are in Germany.

If you check the Tuya app, what country is shown?

StevusPrimus commented 3 years ago

IMG_853EDD88CCEB-1 I am not sure how I can exactly check that, but it shows Germany in the app. Can I somehow do something to move it over?

ZephireNZ commented 3 years ago

@StevusPrimus you probably want to raise a new issue for this one, if you haven't sorted it

StevusPrimus commented 3 years ago

Yes, I migrated the devices into the smart life app. Now it works.