Browse Source

feat(config_flow): add fresh login option for cloud setup

- Introduced a new "cloud_fresh_login" setup mode to allow users to log in
  with a new account during cloud-assisted device setup.
- Added a logout method in the Cloud class to clear authentication cache
  and reset credentials.
- Updated translations across all supported languages to include the new
  setup mode option.

Issue #2778
Jason Rumney 6 months ago
parent
commit
ddb4cc7199

+ 8 - 0
custom_components/tuya_local/cloud.py

@@ -116,6 +116,7 @@ class Cloud:
             self.__error_msg = info.get(TUYA_RESPONSE_MSG, "Unknown error")
             self.__error_msg = info.get(TUYA_RESPONSE_MSG, "Unknown error")
             # Ensure expired authentication is cleared on next attempt
             # Ensure expired authentication is cleared on next attempt
             self.__hass.data[DOMAIN]["auth_cache"] = None
             self.__hass.data[DOMAIN]["auth_cache"] = None
+            self.__authentication = {}
         return success
         return success
 
 
     async def async_get_devices(self) -> dict[str, Any]:
     async def async_get_devices(self) -> dict[str, Any]:
@@ -215,6 +216,13 @@ class Cloud:
                 )
                 )
         return transform
         return transform
 
 
+    def logout(self) -> None:
+        """Logout from the Tuya cloud."""
+        _LOGGER.debug("Logging out from Tuya cloud")
+        # Clear authentication cache
+        self.__hass.data[DOMAIN]["auth_cache"] = None
+        self.__authentication = {}
+
     @property
     @property
     def is_authenticated(self) -> bool:
     def is_authenticated(self) -> bool:
         """Is the cloud account authenticated?"""
         """Is the cloud account authenticated?"""

+ 8 - 3
custom_components/tuya_local/config_flow.py

@@ -73,9 +73,14 @@ class ConfigFlowHandler(ConfigFlow, domain=DOMAIN):
             self.hass.data[DOMAIN][DATA_STORE] = {}
             self.hass.data[DOMAIN][DATA_STORE] = {}
 
 
         if user_input is not None:
         if user_input is not None:
-            if user_input["setup_mode"] == "cloud":
+            mode = user_input.get("setup_mode")
+            if mode == "cloud" or mode == "cloud_fresh_login":
                 self.init_cloud()
                 self.init_cloud()
                 try:
                 try:
+                    if mode == "cloud_fresh_login":
+                        # Force a fresh login
+                        self.cloud.logout()
+
                     if self.cloud.is_authenticated:
                     if self.cloud.is_authenticated:
                         self.__cloud_devices = await self.cloud.async_get_devices()
                         self.__cloud_devices = await self.cloud.async_get_devices()
                         return await self.async_step_choose_device()
                         return await self.async_step_choose_device()
@@ -84,14 +89,14 @@ class ConfigFlowHandler(ConfigFlow, domain=DOMAIN):
                     _LOGGER.warning("Connection test failed with %s %s", type(e), e)
                     _LOGGER.warning("Connection test failed with %s %s", type(e), e)
                     _LOGGER.warning("Re-authentication is required.")
                     _LOGGER.warning("Re-authentication is required.")
                 return await self.async_step_cloud()
                 return await self.async_step_cloud()
-            if user_input["setup_mode"] == "manual":
+            if mode == "manual":
                 return await self.async_step_local()
                 return await self.async_step_local()
 
 
         # Build form
         # Build form
         fields: OrderedDict[vol.Marker, Any] = OrderedDict()
         fields: OrderedDict[vol.Marker, Any] = OrderedDict()
         fields[vol.Required("setup_mode")] = SelectSelector(
         fields[vol.Required("setup_mode")] = SelectSelector(
             SelectSelectorConfig(
             SelectSelectorConfig(
-                options=["cloud", "manual"],
+                options=["cloud", "manual", "cloud_fresh_login"],
                 mode=SelectSelectorMode.LIST,
                 mode=SelectSelectorMode.LIST,
                 translation_key="setup_mode",
                 translation_key="setup_mode",
             )
             )

+ 2 - 1
custom_components/tuya_local/translations/bg.json

@@ -74,7 +74,8 @@
         "setup_mode": {
         "setup_mode": {
             "options": {
             "options": {
                 "cloud": "Настройка на устройство",
                 "cloud": "Настройка на устройство",
-                "manual": "Предоставете ръчно информация за връзката на устройството."
+                "manual": "Предоставете ръчно информация за връзката на устройството.",
+                "cloud_fresh_login": "Влезте в Tuya с нов акаунт"
             }
             }
         }
         }
     },
     },

