mirror of
https://github.com/home-assistant/core.git
synced 2025-07-09 22:37:11 +00:00
Remove workaround for default lock code in Matter (#105173)
* Matter: Remove workaround for default lock code * Review * Review 2
This commit is contained in:
parent
0eb7034f89
commit
9fb9ff4f90
@ -89,10 +89,7 @@ class MatterLock(MatterEntity, LockEntity):
|
|||||||
|
|
||||||
async def async_lock(self, **kwargs: Any) -> None:
|
async def async_lock(self, **kwargs: Any) -> None:
|
||||||
"""Lock the lock with pin if needed."""
|
"""Lock the lock with pin if needed."""
|
||||||
code: str = kwargs.get(
|
code: str | None = kwargs.get(ATTR_CODE)
|
||||||
ATTR_CODE,
|
|
||||||
self._lock_option_default_code,
|
|
||||||
)
|
|
||||||
code_bytes = code.encode() if code else None
|
code_bytes = code.encode() if code else None
|
||||||
await self.send_device_command(
|
await self.send_device_command(
|
||||||
command=clusters.DoorLock.Commands.LockDoor(code_bytes)
|
command=clusters.DoorLock.Commands.LockDoor(code_bytes)
|
||||||
@ -100,10 +97,7 @@ class MatterLock(MatterEntity, LockEntity):
|
|||||||
|
|
||||||
async def async_unlock(self, **kwargs: Any) -> None:
|
async def async_unlock(self, **kwargs: Any) -> None:
|
||||||
"""Unlock the lock with pin if needed."""
|
"""Unlock the lock with pin if needed."""
|
||||||
code: str = kwargs.get(
|
code: str | None = kwargs.get(ATTR_CODE)
|
||||||
ATTR_CODE,
|
|
||||||
self._lock_option_default_code,
|
|
||||||
)
|
|
||||||
code_bytes = code.encode() if code else None
|
code_bytes = code.encode() if code else None
|
||||||
if self.supports_unbolt:
|
if self.supports_unbolt:
|
||||||
# if the lock reports it has separate unbolt support,
|
# if the lock reports it has separate unbolt support,
|
||||||
@ -119,10 +113,7 @@ class MatterLock(MatterEntity, LockEntity):
|
|||||||
|
|
||||||
async def async_open(self, **kwargs: Any) -> None:
|
async def async_open(self, **kwargs: Any) -> None:
|
||||||
"""Open the door latch."""
|
"""Open the door latch."""
|
||||||
code: str = kwargs.get(
|
code: str | None = kwargs.get(ATTR_CODE)
|
||||||
ATTR_CODE,
|
|
||||||
self._lock_option_default_code,
|
|
||||||
)
|
|
||||||
code_bytes = code.encode() if code else None
|
code_bytes = code.encode() if code else None
|
||||||
await self.send_device_command(
|
await self.send_device_command(
|
||||||
command=clusters.DoorLock.Commands.UnlockDoor(code_bytes)
|
command=clusters.DoorLock.Commands.UnlockDoor(code_bytes)
|
||||||
|
@ -14,6 +14,7 @@ from homeassistant.components.lock import (
|
|||||||
)
|
)
|
||||||
from homeassistant.const import ATTR_CODE, STATE_UNKNOWN
|
from homeassistant.const import ATTR_CODE, STATE_UNKNOWN
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
|
import homeassistant.helpers.entity_registry as er
|
||||||
|
|
||||||
from .common import set_node_attribute, trigger_subscription_callback
|
from .common import set_node_attribute, trigger_subscription_callback
|
||||||
|
|
||||||
@ -101,6 +102,7 @@ async def test_lock_requires_pin(
|
|||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
matter_client: MagicMock,
|
matter_client: MagicMock,
|
||||||
door_lock: MatterNode,
|
door_lock: MatterNode,
|
||||||
|
entity_registry: er.EntityRegistry,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test door lock with PINCode."""
|
"""Test door lock with PINCode."""
|
||||||
|
|
||||||
@ -137,6 +139,26 @@ async def test_lock_requires_pin(
|
|||||||
timed_request_timeout_ms=1000,
|
timed_request_timeout_ms=1000,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Lock door using default code
|
||||||
|
default_code = "7654321"
|
||||||
|
entity_registry.async_update_entity_options(
|
||||||
|
"lock.mock_door_lock", "lock", {"default_code": default_code}
|
||||||
|
)
|
||||||
|
await trigger_subscription_callback(hass, matter_client)
|
||||||
|
await hass.services.async_call(
|
||||||
|
"lock",
|
||||||
|
"lock",
|
||||||
|
{"entity_id": "lock.mock_door_lock"},
|
||||||
|
blocking=True,
|
||||||
|
)
|
||||||
|
assert matter_client.send_device_command.call_count == 2
|
||||||
|
assert matter_client.send_device_command.call_args == call(
|
||||||
|
node_id=door_lock.node_id,
|
||||||
|
endpoint_id=1,
|
||||||
|
command=clusters.DoorLock.Commands.LockDoor(default_code.encode()),
|
||||||
|
timed_request_timeout_ms=1000,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
# This tests needs to be adjusted to remove lingering tasks
|
# This tests needs to be adjusted to remove lingering tasks
|
||||||
@pytest.mark.parametrize("expected_lingering_tasks", [True])
|
@pytest.mark.parametrize("expected_lingering_tasks", [True])
|
||||||
|
Loading…
x
Reference in New Issue
Block a user