Fix sending a (default) pincode to Matter Lock operations (#95402)

This commit is contained in:
Marcel van der Veldt 2023-06-27 20:27:48 +02:00 committed by GitHub
parent 99a622c8ee
commit e7f29263e3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -8,7 +8,7 @@ from chip.clusters import Objects as clusters
from homeassistant.components.lock import LockEntity, LockEntityDescription
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import Platform
from homeassistant.const import ATTR_CODE, Platform
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.entity_platform import AddEntitiesCallback
@ -56,11 +56,25 @@ class MatterLock(MatterEntity, LockEntity):
async def async_lock(self, **kwargs: Any) -> None:
"""Lock the lock with pin if needed."""
await self.send_device_command(command=clusters.DoorLock.Commands.LockDoor())
code: str = kwargs.get(
ATTR_CODE,
self._lock_option_default_code,
)
code_bytes = code.encode() if code else None
await self.send_device_command(
command=clusters.DoorLock.Commands.LockDoor(code_bytes)
)
async def async_unlock(self, **kwargs: Any) -> None:
"""Unlock the lock with pin if needed."""
await self.send_device_command(command=clusters.DoorLock.Commands.UnlockDoor())
code: str = kwargs.get(
ATTR_CODE,
self._lock_option_default_code,
)
code_bytes = code.encode() if code else None
await self.send_device_command(
command=clusters.DoorLock.Commands.UnlockDoor(code_bytes)
)
@callback
def _update_from_device(self) -> None: