Skip to content

Commit

Permalink
Add is_locking/is_unlocking to lock (#302)
Browse files Browse the repository at this point in the history
  • Loading branch information
SukramJ authored Feb 16, 2022
1 parent 80df456 commit 2aaa4c5
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 2 deletions.
5 changes: 4 additions & 1 deletion changelog.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
Version 0.34.0 (2022-02-16)
Version 0.34.2 (2022-02-16)
- Add is_locking/is_unlocking to lock

Version 0.34.1 (2022-02-16)
- Fix siren definition

Version 0.34.0 (2022-02-15)
Expand Down
2 changes: 2 additions & 0 deletions hahomematic/devices/entity_definition.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ class EntityDefinition(StrEnum):
ED_DEVICE_GROUP: {
ED_PRIMARY_CHANNEL: 1,
ED_REPEATABLE_FIELDS: {
FIELD_DIRECTION: "ACTIVITY_STATE",
FIELD_LOCK_STATE: "LOCK_STATE",
FIELD_LOCK_TARGET_LEVEL: "LOCK_TARGET_LEVEL",
},
Expand Down Expand Up @@ -373,6 +374,7 @@ class EntityDefinition(StrEnum):
ED_DEVICE_GROUP: {
ED_PRIMARY_CHANNEL: 0,
ED_REPEATABLE_FIELDS: {
FIELD_DIRECTION: "DIRECTION",
FIELD_OPEN: "OPEN",
FIELD_STATE: "STATE",
FIELD_ERROR: "ERROR",
Expand Down
52 changes: 52 additions & 0 deletions hahomematic/devices/lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from hahomematic.const import HmPlatform
import hahomematic.device as hm_device
from hahomematic.devices.entity_definition import (
FIELD_DIRECTION,
FIELD_ERROR,
FIELD_LOCK_STATE,
FIELD_LOCK_TARGET_LEVEL,
Expand All @@ -33,6 +34,9 @@
LOCK_TARGET_LEVEL_UNLOCKED = "UNLOCKED"
LOCK_TARGET_LEVEL_OPEN = "OPEN"

HM_UNLOCKING = "UP"
HM_LOCKING = "DOWN"


class BaseLock(CustomEntity):
"""Class for homematic ip lock entities."""
Expand Down Expand Up @@ -74,6 +78,16 @@ def is_jammed(self) -> bool:
"""Return true if lock is jammed."""
return False

@property
def is_locking(self) -> bool | None:
"""Return true if the lock is locking."""
return None

@property
def is_unlocking(self) -> bool | None:
"""Return true if the lock is unlocking."""
return None

@abstractmethod
async def lock(self) -> None:
"""Lock the lock."""
Expand Down Expand Up @@ -105,6 +119,11 @@ def _e_lock_target_level(self) -> HmAction:
field_name=FIELD_LOCK_TARGET_LEVEL, entity_type=HmAction
)

@property
def _direction(self) -> str | None:
"""Return the direction entity of the lock."""
return self._get_entity_value(field_name=FIELD_DIRECTION)

@property
def _error(self) -> bool | None:
"""Return the error entity of the device."""
Expand All @@ -115,6 +134,20 @@ def is_locked(self) -> bool:
"""Return true if lock is on."""
return self._lock_state == LOCK_STATE_LOCKED

@property
def is_locking(self) -> bool | None:
"""Return true if the lock is locking."""
if self._direction is not None:
return self._direction == HM_LOCKING
return None

@property
def is_unlocking(self) -> bool | None:
"""Return true if the lock is unlocking."""
if self._direction is not None:
return self._direction == HM_UNLOCKING
return None

@property
def is_jammed(self) -> bool:
"""Return true if lock is jammed."""
Expand Down Expand Up @@ -146,6 +179,11 @@ def _e_open(self) -> HmAction:
"""Return the open entity of the device."""
return self._get_entity(field_name=FIELD_OPEN, entity_type=HmAction)

@property
def _direction(self) -> str | None:
"""Return the direction entity of the lock."""
return self._get_entity_value(field_name=FIELD_DIRECTION)

@property
def _error(self) -> str | None:
"""Return the error entity of the device."""
Expand All @@ -156,6 +194,20 @@ def is_locked(self) -> bool:
"""Return true if lock is on."""
return self._e_state.value is not True

@property
def is_locking(self) -> bool | None:
"""Return true if the lock is locking."""
if self._direction is not None:
return self._direction == HM_LOCKING
return None

@property
def is_unlocking(self) -> bool | None:
"""Return true if the lock is unlocking."""
if self._direction is not None:
return self._direction == HM_UNLOCKING
return None

@property
def is_jammed(self) -> bool:
"""Return true if lock is jammed."""
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def readme():
},
PACKAGE_NAME = "hahomematic"
HERE = os.path.abspath(os.path.dirname(__file__))
VERSION = "0.34.1"
VERSION = "0.34.2"

PACKAGES = find_packages(exclude=["tests", "tests.*", "dist", "build"])

Expand Down

0 comments on commit 2aaa4c5

Please sign in to comment.