Skip to content

Commit

Permalink
refactor: transform AAS description -> TD descriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
danielpeintner committed Sep 7, 2023
1 parent f28dcf5 commit c69a1a8
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 27 deletions.
84 changes: 57 additions & 27 deletions packages/td-tools/src/util/asset-interface-description.ts
Original file line number Diff line number Diff line change
Expand Up @@ -453,35 +453,65 @@ export class AssetInterfaceDescriptionUtil {
thing.properties[key].forms = [];

for (const vi of value) {
// The first block of if condition is expected to be temporary. will be adjusted or removed when a decision on how the datapoint's datatype would be modelled is made for AID.
if (vi.interaction.value && vi.interaction.value instanceof Array) {
for (const interactionValue of vi.interaction.value)
if (interactionValue.idShort === "type") {
if (interactionValue.value === "float") {
thing.properties[key].type = "number";
} else {
thing.properties[key].type = interactionValue.value;
}
} else if (interactionValue.idShort === "range") {
if (interactionValue.min) {
thing.properties[key].min = interactionValue.min;
}
if (interactionValue.max) {
thing.properties[key].max = interactionValue.max;
for (const keyInteraction in vi.interaction) {
if (keyInteraction === "description") {
const aasDescription = vi.interaction[keyInteraction];
// convert
//
// [{
// "language": "en",
// "text": "Current counter value"
// },
// {
// "language": "de",
// "text": "Derzeitiger Zählerwert"
// }]
//
// to
//
// {"en": "Current counter value", "de": "Derzeitiger Zählerwert"}
const tdDescription: Record<string, string> = {};
if (aasDescription instanceof Array) {
for (const aasDescriptionEntry of aasDescription) {
if (aasDescriptionEntry.language && aasDescriptionEntry.text) {
const language: string = aasDescriptionEntry.language;
const text: string = aasDescriptionEntry.text;
tdDescription[language] = text;
}
}
} else if (interactionValue.idShort === "observable") {
thing.properties[key].observable = interactionValue.value === "true";
} else if (interactionValue.idShort === "readOnly") {
thing.properties[key].readOnly = interactionValue.value === "true";
} else if (interactionValue.idShort === "writeOnly") {
thing.properties[key].writeOnly = interactionValue.value === "true";
} else if (interactionValue.idShort === "forms") {
// will be handled below
} else {
// handle other terms specifically?
const key2 = interactionValue.idShort;
thing.properties[key][key2] = interactionValue.value;
}
thing.properties[key].descriptions = tdDescription;
} else if (keyInteraction === "value") {
if (vi.interaction.value instanceof Array) {
for (const interactionValue of vi.interaction.value)
if (interactionValue.idShort === "type") {
if (interactionValue.value === "float") {
thing.properties[key].type = "number";
} else {
thing.properties[key].type = interactionValue.value;
}
} else if (interactionValue.idShort === "range") {
if (interactionValue.min) {
thing.properties[key].min = interactionValue.min;
}
if (interactionValue.max) {
thing.properties[key].max = interactionValue.max;
}
} else if (interactionValue.idShort === "observable") {
thing.properties[key].observable = interactionValue.value === "true";
} else if (interactionValue.idShort === "readOnly") {
thing.properties[key].readOnly = interactionValue.value === "true";
} else if (interactionValue.idShort === "writeOnly") {
thing.properties[key].writeOnly = interactionValue.value === "true";
} else if (interactionValue.idShort === "forms") {
// will be handled below
} else {
// handle other terms specifically?
const key2 = interactionValue.idShort;
thing.properties[key][key2] = interactionValue.value;
}
}
}
}

if (vi.endpointMetadata) {
Expand Down
5 changes: 5 additions & 0 deletions packages/td-tools/test/AssetInterfaceDescriptionTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ class AssetInterfaceDescriptionUtilTest {

// check count property
expect(tdObj).to.have.property("properties").to.have.property("count");
expect(tdObj).to.have.property("properties").to.have.property("count").to.have.property("descriptions").to.eql({
en: "Current counter value",
de: "Derzeitiger Zählerwert",
it: "Valore attuale del contatore",
});
expect(tdObj)
.to.have.property("properties")
.to.have.property("count")
Expand Down

0 comments on commit c69a1a8

Please sign in to comment.