From acac699436a95853a6044b8aaca9e73056e7265d Mon Sep 17 00:00:00 2001 From: Aaron Bach Date: Sat, 9 Nov 2019 15:14:28 -0700 Subject: [PATCH] Remove "jammed" attribute of lock and make it part of state (#54) --- simplipy/lock.py | 10 ++++------ tests/const.py | 1 + tests/fixtures/v3.py | 45 ++++++++++++++++++++++++++++++++++++++++++++ tests/test_lock.py | 18 ++++++++++++++---- 4 files changed, 64 insertions(+), 10 deletions(-) diff --git a/simplipy/lock.py b/simplipy/lock.py index 298ff4ae..cc17edd4 100644 --- a/simplipy/lock.py +++ b/simplipy/lock.py @@ -10,8 +10,9 @@ class LockStates(Enum): """Define states that the lock can be in.""" - locked = 1 unlocked = 0 + locked = 1 + jammed = 2 SET_STATE_MAP = {LockStates.locked: "lock", LockStates.unlocked: "unlock"} @@ -30,11 +31,6 @@ def lock_low_battery(self) -> bool: """Return whether the lock's battery is low.""" return self.entity_data["status"]["lockLowBattery"] - @property - def jammed(self) -> bool: - """Return whether the lock is jammed.""" - return bool(self.entity_data["status"]["lockJamState"]) - @property def pin_pad_low_battery(self) -> bool: """Return whether the pin pad's battery is low.""" @@ -48,6 +44,8 @@ def pin_pad_offline(self) -> bool: @property def state(self) -> LockStates: """Return the current state of the lock.""" + if bool(self.entity_data["status"]["lockJamState"]): + return LockStates.jammed return LockStates(self.entity_data["status"]["lockState"]) async def _set_lock_state(self, state: LockStates) -> None: diff --git a/tests/const.py b/tests/const.py index 281f806e..464744a8 100644 --- a/tests/const.py +++ b/tests/const.py @@ -4,6 +4,7 @@ TEST_ADDRESS = "1234 Main Street" TEST_EMAIL = "user@email.com" TEST_LOCK_ID = "987" +TEST_LOCK_ID_2 = "654" TEST_PASSWORD = "12345" TEST_REFRESH_TOKEN = "qrstu98765" TEST_SUBSCRIPTION_ID = 12345 diff --git a/tests/fixtures/v3.py b/tests/fixtures/v3.py index 767463bc..c52b2216 100644 --- a/tests/fixtures/v3.py +++ b/tests/fixtures/v3.py @@ -7,6 +7,7 @@ from ..const import ( TEST_ACCOUNT_ID, TEST_LOCK_ID, + TEST_LOCK_ID_2, TEST_SUBSCRIPTION_ID, TEST_SYSTEM_ID, TEST_SYSTEM_SERIAL_NO, @@ -466,6 +467,50 @@ def v3_sensors_json(): "offline": False, }, }, + { + "serial": TEST_LOCK_ID_2, + "type": 16, + "status": { + "pinPadState": 0, + "lockState": 1, + "pinPadOffline": False, + "pinPadLowBattery": False, + "lockDisabled": False, + "lockLowBattery": False, + "calibrationErrDelta": 0, + "calibrationErrZero": 0, + "lockJamState": 1, + }, + "name": "Back Door", + "deviceGroupID": 1, + "firmwareVersion": "1.0.0", + "bootVersion": "1.0.0", + "setting": { + "autoLock": 3, + "away": 1, + "home": 1, + "awayToOff": 0, + "homeToOff": 1, + }, + "flags": { + "swingerShutdown": False, + "lowBattery": False, + "offline": False, + }, + }, + { + "serial": "654", + "type": 253, + "status": {}, + "name": "Front Door", + "deviceGroupID": 1, + "setting": {}, + "flags": { + "swingerShutdown": False, + "lowBattery": False, + "offline": False, + }, + }, ], "lastUpdated": 1534626361, "lastSynced": 1534626361, diff --git a/tests/test_lock.py b/tests/test_lock.py index 266df4a7..9d6d9d7e 100644 --- a/tests/test_lock.py +++ b/tests/test_lock.py @@ -12,6 +12,7 @@ from .const import ( TEST_EMAIL, TEST_LOCK_ID, + TEST_LOCK_ID_2, TEST_PASSWORD, TEST_SUBSCRIPTION_ID, TEST_SYSTEM_ID, @@ -63,6 +64,19 @@ async def test_lock_unlock( assert lock.state == LockStates.locked +@pytest.mark.asyncio +async def test_jammed(event_loop, v3_server): + """Test that a jammed lock shows the correct state.""" + async with v3_server: + async with aiohttp.ClientSession(loop=event_loop) as websession: + api = await API.login_via_credentials(TEST_EMAIL, TEST_PASSWORD, websession) + systems = await api.get_systems() + system = systems[TEST_SYSTEM_ID] + + lock = system.locks["654"] + assert lock.state is LockStates.jammed + + @pytest.mark.asyncio async def test_no_state_change_on_failure(aresponses, event_loop, v3_server): """Test that the lock doesn't change state on error.""" @@ -105,13 +119,11 @@ async def test_properties(event_loop, v3_server): lock = system.locks["987"] assert not lock.disabled assert not lock.error - assert not lock.jammed assert not lock.lock_low_battery assert not lock.low_battery assert not lock.offline assert not lock.pin_pad_low_battery assert not lock.pin_pad_offline - assert lock.state is LockStates.locked @@ -127,11 +139,9 @@ async def test_properties(event_loop, v3_server): lock = system.locks["987"] assert not lock.disabled assert not lock.error - assert not lock.jammed assert not lock.lock_low_battery assert not lock.low_battery assert not lock.offline assert not lock.pin_pad_low_battery assert not lock.pin_pad_offline - assert lock.state is LockStates.locked