diff --git a/homeassistant/components/matter/lock.py b/homeassistant/components/matter/lock.py index e7d177e484c..f78529b7268 100644 --- a/homeassistant/components/matter/lock.py +++ b/homeassistant/components/matter/lock.py @@ -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: