diff --git a/homeassistant/components/tedee/config_flow.py b/homeassistant/components/tedee/config_flow.py index 27f455ee20c..075a4c998ea 100644 --- a/homeassistant/components/tedee/config_flow.py +++ b/homeassistant/components/tedee/config_flow.py @@ -6,6 +6,7 @@ from pytedee_async import ( TedeeAuthException, TedeeClient, TedeeClientException, + TedeeDataUpdateException, TedeeLocalAuthException, ) import voluptuous as vol @@ -46,6 +47,8 @@ class TedeeConfigFlow(ConfigFlow, domain=DOMAIN): errors[CONF_LOCAL_ACCESS_TOKEN] = "invalid_api_key" except TedeeClientException: errors[CONF_HOST] = "invalid_host" + except TedeeDataUpdateException: + errors["base"] = "cannot_connect" else: if self.reauth_entry: self.hass.config_entries.async_update_entry( diff --git a/homeassistant/components/tedee/entity.py b/homeassistant/components/tedee/entity.py index ef75affebbc..59e3354aa1a 100644 --- a/homeassistant/components/tedee/entity.py +++ b/homeassistant/components/tedee/entity.py @@ -41,11 +41,6 @@ class TedeeEntity(CoordinatorEntity[TedeeApiCoordinator]): self._lock = self.coordinator.data.get(self._lock.lock_id, self._lock) super()._handle_coordinator_update() - @property - def available(self) -> bool: - """Return True if entity is available.""" - return super().available and self._lock.is_connected - class TedeeDescriptionEntity(TedeeEntity): """Base class for Tedee device entities.""" diff --git a/homeassistant/components/tedee/lock.py b/homeassistant/components/tedee/lock.py index a01d13c3bbb..1025942d787 100644 --- a/homeassistant/components/tedee/lock.py +++ b/homeassistant/components/tedee/lock.py @@ -74,6 +74,11 @@ class TedeeLockEntity(TedeeEntity, LockEntity): """Return true if lock is jammed.""" return self._lock.is_state_jammed + @property + def available(self) -> bool: + """Return True if entity is available.""" + return super().available and self._lock.is_connected + async def async_unlock(self, **kwargs: Any) -> None: """Unlock the door.""" try: diff --git a/tests/components/tedee/test_config_flow.py b/tests/components/tedee/test_config_flow.py index 4feb9bb8ca5..bc5b73aa4a9 100644 --- a/tests/components/tedee/test_config_flow.py +++ b/tests/components/tedee/test_config_flow.py @@ -1,7 +1,11 @@ """Test the Tedee config flow.""" from unittest.mock import MagicMock -from pytedee_async import TedeeClientException, TedeeLocalAuthException +from pytedee_async import ( + TedeeClientException, + TedeeDataUpdateException, + TedeeLocalAuthException, +) import pytest from homeassistant.components.tedee.const import CONF_LOCAL_ACCESS_TOKEN, DOMAIN @@ -72,6 +76,7 @@ async def test_flow_already_configured( TedeeLocalAuthException("boom."), {CONF_LOCAL_ACCESS_TOKEN: "invalid_api_key"}, ), + (TedeeDataUpdateException("boom."), {"base": "cannot_connect"}), ], ) async def test_config_flow_errors( @@ -130,51 +135,3 @@ async def test_reauth_flow( ) assert result["type"] == FlowResultType.ABORT assert result["reason"] == "reauth_successful" - - -@pytest.mark.parametrize( - ("side_effect", "error"), - [ - (TedeeClientException("boom."), {CONF_HOST: "invalid_host"}), - ( - TedeeLocalAuthException("boom."), - {CONF_LOCAL_ACCESS_TOKEN: "invalid_api_key"}, - ), - ], -) -async def test_reauth_flow_errors( - hass: HomeAssistant, - mock_config_entry: MockConfigEntry, - mock_tedee: MagicMock, - side_effect: Exception, - error: dict[str, str], -) -> None: - """Test that the reauth flow errors.""" - - mock_config_entry.add_to_hass(hass) - - result = await hass.config_entries.flow.async_init( - DOMAIN, - context={ - "source": SOURCE_REAUTH, - "unique_id": mock_config_entry.unique_id, - "entry_id": mock_config_entry.entry_id, - }, - data={ - CONF_LOCAL_ACCESS_TOKEN: LOCAL_ACCESS_TOKEN, - CONF_HOST: "192.168.1.42", - }, - ) - - mock_tedee.get_local_bridge.side_effect = side_effect - - result2 = await hass.config_entries.flow.async_configure( - result["flow_id"], - { - CONF_LOCAL_ACCESS_TOKEN: LOCAL_ACCESS_TOKEN, - }, - ) - - assert result2["type"] == FlowResultType.FORM - assert result2["errors"] == error - assert len(mock_tedee.get_local_bridge.mock_calls) == 1