settings: correctly handle diversions when key has other flags set

This commit is contained in:
Peter F. Patel-Schneider 2020-11-27 17:35:17 -05:00
parent 419a7722ad
commit 0427e5607e
2 changed files with 4 additions and 2 deletions

View File

@ -871,6 +871,7 @@ class ChoicesMapValidator(ChoicesValidator):
read_skip_byte_count=0,
write_prefix_bytes=b'',
extra_default=None,
mask=-1,
activate=0
):
assert choices_map is not None
@ -898,13 +899,14 @@ class ChoicesMapValidator(ChoicesValidator):
self._read_skip_byte_count = read_skip_byte_count if read_skip_byte_count else 0
self._write_prefix_bytes = write_prefix_bytes if write_prefix_bytes else b''
self.activate = activate
self.mask = mask
assert self._byte_count + self._read_skip_byte_count + self._key_byte_count <= 14
assert self._byte_count + len(self._write_prefix_bytes) + self._key_byte_count <= 14
def validate_read(self, reply_bytes, key):
start = self._key_byte_count + self._read_skip_byte_count
end = start + self._byte_count
reply_value = _bytes2int(reply_bytes[start:end])
reply_value = _bytes2int(reply_bytes[start:end]) & self.mask
# reprogrammable keys starts out as 0, which is not a choice, so don't use assert here
if self.extra_default is not None and self.extra_default == reply_value:
return int(self.choices[key][0])

View File

@ -564,7 +564,7 @@ def _feature_divert_keys_callback(device):
return None
if not choices:
return None
return _ChoicesMapV(choices, key_byte_count=2, byte_count=1, activate=0x02)
return _ChoicesMapV(choices, key_byte_count=2, byte_count=1, mask=0x01, activate=0x02)
def _feature_divert_keys():