Add open / opening state to LockEntity (#2100)

* Add open / opening state to LockEntity

* Fix link

* Fix comments

* New date

* Change date

* Change wording
This commit is contained in:
G Johansson 2024-05-10 10:17:05 +02:00 committed by GitHub
parent f066eb8ba4
commit 7ffa180b3b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 35 additions and 0 deletions

View File

@ -0,0 +1,33 @@
---
author: G Johansson
authorURL: https://github.com/gjohansson-ST
title: "LockEntity supports open/opening state"
---
Recently we have added a `open` and `opening` state to `LockEntity`
This is useful if you have locks which can differentiate between `unlocked` (not locked but latched) state and `open` (unlocked and latch withdrawn) state.
`LockEntity` already supports the [`open` method](/docs/core/entity/lock#open) by implementing the feature flag `LockEntityFeature.OPEN`
Example (default implementation):
```python
class MyLock(LockEntity):
@property
def is_opening(self) -> bool:
"""Return true if lock is open."""
return self._state == STATE_OPENING
@property
def is_open(self) -> bool:
"""Return true if lock is open."""
return self._state == STATE_OPEN
async def async_open(self, **kwargs: Any) -> None:
"""Open the door latch."""
self._state = STATE_OPEN
self.async_write_ha_state()
```

View File

@ -19,6 +19,8 @@ Properties should always only return information from memory and not do I/O (lik
| is_locking | bool | None | Indication of whether the lock is currently locking. Used to determine `state`. | is_locking | bool | None | Indication of whether the lock is currently locking. Used to determine `state`.
| is_unlocking | bool | None | Indication of whether the lock is currently unlocking. Used to determine `state`. | is_unlocking | bool | None | Indication of whether the lock is currently unlocking. Used to determine `state`.
| is_jammed | bool | None | Indication of whether the lock is currently jammed. Used to determine `state`. | is_jammed | bool | None | Indication of whether the lock is currently jammed. Used to determine `state`.
| is_opening | bool | None | Indication of whether the lock is currently opening. Used to determine `state`.
| is_open | bool | None | Indication of whether the lock is currently open. Used to determine `state`.
## Supported Features ## Supported Features