Skip to content

Commit

Permalink
refactor(td-tools): AID add TD term support for description, contentM…
Browse files Browse the repository at this point in the history
…ediaType, const, default, and unit (#1137)
  • Loading branch information
danielpeintner authored Oct 24, 2023
1 parent 112dce2 commit ccea971
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 16 deletions.
47 changes: 47 additions & 0 deletions packages/td-tools/src/util/asset-interface-description.ts
Original file line number Diff line number Diff line change
Expand Up @@ -893,6 +893,15 @@ export class AssetInterfaceDescriptionUtil {
modelType: "Property",
});
}
// description
if (propertyValue.description != null) {
propertyValues.push({
idShort: "description",
valueType: "xs:string",
value: propertyValue.description,
modelType: "Property",
});
}
// observable (if it deviates from the default == false only)
if (propertyValue.observable != null && propertyValue.observable === true) {
propertyValues.push({
Expand All @@ -902,6 +911,44 @@ export class AssetInterfaceDescriptionUtil {
modelType: "Property",
});
}
// contentMediaType
if (propertyValue.contentMediaType != null) {
propertyValues.push({
idShort: "contentMediaType",
valueType: "xs:string",
value: propertyValue.contentMediaType,
modelType: "Property",
});
}
// TODO enum
// const
if (propertyValue.const != null) {
propertyValues.push({
idShort: "const",
valueType: "xs:string",
value: propertyValue.const,
modelType: "Property",
});
}
// default
if (propertyValue.default != null) {
propertyValues.push({
idShort: "default",
valueType: "xs:string",
value: propertyValue.default,
modelType: "Property",
});
}
// unit
if (propertyValue.unit != null) {
propertyValues.push({
idShort: "unit",
valueType: "xs:string",
value: propertyValue.unit,
modelType: "Property",
});
}

// readOnly and writeOnly marked as EXTERNAL in AID spec
// range and others? Simply add them as is?

Expand Down
74 changes: 58 additions & 16 deletions packages/td-tools/test/AssetInterfaceDescriptionTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,18 @@ class AssetInterfaceDescriptionUtilTest {
},
],
},
temperature: {
description: "Temperature value of the weather station",
type: "number",
minimum: -32.5,
maximum: 55.2,
unit: "degreeCelsius",
forms: [
{
href: "temp",
},
],
},
},
};

Expand Down Expand Up @@ -586,7 +598,7 @@ class AssetInterfaceDescriptionUtilTest {
.to.be.an("array")
.to.have.lengthOf.greaterThan(0);
let hasPropertyStatus = false;
let hasPropertyStatusDescription = false;
let hasPropertyTemperature = false;
for (const propertyValue of interactionValues.value) {
if (propertyValue.idShort === "status") {
hasPropertyStatus = true;
Expand All @@ -598,6 +610,7 @@ class AssetInterfaceDescriptionUtilTest {
let hasTitle = false;
let hasObservable = false;
let hasForms = false;
let hasPropertyStatusDescription = false;
for (const propProperty of propertyValue.value) {
if (propProperty.idShort === "type") {
hasType = true;
Expand Down Expand Up @@ -636,29 +649,58 @@ class AssetInterfaceDescriptionUtilTest {
expect(hasHtvMethodName).to.equal(true);
}
}
if (propertyValue.description != null) {
hasPropertyStatusDescription = true;
expect(propertyValue)
.to.have.property("description")
.to.eql([
{
language: "en",
text: "Statistic",
},
{
language: "de",
text: "Statistik",
},
]);
}
expect(hasType).to.equal(true);
expect(hasTitle).to.equal(false);
expect(hasObservable).to.equal(true);
expect(hasForms).to.equal(true);
}
if (propertyValue.description != null) {
hasPropertyStatusDescription = true;
expect(hasPropertyStatusDescription).to.equal(true);
} else if (propertyValue.idShort === "temperature") {
hasPropertyTemperature = true;
expect(propertyValue)
.to.have.property("description")
.to.eql([
{
language: "en",
text: "Statistic",
},
{
language: "de",
text: "Statistik",
},
]);
.to.have.property("value")
.to.be.an("array")
.to.have.lengthOf.greaterThan(0);
let hasType = false;
let hasDescription = false;
let hasUnit = false;
let hasForms = false;
for (const propProperty of propertyValue.value) {
if (propProperty.idShort === "type") {
hasType = true;
expect(propProperty.value).to.equal("number");
} else if (propProperty.idShort === "description") {
hasDescription = true;
expect(propProperty.value).to.equal("Temperature value of the weather station");
} else if (propProperty.idShort === "unit") {
hasUnit = true;
expect(propProperty.value).to.equal("degreeCelsius");
} else if (propProperty.idShort === "forms") {
hasForms = true;
}
}
expect(hasType).to.equal(true);
expect(hasDescription).to.equal(true);
expect(hasUnit).to.equal(true);
expect(hasForms).to.equal(true);
}
}
expect(hasPropertyStatus).to.equal(true);
expect(hasPropertyStatusDescription).to.equal(true);
expect(hasPropertyTemperature).to.equal(true);
}
}
expect(hasProperties).to.equal(true);
Expand Down

0 comments on commit ccea971

Please sign in to comment.