settings: don't halt when trying to write invalid map choice

This commit is contained in:
Peter F. Patel-Schneider 2021-04-16 09:27:43 -04:00
parent 75fec689a0
commit 7add22e861
2 changed files with 5 additions and 4 deletions

View File

@ -925,9 +925,10 @@ class ChoicesMapValidator(ChoicesValidator):
return reply_value
def prepare_write(self, key, new_value):
choices = self.choices[key]
if new_value not in choices and new_value != self.extra_default:
raise ValueError('invalid choice %r' % new_value)
choices = self.choices.get(key)
if choices is None or (new_value not in choices and new_value != self.extra_default):
_log.error('invalid choice %r for %s', new_value, key)
return None
new_value = new_value | self.activate
return self._write_prefix_bytes + new_value.to_bytes(self._byte_count, 'big')

View File

@ -646,7 +646,7 @@ class DivertKeysRW(object):
def _feature_divert_keys_callback(device):
choices = {}
for k in device.keys:
if 'divertable' in k.flags:
if 'divertable' in k.flags and 'virtual' not in k.flags:
choices[k.key] = [_NamedInt(0x00, 'Regular'), _NamedInt(0x01, 'Diverted')]
if not choices:
return None