+ 2 - 1
custom_components/tuya_local/translations/ca.json

@@ -74,7 +74,8 @@
         "setup_mode": {
         "setup_mode": {
             "options": {
             "options": {
                 "cloud": "Configuració del dispositiu assistida amb el núvol Smart Life.",
                 "cloud": "Configuració del dispositiu assistida amb el núvol Smart Life.",
-                "manual": "Proporciona manualment la informació de connexió al dispositiu."
+                "manual": "Proporciona manualment la informació de connexió al dispositiu.",
+                "cloud_fresh_login": "Inicia la sessió en un altre compte de núvol de Smart Life."
             }
             }
         }
         }
     },
     },

+ 2 - 1
custom_components/tuya_local/translations/cz.json

@@ -74,7 +74,8 @@
         "setup_mode": {
         "setup_mode": {
             "options": {
             "options": {
                 "cloud": "Nastavení zařízení pomocí cloudu Smart Life.",
                 "cloud": "Nastavení zařízení pomocí cloudu Smart Life.",
-                "manual": "Ručně zadejte informace o připojení zařízení."
+                "manual": "Ručně zadejte informace o připojení zařízení.",
+                "cloud_fresh_login": "Přihlaste se pomocí jiného účtu Smart Life nebo Tuya Smart."
             }
             }
         }
         }
     },
     },

+ 2 - 1
custom_components/tuya_local/translations/de.json

@@ -74,7 +74,8 @@
         "setup_mode": {
         "setup_mode": {
             "options": {
             "options": {
                 "cloud": "Cloud-gestützte Geräteeinrichtung von Smart Life.",
                 "cloud": "Cloud-gestützte Geräteeinrichtung von Smart Life.",
-                "manual": "Geben Sie manuell Informationen zur Geräteverbindung an."
+                "manual": "Geben Sie manuell Informationen zur Geräteverbindung an.",
+                "cloud_fresh_login": "Cloud-gestützte Geräteeinrichtung von Smart Life mit einem frischen Login."
             }
             }
         }
         }
     },
     },

+ 2 - 1
custom_components/tuya_local/translations/el.json

@@ -74,7 +74,8 @@
         "setup_mode": {
         "setup_mode": {
             "options": {
             "options": {
                 "cloud": "Εγκατάσταση συσκευής υποβοηθούμενη απο το Smart Life cloud.",
                 "cloud": "Εγκατάσταση συσκευής υποβοηθούμενη απο το Smart Life cloud.",
-                "manual": "Εισάγετε χειροκίνητα τις πληροφορίες για τη σύνδεση της συσκευής."
+                "manual": "Εισάγετε χειροκίνητα τις πληροφορίες για τη σύνδεση της συσκευής.",
+                "cloud_fresh_login": "Εγκατάσταση συσκευής υποβοηθούμενη απο το Smart Life cloud με νέο λογαριασμό."
             }
             }
         }
         }
     },
     },

+ 2 - 1
custom_components/tuya_local/translations/en.json

@@ -74,7 +74,8 @@
         "setup_mode": {
         "setup_mode": {
             "options": {
             "options": {
                 "cloud": "Smart Life cloud-assisted device setup.",
                 "cloud": "Smart Life cloud-assisted device setup.",
-                "manual": "Manually provide device connection information."
+                "manual": "Manually provide device connection information.",
+                "cloud_fresh_login": "Smart Life cloud-assisted device setup with fresh login."
             }
             }
         }
         }
     },
     },

+ 2 - 1
custom_components/tuya_local/translations/es.json

@@ -74,7 +74,8 @@
         "setup_mode": {
         "setup_mode": {
             "options": {
             "options": {
                 "cloud": "Configuración del dispositivo asistida por la nube Smart Life.",
                 "cloud": "Configuración del dispositivo asistida por la nube Smart Life.",
-                "manual": "Proporcione manualmente información de conexión del dispositivo."
+                "manual": "Proporcione manualmente información de conexión del dispositivo.",
+                "cloud_fresh_login": "Configuración del dispositivo asistida por la nube Smart Life con inicio de sesión fresco."
             }
             }
         }
         }
     },
     },

+ 2 - 1
custom_components/tuya_local/translations/fr.json

