Remove ozw lock service for loops, replace with get_value() (#39735)

This commit is contained in:
Chris 2020-09-06 23:39:23 -07:00 committed by GitHub
parent cd0195a27a
commit 12cc158b64
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,7 +1,7 @@
"""Representation of Z-Wave locks.""" """Representation of Z-Wave locks."""
import logging import logging
from openzwavemqtt.const import CommandClass from openzwavemqtt.const import CommandClass, ValueIndex
import voluptuous as vol import voluptuous as vol
from homeassistant.components.lock import DOMAIN as LOCK_DOMAIN, LockEntity from homeassistant.components.lock import DOMAIN as LOCK_DOMAIN, LockEntity
@ -73,35 +73,25 @@ class ZWaveLock(ZWaveDeviceEntity, LockEntity):
@callback @callback
def async_set_usercode(self, code_slot, usercode): def async_set_usercode(self, code_slot, usercode):
"""Set the usercode to index X on the lock.""" """Set the usercode to index X on the lock."""
lock_node = self.values.primary.node.values() value = self.values.primary.node.get_value(CommandClass.USER_CODE, code_slot)
for value in lock_node: if len(str(usercode)) < 4:
if ( _LOGGER.error(
value.command_class == CommandClass.USER_CODE "Invalid code provided: (%s) user code must be at least 4 digits",
and value.index == code_slot usercode,
): )
if len(str(usercode)) < 4: return
_LOGGER.error( value.send_value(usercode)
"Invalid code provided: (%s) user code must be at least 4 digits", _LOGGER.debug("User code at slot %s set", code_slot)
usercode,
)
break
value.send_value(usercode)
_LOGGER.debug("User code at slot %s set", code_slot)
break
@callback @callback
def async_clear_usercode(self, code_slot): def async_clear_usercode(self, code_slot):
"""Clear usercode in slot X on the lock.""" """Clear usercode in slot X on the lock."""
lock_node = self.values.primary.node.values() value = self.values.primary.node.get_value(
CommandClass.USER_CODE, ValueIndex.CLEAR_USER_CODE
)
for value in lock_node: value.send_value(code_slot)
if ( # Sending twice because the first time it doesn't take
value.command_class == CommandClass.USER_CODE value.send_value(code_slot)
and value.label == "Remove User Code" _LOGGER.info("Usercode at slot %s is cleared", code_slot)
):
value.send_value(code_slot)
# Sending twice because the first time it doesn't take
value.send_value(code_slot)
_LOGGER.info("Usercode at slot %s is cleared", code_slot)
break