Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 37 additions & 2 deletions homeassistant/components/lock/zwave.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,37 @@
DANALOCK_V2_BTZE = 0x2
POLYCONTROL_DANALOCK_V2_BTZE_LOCK = (POLYCONTROL, DANALOCK_V2_BTZE)
WORKAROUND_V2BTZE = 'v2btze'
WORKAROUND_DEVICE_STATE = 'state'
# Kwikset 914TRL ZW500
KWIKSET = 0x0090
ZW500_914TRL = 0x440

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why all these constants that are only used once ? We should just inline them at the one place where they are used.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was just mirroring the pattern that was already in there for the Polycom workaround (and in other zwave components that have workaround sections) But, if it's that much of a problem I can change it to inline the ids in the device mapping dict.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well we only ever use the constant once, the code would get more readable if we just inline it. I would be open to accept another PR to fix this for the others too

KWIKSET_914TRL_ZW500 = (KWIKSET, ZW500_914TRL)
# Yale YRD210
YALE = 0x0129
YRD210 = 0x0209
YRD210_A = 0xAA00
YRD210_B = 0x0000
YALE_YRD210 = (YALE, YRD210)
YALE_YRD210_A = (YALE, YRD210_A)
YALE_YRD210_B = (YALE, YRD210_B)
# Yale YRD220 (as reported by adrum in PR #17386)
YALE_YRD220 = (0x0109, 0x0000)
# Schalge BE469 and FE599NX
SCHLAGE = 0x003B
BE469 = 0x5044
SCHLAGE_BE469 = (SCHLAGE, BE469)
FE599NX = 0x504C
SCLAGE_FE599NX = (SCHLAGE, FE599NX)

DEVICE_MAPPINGS = {
POLYCONTROL_DANALOCK_V2_BTZE_LOCK: WORKAROUND_V2BTZE
POLYCONTROL_DANALOCK_V2_BTZE_LOCK: WORKAROUND_V2BTZE,
KWIKSET_914TRL_ZW500: WORKAROUND_DEVICE_STATE,
YALE_YRD210: WORKAROUND_DEVICE_STATE,
YALE_YRD210_A: WORKAROUND_DEVICE_STATE,
YALE_YRD210_B: WORKAROUND_DEVICE_STATE,
YALE_YRD220: WORKAROUND_DEVICE_STATE,
SCHLAGE_BE469: WORKAROUND_DEVICE_STATE,
SCLAGE_FE599NX: WORKAROUND_DEVICE_STATE,
}

LOCK_NOTIFICATION = {
Expand Down Expand Up @@ -204,6 +232,7 @@ def __init__(self, values):
self._notification = None
self._lock_status = None
self._v2btze = None
self._state_workaround = False

# Enable appropriate workaround flags for our device
# Make sure that we have values for the key before converting to int
Expand All @@ -216,6 +245,11 @@ def __init__(self, values):
self._v2btze = 1
_LOGGER.debug("Polycontrol Danalock v2 BTZE "
"workaround enabled")
if DEVICE_MAPPINGS[specific_sensor_key] == \
WORKAROUND_DEVICE_STATE:
self._state_workaround = True
_LOGGER.debug(
"Notification device state workaround enabled")
self.update_properties()

def update_properties(self):
Expand All @@ -225,7 +259,8 @@ def update_properties(self):
if self.values.access_control:
notification_data = self.values.access_control.data
self._notification = LOCK_NOTIFICATION.get(str(notification_data))

if self._state_workaround:
self._state = LOCK_STATUS.get(str(notification_data))
if self._v2btze:
if self.values.v2btze_advanced and \
self.values.v2btze_advanced.data == CONFIG_ADVANCED:
Expand Down
16 changes: 16 additions & 0 deletions tests/components/lock/test_zwave.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,22 @@ def test_lock_value_changed(mock_openzwave):
assert device.is_locked


def test_lock_value_changed_workaround(mock_openzwave):
"""Test value changed for Z-Wave lock using notification state."""
node = MockNode(manufacturer_id='0090', product_id='0440')
values = MockEntityValues(
primary=MockValue(data=True, node=node),
access_control=MockValue(data=1, node=node),
alarm_type=None,
alarm_level=None,
)
device = zwave.get_device(node=node, values=values)
assert device.is_locked
values.access_control.data = 2
value_changed(values.access_control)
assert not device.is_locked


def test_v2btze_value_changed(mock_openzwave):
"""Test value changed for v2btze Z-Wave lock."""
node = MockNode(manufacturer_id='010e', product_id='0002')
Expand Down