Set lock status correctly for Schlage BE469 Z-Wave locks (#18737)

* Set lock status correctly for Schlage BE469 Z-Wave locks

PR #17386 attempted to improve the state of z-wave lock tracking for
some problematic models. However, it operated under a flawed
assumptions. Namely, that we can always trust `self.values` to have
fresh data, and that the Schlage BE469 sends alarm reports after every
lock event. We can't trust `self.values`, and the Schlage is very
broken. :)

When we receive a notification from the driver about a state change,
we call `update_properties` - but we can (and do!) have _stale_
properties left over from previous updates. #17386 really works best
if you start from a clean slate each time. However, `update_properties`
is called on every value update, and we don't get a reason why.
Moreover, values that weren't just refreshed are not removed. So blindly
looking at something like `self.values.access_control` when deciding to
apply a workaround is not going to always be correct - it may or may not
be, depending on what happened in the past.

For the sad case of the BE469, here are the Z-Wave events that happen
under various circumstances:

RF Lock / Unlock:
- Send: door lock command set
- Receive: door lock report
- Send: door lock command get
- Receive: door lock report

Manual lock / Unlock:
- Receive: alarm
- Send: door lock command get
- Receive: door lock report

Keypad lock / Unlock:
- Receive: alarm
- Send: door lock command get
- Receive: door lock report

Thus, this PR introduces yet another work around - we track the current
and last z-wave command that the driver saw, and make assumptions based
on the sequence of events. This seems to be the most reliable way to go
- simply asking the driver to refresh various states doesn't clear out
alarms the way you would expect; this model doesn't support the access
control logging commands; and trying to manually clear out alarm state
when calling RF lock/unlock was tricky.

The lock state, when the z-wave network restarts, may look out of sync
for a few minutes. However, after the full network restart is complete,
everything looks good in my testing.

* Fix linter
This commit is contained in:
Andrew Hayworth authored and John Arild Berentsen committed 2018-12-07 21:17:34 +01:00
1 parent a58b3aad59
commit 05586de51f
2 files changed
+90 -14

No files matched your search

+45 -1
View File
@@ -62,7 +62,7 @@ def test_lock_value_changed(mock_openzwave):
assert device.is_locked
def test_lock_value_changed_workaround(mock_openzwave):
def test_lock_state_workaround(mock_openzwave):
"""Test value changed for Z-Wave lock using notification state."""
node = MockNode(manufacturer_id='0090', product_id='0440')
values = MockEntityValues(
@@ -78,6 +78,50 @@ def test_lock_value_changed_workaround(mock_openzwave):
assert not device.is_locked
def test_track_message_workaround(mock_openzwave):
"""Test value changed for Z-Wave lock by alarm-clearing workaround."""
node = MockNode(manufacturer_id='003B', product_id='5044',
stats={'lastReceivedMessage': [0] * 6})
values = MockEntityValues(
primary=MockValue(data=True, node=node),
access_control=None,
alarm_type=None,
alarm_level=None,
)
# Here we simulate an RF lock. The first zwave.get_device will call
# update properties, simulating the first DoorLock report. We then trigger
# a change, simulating the openzwave automatic refreshing behavior (which
# is enabled for at least the lock that needs this workaround)
node.stats['lastReceivedMessage'][5] = const.COMMAND_CLASS_DOOR_LOCK
device = zwave.get_device(node=node, values=values)
value_changed(values.primary)
assert device.is_locked
assert device.device_state_attributes[zwave.ATTR_NOTIFICATION] == 'RF Lock'
# Simulate a keypad unlock. We trigger a value_changed() which simulates
# the Alarm notification received from the lock. Then, we trigger
# value_changed() to simulate the automatic refreshing behavior.
values.access_control = MockValue(data=6, node=node)
values.alarm_type = MockValue(data=19, node=node)
values.alarm_level = MockValue(data=3, node=node)
node.stats['lastReceivedMessage'][5] = const.COMMAND_CLASS_ALARM
value_changed(values.access_control)
node.stats['lastReceivedMessage'][5] = const.COMMAND_CLASS_DOOR_LOCK
values.primary.data = False
value_changed(values.primary)
assert not device.is_locked
assert device.device_state_attributes[zwave.ATTR_LOCK_STATUS] == \
'Unlocked with Keypad by user 3'
# Again, simulate an RF lock.
device.lock()
node.stats['lastReceivedMessage'][5] = const.COMMAND_CLASS_DOOR_LOCK
value_changed(values.primary)
assert device.is_locked
assert device.device_state_attributes[zwave.ATTR_NOTIFICATION] == 'RF Lock'
def test_v2btze_value_changed(mock_openzwave):
"""Test value changed for v2btze Z-Wave lock."""
node = MockNode(manufacturer_id='010e', product_id='0002')