@@ -74,7 +74,8 @@
         "setup_mode": {
         "setup_mode": {
             "options": {
             "options": {
                 "cloud": "Configuration de l'appareil assistée par le cloud Smart Life.",
                 "cloud": "Configuration de l'appareil assistée par le cloud Smart Life.",
-                "manual": "Fournissez manuellement les informations de connexion de l’appareil."
+                "manual": "Fournissez manuellement les informations de connexion de l’appareil.",
+                "cloud_fresh_login": "Configuration de l'appareil assistée par le cloud Smart Life (nouvelle connexion)."
             }
             }
         }
         }
     },
     },

+ 2 - 1
custom_components/tuya_local/translations/hu.json

@@ -75,7 +75,8 @@
         "setup_mode": {
         "setup_mode": {
             "options": {
             "options": {
                 "cloud": "Smart Life felhő által támogatott eszközbeállítás.",
                 "cloud": "Smart Life felhő által támogatott eszközbeállítás.",
-                "manual": "Adja meg manuálisan az eszköz csatlakozási adatait."
+                "manual": "Adja meg manuálisan az eszköz csatlakozási adatait.",
+                "cloud_fresh_login": "Smart Life felhő által támogatott eszközbeállítás, friss bejelentkezés."
             }
             }
         }
         }
     },
     },

+ 2 - 1
custom_components/tuya_local/translations/id.json

@@ -74,7 +74,8 @@
         "setup_mode": {
         "setup_mode": {
             "options": {
             "options": {
                 "cloud": "Penyiapan perangkat berbantuan cloud Smart Life.",
                 "cloud": "Penyiapan perangkat berbantuan cloud Smart Life.",
-                "manual": "Berikan informasi koneksi perangkat secara manual."
+                "manual": "Berikan informasi koneksi perangkat secara manual.",
+                "cloud_fresh_login": "Penyiapan perangkat berbantuan cloud Smart Life dengan login baru."
             }
             }
         }
         }
     },
     },

+ 2 - 1
custom_components/tuya_local/translations/it.json

@@ -75,7 +75,8 @@
         "setup_mode": {
         "setup_mode": {
             "options": {
             "options": {
                 "cloud": "Configurazione del dispositivo Smart Life assistita da cloud.",
                 "cloud": "Configurazione del dispositivo Smart Life assistita da cloud.",
-                "manual": "Inserisci manualmente le informazioni sulla connessione del dispositivo."
+                "manual": "Inserisci manualmente le informazioni sulla connessione del dispositivo.",
+                "cloud_fresh_login": "Configurazione del dispositivo Smart Life assistita da cloud con accesso fresco."
             }
             }
         }
         }
     },
     },

+ 2 - 1
custom_components/tuya_local/translations/ja.json

@@ -74,7 +74,8 @@
         "setup_mode": {
         "setup_mode": {
             "options": {
             "options": {
                 "cloud": "Smart Life クラウド支援デバイスのセットアップ。",
                 "cloud": "Smart Life クラウド支援デバイスのセットアップ。",
-                "manual": "デバイスの接続情報を手動で提供します。"
+                "manual": "デバイスの接続情報を手動で提供します。",
+                "cloud_fresh_login": "Smart Life クラウド支援デバイスのセットアップ (新しいログイン)。"
             }
             }
         }
         }
     },
     },

+ 2 - 1
custom_components/tuya_local/translations/no-NB.json

@@ -75,7 +75,8 @@
         "setup_mode": {
         "setup_mode": {
             "options": {
             "options": {
                 "cloud": "Smart Life sky-assistert enhetsoppsett.",
                 "cloud": "Smart Life sky-assistert enhetsoppsett.",
-                "manual": "Oppgi informasjon om enhetstilkobling manuelt."
+                "manual": "Oppgi informasjon om enhetstilkobling manuelt.",
+                "cloud_fresh_login": "Smart Life sky-assistert enhetsoppsett med ny pålogging."
             }
             }
         }
         }
     },
     },

+ 2 - 1
custom_components/tuya_local/translations/pl.json

@@ -74,7 +74,8 @@
         "setup_mode": {
         "setup_mode": {
             "options": {
             "options": {
                 "cloud": "Konfiguracja urządzenia Smart Life wspomagana chmurą.",
                 "cloud": "Konfiguracja urządzenia Smart Life wspomagana chmurą.",
-                "manual": "Ręcznie podaj informacje o połączeniu urządzenia."
+                "manual": "Ręcznie podaj informacje o połączeniu urządzenia.",
+                "cloud_fresh_login": "Konfiguracja urządzenia Smart Life wspomagana chmurą (świeże logowanie)."
             }
             }
         }
         }
     },
     },

+ 2 - 1
custom_components/tuya_local/translations/pt-BR.json

