From c69a1a889472c676513c7c54ecb868b12bbf571b Mon Sep 17 00:00:00 2001 From: danielpeintner Date: Thu, 7 Sep 2023 11:00:19 +0200 Subject: [PATCH] refactor: transform AAS description -> TD descriptions --- .../src/util/asset-interface-description.ts | 84 +++++++++++++------ .../test/AssetInterfaceDescriptionTest.ts | 5 ++ 2 files changed, 62 insertions(+), 27 deletions(-) diff --git a/packages/td-tools/src/util/asset-interface-description.ts b/packages/td-tools/src/util/asset-interface-description.ts index eb9c40192..7d0c39880 100644 --- a/packages/td-tools/src/util/asset-interface-description.ts +++ b/packages/td-tools/src/util/asset-interface-description.ts @@ -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 = {}; + 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) { diff --git a/packages/td-tools/test/AssetInterfaceDescriptionTest.ts b/packages/td-tools/test/AssetInterfaceDescriptionTest.ts index d84cc5464..3673526e6 100644 --- a/packages/td-tools/test/AssetInterfaceDescriptionTest.ts +++ b/packages/td-tools/test/AssetInterfaceDescriptionTest.ts @@ -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")