def _ValidateEntityBlock(self, block: syaml.YAML) -> None: """Validates a block of entities and adds them to the validated blocks. Args: block: YAML representing one or more entities Raises: ValueError: if block contains a key that has already been found. """ for key in block.keys(): if key in self._validated_entities: raise ValueError('Duplicate key {key}') self._ValidateEntityContent(block.get(key)) self._validated_entities.update(block.data)
def _ParseTranslation( translation_body: syaml.YAML ) -> Dict[str, field_translation.FieldTranslation]: """Parses YAML defining the translation of an entity's points. Args: translation_body: YAML body for the entity translation Returns: A dictionary from field names to FieldTranslation instances """ if isinstance(translation_body, str): return translation_body translation = {} # TODO(b/176094783): reuse the tuple from the ontology validator for std_field_name in translation_body.keys(): if isinstance(translation_body[std_field_name], str): continue # TODO(b/176097512): Manually defined non UDMI translations should be # accepted by the validator ft = translation_body[std_field_name] raw_field_name = str(ft[PRESENT_VALUE])\ .replace(PRESENT_VALUE, '')\ .replace(POINTS, '')\ .replace('.', '') units = dict() if UNITS_KEY in ft.keys(): units = ft[UNITS_KEY][VALUES_KEY] elif UNIT_VALUES_KEY in ft.keys(): units = ft[UNIT_VALUES_KEY] states = dict() if STATES_KEY in ft.keys(): states = ft[STATES_KEY] translation[std_field_name] = field_translation.FieldTranslation( std_field_name, raw_field_name, units, states) return translation