Skip to content

Commit

Permalink
Proof of concept for allowing chip-repl test to send invalid enum values
Browse files Browse the repository at this point in the history
  • Loading branch information
tehampson committed Jan 18, 2023
1 parent adb81d7 commit 1944656
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/controller/python/chip/clusters/Objects.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 11 additions & 3 deletions src/controller/python/chip/yaml/format_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# limitations under the License.
#

import enum
from aenum import Enum, extend_enum
import typing
from dataclasses import dataclass

Expand All @@ -30,6 +30,8 @@ class _TargetTypeInfo:
field: typing.Union[list[matter_idl_types.Field], matter_idl_types.Field]
is_fabric_scoped: bool

_dummy_count = 0


def _case_insensitive_getattr(object, attr_name, default):
for attr in dir(object):
Expand Down Expand Up @@ -201,8 +203,14 @@ def convert_to_data_model_type(field_value, field_type):
value = int(field_value)
return field_type(value)
# YAML treats enums as ints. Convert to the typed enum class.
elif (issubclass(field_type, enum.Enum)):
return field_type(field_value)
elif (issubclass(field_type, Enum)):
try:
return field_type(field_value)
except ValueError:
global _dummy_count
extend_enum(field_type, F'kDummy{_dummy_count}', field_value)
_dummy_count = _dummy_count + 1
return field_type(field_value)
# By default, just return the field_value casted to field_type.
else:
return field_type(field_value)

0 comments on commit 1944656

Please sign in to comment.