parent
ecbff61332
commit
a42615add0
2 changed files with 27 additions and 8 deletions
|
@ -55,8 +55,13 @@ class TedeeLockEntity(TedeeEntity, LockEntity):
|
|||
super().__init__(lock, coordinator, "lock")
|
||||
|
||||
@property
|
||||
def is_locked(self) -> bool:
|
||||
def is_locked(self) -> bool | None:
|
||||
"""Return true if lock is locked."""
|
||||
if self._lock.state in (
|
||||
TedeeLockState.HALF_OPEN,
|
||||
TedeeLockState.UNKNOWN,
|
||||
):
|
||||
return None
|
||||
return self._lock.state == TedeeLockState.LOCKED
|
||||
|
||||
@property
|
||||
|
@ -87,7 +92,11 @@ class TedeeLockEntity(TedeeEntity, LockEntity):
|
|||
@property
|
||||
def available(self) -> bool:
|
||||
"""Return True if entity is available."""
|
||||
return super().available and self._lock.is_connected
|
||||
return (
|
||||
super().available
|
||||
and self._lock.is_connected
|
||||
and self._lock.state != TedeeLockState.UNCALIBRATED
|
||||
)
|
||||
|
||||
async def async_unlock(self, **kwargs: Any) -> None:
|
||||
"""Unlock the door."""
|
||||
|
|
|
@ -25,7 +25,7 @@ from homeassistant.components.lock import (
|
|||
STATE_UNLOCKING,
|
||||
)
|
||||
from homeassistant.components.webhook import async_generate_url
|
||||
from homeassistant.const import ATTR_ENTITY_ID, STATE_UNAVAILABLE
|
||||
from homeassistant.const import ATTR_ENTITY_ID, STATE_UNAVAILABLE, STATE_UNKNOWN
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.helpers import device_registry as dr, entity_registry as er
|
||||
|
@ -276,10 +276,21 @@ async def test_new_lock(
|
|||
assert state
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("lib_state", "expected_state"),
|
||||
[
|
||||
(TedeeLockState.LOCKED, STATE_LOCKED),
|
||||
(TedeeLockState.HALF_OPEN, STATE_UNKNOWN),
|
||||
(TedeeLockState.UNKNOWN, STATE_UNKNOWN),
|
||||
(TedeeLockState.UNCALIBRATED, STATE_UNAVAILABLE),
|
||||
],
|
||||
)
|
||||
async def test_webhook_update(
|
||||
hass: HomeAssistant,
|
||||
mock_tedee: MagicMock,
|
||||
hass_client_no_auth: ClientSessionGenerator,
|
||||
lib_state: TedeeLockState,
|
||||
expected_state: str,
|
||||
) -> None:
|
||||
"""Test updated data set through webhook."""
|
||||
|
||||
|
@ -287,10 +298,9 @@ async def test_webhook_update(
|
|||
assert state
|
||||
assert state.state == STATE_UNLOCKED
|
||||
|
||||
webhook_data = {"dummystate": 6}
|
||||
mock_tedee.locks_dict[
|
||||
12345
|
||||
].state = TedeeLockState.LOCKED # is updated in the lib, so mock and assert in L296
|
||||
webhook_data = {"dummystate": lib_state.value}
|
||||
# is updated in the lib, so mock and assert below
|
||||
mock_tedee.locks_dict[12345].state = lib_state
|
||||
client = await hass_client_no_auth()
|
||||
webhook_url = async_generate_url(hass, WEBHOOK_ID)
|
||||
|
||||
|
@ -302,4 +312,4 @@ async def test_webhook_update(
|
|||
|
||||
state = hass.states.get("lock.lock_1a2b")
|
||||
assert state
|
||||
assert state.state == STATE_LOCKED
|
||||
assert state.state == expected_state
|
||||
|
|
Loading…
Add table
Reference in a new issue