pull/7662/head
John Arild Berentsen 2017-05-19 13:40:26 +02:00 committed by GitHub
parent 7daa92249a
commit 5aa72562a7
2 changed files with 6 additions and 5 deletions

View File

@ -141,9 +141,10 @@ def async_setup_platform(hass, config, async_add_devices, discovery_info=None):
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)

View File

@ -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())
@ -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()