From f2f68859ccdba237e8cfabdbd62c3ad8e6e59f1c Mon Sep 17 00:00:00 2001 From: SukramJ Date: Thu, 3 Sep 2020 09:52:51 +0200 Subject: [PATCH] Fix wrong error message on adding a new HomematicIP Cloud AP (#39599) --- homeassistant/components/homematicip_cloud/config_flow.py | 3 +++ homeassistant/components/homematicip_cloud/hap.py | 4 ++-- homeassistant/components/homematicip_cloud/strings.json | 2 +- .../components/homematicip_cloud/translations/en.json | 2 +- tests/components/homematicip_cloud/test_hap.py | 4 +--- 5 files changed, 8 insertions(+), 7 deletions(-) diff --git a/homeassistant/components/homematicip_cloud/config_flow.py b/homeassistant/components/homematicip_cloud/config_flow.py index 547289f871a08..b6b78948894c8 100644 --- a/homeassistant/components/homematicip_cloud/config_flow.py +++ b/homeassistant/components/homematicip_cloud/config_flow.py @@ -47,6 +47,9 @@ async def async_step_init(self, user_input=None) -> Dict[str, Any]: _LOGGER.info("Connection to HomematicIP Cloud established") return await self.async_step_link() + _LOGGER.info("Connection to HomematicIP Cloud failed") + errors["base"] = "invalid_sgtin_or_pin" + return self.async_show_form( step_id="init", data_schema=vol.Schema( diff --git a/homeassistant/components/homematicip_cloud/hap.py b/homeassistant/components/homematicip_cloud/hap.py index 78f1d57ac93ee..164997d5582ae 100644 --- a/homeassistant/components/homematicip_cloud/hap.py +++ b/homeassistant/components/homematicip_cloud/hap.py @@ -34,7 +34,7 @@ async def async_setup(self) -> bool: self.auth = await self.get_auth( self.hass, self.config.get(HMIPC_HAPID), self.config.get(HMIPC_PIN) ) - return True + return self.auth is not None except HmipcConnectionError: return False @@ -63,7 +63,7 @@ async def get_auth(self, hass: HomeAssistantType, hapid, pin): auth.pin = pin await auth.connectionRequest("HomeAssistant") except HmipConnectionError: - return False + return None return auth diff --git a/homeassistant/components/homematicip_cloud/strings.json b/homeassistant/components/homematicip_cloud/strings.json index 2b2a75ebc08f6..fddb2b85df69d 100644 --- a/homeassistant/components/homematicip_cloud/strings.json +++ b/homeassistant/components/homematicip_cloud/strings.json @@ -16,7 +16,7 @@ }, "error": { "register_failed": "Failed to register, please try again.", - "invalid_pin": "Invalid PIN, please try again.", + "invalid_sgtin_or_pin": "Invalid SGTIN or PIN, please try again.", "press_the_button": "Please press the blue button.", "timeout_button": "Blue button press timeout, please try again." }, diff --git a/homeassistant/components/homematicip_cloud/translations/en.json b/homeassistant/components/homematicip_cloud/translations/en.json index 26ca6eb60d6e9..74d42fc7bc48a 100644 --- a/homeassistant/components/homematicip_cloud/translations/en.json +++ b/homeassistant/components/homematicip_cloud/translations/en.json @@ -6,7 +6,7 @@ "unknown": "Unknown error occurred." }, "error": { - "invalid_pin": "Invalid PIN, please try again.", + "invalid_sgtin_or_pin": "Invalid SGTIN or PIN, please try again.", "press_the_button": "Please press the blue button.", "register_failed": "Failed to register, please try again.", "timeout_button": "Blue button press timeout, please try again." diff --git a/tests/components/homematicip_cloud/test_hap.py b/tests/components/homematicip_cloud/test_hap.py index ca701622e900c..2a4833553d29f 100644 --- a/tests/components/homematicip_cloud/test_hap.py +++ b/tests/components/homematicip_cloud/test_hap.py @@ -175,9 +175,7 @@ async def test_auth_create_exception(hass, simple_mock_auth): "homeassistant.components.homematicip_cloud.hap.AsyncAuth", return_value=simple_mock_auth, ): - assert await hmip_auth.async_setup() - await hass.async_block_till_done() - assert not hmip_auth.auth + assert not await hmip_auth.async_setup() with patch( "homeassistant.components.homematicip_cloud.hap.AsyncAuth",