Skip to content

Commit

Permalink
Fix conflict after master merge
Browse files Browse the repository at this point in the history
  • Loading branch information
tehampson committed Nov 24, 2022
1 parent 299be93 commit 0936858
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
31 changes: 17 additions & 14 deletions src/controller/python/chip/yaml/constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def is_met(self, response) -> bool:
class _LoadableConstraint(BaseConstraint):
'''Constraints where value might be stored in VariableStorage needing runtime load.'''

def __init__(self, value, field_type, variable_storage: VariableStorage):
def __init__(self, value, field_type, variable_storage: VariableStorage, config_values: dict):
self._variable_storage = variable_storage
# When not none _indirect_value_key is binding a name to the constraint value, and the
# actual value can only be looked-up dynamically, which is why this is a key name.
Expand All @@ -50,8 +50,8 @@ def __init__(self, value, field_type, variable_storage: VariableStorage):
if isinstance(value, str) and self._variable_storage.is_key_saved(value):
self._indirect_value_key = value
else:
self._value = Converter.convert_yaml_type(
value, field_type)
self._value = Converter.parse_and_convert_yaml_value(
value, field_type, config_values)

def get_value(self):
'''Gets the current value of the constraint.
Expand Down Expand Up @@ -112,17 +112,19 @@ def is_met(self, response) -> bool:


class _ConstraintMinValue(_LoadableConstraint):
def __init__(self, min_value, field_type, variable_storage: VariableStorage):
super().__init__(min_value, field_type, variable_storage)
def __init__(self, min_value, field_type, variable_storage: VariableStorage,
config_values: dict):
super().__init__(min_value, field_type, variable_storage, config_values)

def is_met(self, response) -> bool:
min_value = self.get_value()
return response >= min_value


class _ConstraintMaxValue(_LoadableConstraint):
def __init__(self, max_value, field_type, variable_storage: VariableStorage):
super().__init__(max_value, field_type, variable_storage)
def __init__(self, max_value, field_type, variable_storage: VariableStorage,
config_values: dict):
super().__init__(max_value, field_type, variable_storage, config_values)

def is_met(self, response) -> bool:
max_value = self.get_value()
Expand Down Expand Up @@ -162,16 +164,17 @@ def is_met(self, response) -> bool:


class _ConstraintNotValue(_LoadableConstraint):
def __init__(self, not_value, field_type, variable_storage: VariableStorage):
super().__init__(not_value, field_type, variable_storage)
def __init__(self, not_value, field_type, variable_storage: VariableStorage,
config_values: dict):
super().__init__(not_value, field_type, variable_storage, config_values)

def is_met(self, response) -> bool:
not_value = self.get_value()
return response != not_value


def get_constraints(constraints, field_type,
variable_storage: VariableStorage) -> list[BaseConstraint]:
def get_constraints(constraints, field_type, variable_storage: VariableStorage,
config_values: dict) -> list[BaseConstraint]:
_constraints = []
if 'hasValue' in constraints:
_constraints.append(_ConstraintHasValue(constraints.get('hasValue')))
Expand All @@ -193,11 +196,11 @@ def get_constraints(constraints, field_type,

if 'minValue' in constraints:
_constraints.append(_ConstraintMinValue(
constraints.get('minValue'), field_type, variable_storage))
constraints.get('minValue'), field_type, variable_storage, config_values))

if 'maxValue' in constraints:
_constraints.append(_ConstraintMaxValue(
constraints.get('maxValue'), field_type, variable_storage))
constraints.get('maxValue'), field_type, variable_storage, config_values))

if 'contains' in constraints:
_constraints.append(_ConstraintContains(constraints.get('contains')))
Expand All @@ -213,6 +216,6 @@ def get_constraints(constraints, field_type,

if 'notValue' in constraints:
_constraints.append(_ConstraintNotValue(
constraints.get('notValue'), field_type, variable_storage))
constraints.get('notValue'), field_type, variable_storage, config_values))

return _constraints
3 changes: 2 additions & 1 deletion src/controller/python/chip/yaml/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,8 @@ def __init__(self, item: dict, cluster: str, context: _ExecutionContext):
if constraints:
self._constraints = get_constraints(constraints,
self._request_object.attribute_type.Type,
context.variable_storage)
context.variable_storage,
context.config_values)

def run_action(self, dev_ctrl: ChipDeviceCtrl, endpoint: int, node_id: int):
try:
Expand Down

0 comments on commit 0936858

Please sign in to comment.