@@ -74,7 +74,8 @@
         "setup_mode": {
         "setup_mode": {
             "options": {
             "options": {
                 "cloud": "Configuração do dispositivo assistido pela nuvem Smart Life.",
                 "cloud": "Configuração do dispositivo assistido pela nuvem Smart Life.",
-                "manual": "Forneça manualmente informações de conexão do dispositivo."
+                "manual": "Forneça manualmente informações de conexão do dispositivo.",
+                "cloud_fresh_login": "Configuração do dispositivo assistido pela nuvem Smart Life com novo login."
             }
             }
         }
         }
     },
     },

+ 2 - 1
custom_components/tuya_local/translations/pt-PT.json

@@ -74,7 +74,8 @@
         "setup_mode": {
         "setup_mode": {
             "options": {
             "options": {
                 "cloud": "Configuração do dispositivo assistido pela Cloud Smart Life.",
                 "cloud": "Configuração do dispositivo assistido pela Cloud Smart Life.",
-                "manual": "Forneça manualmente informações de conexão do dispositivo."
+                "manual": "Forneça manualmente informações de conexão do dispositivo.",
+                "cloud_fresh_login": "Configuração do dispositivo assistido pela Cloud Smart Life com login fresco."
             }
             }
         }
         }
     },
     },

+ 2 - 1
custom_components/tuya_local/translations/ru.json

@@ -74,7 +74,8 @@
         "setup_mode": {
         "setup_mode": {
             "options": {
             "options": {
                 "cloud": "Настройка устройства с помощью облака Smart Life.",
                 "cloud": "Настройка устройства с помощью облака Smart Life.",
-                "manual": "Вручную укажите информацию о подключении устройства."
+                "manual": "Вручную укажите информацию о подключении устройства.",
+                "cloud_fresh_login": "Войдите в другую учетную запись Smart Life или Tuya Smart."
             }
             }
         }
         }
     },
     },

+ 2 - 1
custom_components/tuya_local/translations/uk.json

@@ -76,7 +76,8 @@
         "setup_mode": {
         "setup_mode": {
             "options": {
             "options": {
                 "cloud": "Хмарне налаштування пристрою Smart Life.",
                 "cloud": "Хмарне налаштування пристрою Smart Life.",
-                "manual": "Вручну надайте інформацію про підключення пристрою."
+                "manual": "Вручну надайте інформацію про підключення пристрою.",
+                "cloud_fresh_login": "Хмарне налаштування пристрою Smart Life з новим входом."
             }
             }
         }
         }
     },
     },

+ 2 - 1
custom_components/tuya_local/translations/ur.json

@@ -76,7 +76,8 @@
         "setup_mode": {
         "setup_mode": {
             "options": {
             "options": {
                 "cloud": "اسمارٹ لائف کلاؤڈ اسسٹڈ ڈیوائس سیٹ اپ۔",
                 "cloud": "اسمارٹ لائف کلاؤڈ اسسٹڈ ڈیوائس سیٹ اپ۔",
-                "manual": "دستی طور پر ڈیوائس کنکشن کی معلومات فراہم کریں۔"
+                "manual": "دستی طور پر ڈیوائس کنکشن کی معلومات فراہم کریں۔",
+                "cloud_fresh_login": "اسمارٹ لائف کلاؤڈ اسسٹڈ ڈیوائس سیٹ اپ (تازہ لاگ ان)"
             }
             }
         }
         }
     },
     },

+ 2 - 1
custom_components/tuya_local/translations/zh-Hans.json

@@ -74,7 +74,8 @@
         "setup_mode": {
         "setup_mode": {
             "options": {
             "options": {
                 "cloud": "Smart Life云辅助设备设置。",
                 "cloud": "Smart Life云辅助设备设置。",
-                "manual": "手动提供设备连接信息。"
+                "manual": "手动提供设备连接信息。",
+                "cloud_fresh_login": "Smart Life云辅助设备设置(新登录)。"
             }
             }
         }
         }
     },
     },

+ 2 - 1
custom_components/tuya_local/translations/zh-Hant.json

@@ -74,7 +74,8 @@
         "setup_mode": {
         "setup_mode": {
             "options": {
             "options": {
                 "cloud": "Smart Life雲端輔助設備設定。",
                 "cloud": "Smart Life雲端輔助設備設定。",
-                "manual": "手動提供設備連接資訊。"
+                "manual": "手動提供設備連接資訊。",
+                "cloud_fresh_login": "Smart Life雲端輔助設備設定(新登入)。"
             }
             }
         }
         }
     },
     },