Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 3 additions & 2 deletions homeassistant/components/lock/zwave.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,10 @@ def set_usercode(service):
class_id=zwave.const.COMMAND_CLASS_USER_CODE).values():
if value.index != code_slot:
continue
if len(str(usercode)) > 4:
if len(str(usercode)) < 4:
_LOGGER.error("Invalid code provided: (%s) "
"usercode must %s or less digits",
"usercode must be atleast 4 and at most"
" %s digits",
usercode, len(value.data))
break
value.data = str(usercode)
Expand Down
6 changes: 3 additions & 3 deletions tests/components/lock/test_zwave.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,8 @@ def test_lock_set_usercode_service(hass, mock_openzwave):
"""Test the zwave lock set_usercode service."""
mock_network = hass.data[zwave.zwave.ZWAVE_NETWORK] = MagicMock()
node = MockNode(node_id=12)
value0 = MockValue(data=None, node=node, index=0)
value1 = MockValue(data=None, node=node, index=1)
value0 = MockValue(data=' ', node=node, index=0)
value1 = MockValue(data=' ', node=node, index=1)
yield from zwave.async_setup_platform(
hass, {}, MagicMock())

Expand Down Expand Up @@ -202,7 +202,7 @@ def test_lock_set_usercode_service(hass, mock_openzwave):
yield from hass.services.async_call(
zwave.DOMAIN, zwave.SERVICE_SET_USERCODE, {
const.ATTR_NODE_ID: node.node_id,
zwave.ATTR_USERCODE: '12345',
zwave.ATTR_USERCODE: '123',
zwave.ATTR_CODE_SLOT: 1,
})
yield from hass.async_block_till_done()
Expand Down