mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 16:57:53 +00:00
Improvements for tedee integration (#107238)
* improvements * wait another second before creating the entry * move delay to lib * move library bump to separate PR * move available back to lock from entity
This commit is contained in:
parent
e5eb58b456
commit
956921a930
@ -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(
|
||||
|
@ -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."""
|
||||
|
@ -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:
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user