Skip to content

Commit

Permalink
Remove "jammed" attribute of lock and make it part of state (#54)
Browse files Browse the repository at this point in the history
  • Loading branch information
bachya authored Nov 9, 2019
1 parent ca5ce9e commit acac699
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 10 deletions.
10 changes: 4 additions & 6 deletions simplipy/lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
Expand All @@ -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."""
Expand All @@ -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:
Expand Down
1 change: 1 addition & 0 deletions tests/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
TEST_ADDRESS = "1234 Main Street"
TEST_EMAIL = "[email protected]"
TEST_LOCK_ID = "987"
TEST_LOCK_ID_2 = "654"
TEST_PASSWORD = "12345"
TEST_REFRESH_TOKEN = "qrstu98765"
TEST_SUBSCRIPTION_ID = 12345
Expand Down
45 changes: 45 additions & 0 deletions tests/fixtures/v3.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
18 changes: 14 additions & 4 deletions tests/test_lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from .const import (
TEST_EMAIL,
TEST_LOCK_ID,
TEST_LOCK_ID_2,
TEST_PASSWORD,
TEST_SUBSCRIPTION_ID,
TEST_SYSTEM_ID,
Expand Down Expand Up @@ -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."""
Expand Down Expand Up @@ -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


Expand All @@ -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

0 comments on commit acac699

Please sign in to comment.