From c98ee412c0188dadbd74dcd4f0df17037fa73e43 Mon Sep 17 00:00:00 2001
From: Mick Vleeshouwer <mick@imick.nl>
Date: Wed, 31 Aug 2022 21:16:00 +0200
Subject: [PATCH] Catch unknown user exception in Overkiz integration (#76693)

---
 homeassistant/components/overkiz/config_flow.py       | 3 +++
 homeassistant/components/overkiz/strings.json         | 3 ++-
 homeassistant/components/overkiz/translations/en.json | 3 ++-
 tests/components/overkiz/test_config_flow.py          | 2 ++
 4 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/homeassistant/components/overkiz/config_flow.py b/homeassistant/components/overkiz/config_flow.py
index 2808c309938..d3ab9722fca 100644
--- a/homeassistant/components/overkiz/config_flow.py
+++ b/homeassistant/components/overkiz/config_flow.py
@@ -12,6 +12,7 @@ from pyoverkiz.exceptions import (
     MaintenanceException,
     TooManyAttemptsBannedException,
     TooManyRequestsException,
+    UnknownUserException,
 )
 from pyoverkiz.models import obfuscate_id
 import voluptuous as vol
@@ -83,6 +84,8 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
                 errors["base"] = "server_in_maintenance"
             except TooManyAttemptsBannedException:
                 errors["base"] = "too_many_attempts"
+            except UnknownUserException:
+                errors["base"] = "unknown_user"
             except Exception as exception:  # pylint: disable=broad-except
                 errors["base"] = "unknown"
                 LOGGER.exception(exception)
diff --git a/homeassistant/components/overkiz/strings.json b/homeassistant/components/overkiz/strings.json
index 9c64311a73e..ecc0329eb2a 100644
--- a/homeassistant/components/overkiz/strings.json
+++ b/homeassistant/components/overkiz/strings.json
@@ -18,7 +18,8 @@
       "server_in_maintenance": "Server is down for maintenance",
       "too_many_attempts": "Too many attempts with an invalid token, temporarily banned",
       "too_many_requests": "Too many requests, try again later",
-      "unknown": "[%key:common::config_flow::error::unknown%]"
+      "unknown": "[%key:common::config_flow::error::unknown%]",
+      "unknown_user": "Unknown user. Somfy Protect accounts are not supported by this integration."
     },
     "abort": {
       "already_configured": "[%key:common::config_flow::abort::already_configured_account%]",
diff --git a/homeassistant/components/overkiz/translations/en.json b/homeassistant/components/overkiz/translations/en.json
index 9e24a9d3cb3..9c8ad538695 100644
--- a/homeassistant/components/overkiz/translations/en.json
+++ b/homeassistant/components/overkiz/translations/en.json
@@ -11,7 +11,8 @@
             "server_in_maintenance": "Server is down for maintenance",
             "too_many_attempts": "Too many attempts with an invalid token, temporarily banned",
             "too_many_requests": "Too many requests, try again later",
-            "unknown": "Unexpected error"
+            "unknown": "Unexpected error",
+            "unknown_user": "Unknown user. Somfy Protect accounts are not supported by this integration."
         },
         "flow_title": "Gateway: {gateway_id}",
         "step": {
diff --git a/tests/components/overkiz/test_config_flow.py b/tests/components/overkiz/test_config_flow.py
index 0542f4dc9fc..940da7b39c2 100644
--- a/tests/components/overkiz/test_config_flow.py
+++ b/tests/components/overkiz/test_config_flow.py
@@ -9,6 +9,7 @@ from pyoverkiz.exceptions import (
     MaintenanceException,
     TooManyAttemptsBannedException,
     TooManyRequestsException,
+    UnknownUserException,
 )
 import pytest
 
@@ -88,6 +89,7 @@ async def test_form(hass: HomeAssistant) -> None:
         (ClientError, "cannot_connect"),
         (MaintenanceException, "server_in_maintenance"),
         (TooManyAttemptsBannedException, "too_many_attempts"),
+        (UnknownUserException, "unknown_user"),
         (Exception, "unknown"),
     ],
 )
-- 
GitLab