Skip to content

Commit ccea971

Browse files
refactor(td-tools): AID add TD term support for description, contentMediaType, const, default, and unit (#1137)
1 parent 112dce2 commit ccea971

2 files changed

Lines changed: 105 additions & 16 deletions

File tree

packages/td-tools/src/util/asset-interface-description.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -893,6 +893,15 @@ export class AssetInterfaceDescriptionUtil {
893893
modelType: "Property",
894894
});
895895
}
896+
// description
897+
if (propertyValue.description != null) {
898+
propertyValues.push({
899+
idShort: "description",
900+
valueType: "xs:string",
901+
value: propertyValue.description,
902+
modelType: "Property",
903+
});
904+
}
896905
// observable (if it deviates from the default == false only)
897906
if (propertyValue.observable != null && propertyValue.observable === true) {
898907
propertyValues.push({
@@ -902,6 +911,44 @@ export class AssetInterfaceDescriptionUtil {
902911
modelType: "Property",
903912
});
904913
}
914+
// contentMediaType
915+
if (propertyValue.contentMediaType != null) {
916+
propertyValues.push({
917+
idShort: "contentMediaType",
918+
valueType: "xs:string",
919+
value: propertyValue.contentMediaType,
920+
modelType: "Property",
921+
});
922+
}
923+
// TODO enum
924+
// const
925+
if (propertyValue.const != null) {
926+
propertyValues.push({
927+
idShort: "const",
928+
valueType: "xs:string",
929+
value: propertyValue.const,
930+
modelType: "Property",
931+
});
932+
}
933+
// default
934+
if (propertyValue.default != null) {
935+
propertyValues.push({
936+
idShort: "default",
937+
valueType: "xs:string",
938+
value: propertyValue.default,
939+
modelType: "Property",
940+
});
941+
}
942+
// unit
943+
if (propertyValue.unit != null) {
944+
propertyValues.push({
945+
idShort: "unit",
946+
valueType: "xs:string",
947+
value: propertyValue.unit,
948+
modelType: "Property",
949+
});
950+
}
951+
905952
// readOnly and writeOnly marked as EXTERNAL in AID spec
906953
// range and others? Simply add them as is?
907954

packages/td-tools/test/AssetInterfaceDescriptionTest.ts

Lines changed: 58 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,18 @@ class AssetInterfaceDescriptionUtilTest {
497497
},
498498
],
499499
},
500+
temperature: {
501+
description: "Temperature value of the weather station",
502+
type: "number",
503+
minimum: -32.5,
504+
maximum: 55.2,
505+
unit: "degreeCelsius",
506+
forms: [
507+
{
508+
href: "temp",
509+
},
510+
],
511+
},
500512
},
501513
};
502514

@@ -586,7 +598,7 @@ class AssetInterfaceDescriptionUtilTest {
586598
.to.be.an("array")
587599
.to.have.lengthOf.greaterThan(0);
588600
let hasPropertyStatus = false;
589-
let hasPropertyStatusDescription = false;
601+
let hasPropertyTemperature = false;
590602
for (const propertyValue of interactionValues.value) {
591603
if (propertyValue.idShort === "status") {
592604
hasPropertyStatus = true;
@@ -598,6 +610,7 @@ class AssetInterfaceDescriptionUtilTest {
598610
let hasTitle = false;
599611
let hasObservable = false;
600612
let hasForms = false;
613+
let hasPropertyStatusDescription = false;
601614
for (const propProperty of propertyValue.value) {
602615
if (propProperty.idShort === "type") {
603616
hasType = true;
@@ -636,29 +649,58 @@ class AssetInterfaceDescriptionUtilTest {
636649
expect(hasHtvMethodName).to.equal(true);
637650
}
638651
}
652+
if (propertyValue.description != null) {
653+
hasPropertyStatusDescription = true;
654+
expect(propertyValue)
655+
.to.have.property("description")
656+
.to.eql([
657+
{
658+
language: "en",
659+
text: "Statistic",
660+
},
661+
{
662+
language: "de",
663+
text: "Statistik",
664+
},
665+
]);
666+
}
639667
expect(hasType).to.equal(true);
640668
expect(hasTitle).to.equal(false);
641669
expect(hasObservable).to.equal(true);
642670
expect(hasForms).to.equal(true);
643-
}
644-
if (propertyValue.description != null) {
645-
hasPropertyStatusDescription = true;
671+
expect(hasPropertyStatusDescription).to.equal(true);
672+
} else if (propertyValue.idShort === "temperature") {
673+
hasPropertyTemperature = true;
646674
expect(propertyValue)
647-
.to.have.property("description")
648-
.to.eql([
649-
{
650-
language: "en",
651-
text: "Statistic",
652-
},
653-
{
654-
language: "de",
655-
text: "Statistik",
656-
},
657-
]);
675+
.to.have.property("value")
676+
.to.be.an("array")
677+
.to.have.lengthOf.greaterThan(0);
678+
let hasType = false;
679+
let hasDescription = false;
680+
let hasUnit = false;
681+
let hasForms = false;
682+
for (const propProperty of propertyValue.value) {
683+
if (propProperty.idShort === "type") {
684+
hasType = true;
685+
expect(propProperty.value).to.equal("number");
686+
} else if (propProperty.idShort === "description") {
687+
hasDescription = true;
688+
expect(propProperty.value).to.equal("Temperature value of the weather station");
689+
} else if (propProperty.idShort === "unit") {
690+
hasUnit = true;
691+
expect(propProperty.value).to.equal("degreeCelsius");
692+
} else if (propProperty.idShort === "forms") {
693+
hasForms = true;
694+
}
695+
}
696+
expect(hasType).to.equal(true);
697+
expect(hasDescription).to.equal(true);
698+
expect(hasUnit).to.equal(true);
699+
expect(hasForms).to.equal(true);
658700
}
659701
}
660702
expect(hasPropertyStatus).to.equal(true);
661-
expect(hasPropertyStatusDescription).to.equal(true);
703+
expect(hasPropertyTemperature).to.equal(true);
662704
}
663705
}
664706
expect(hasProperties).to.equal(true);

0 commit comments

Comments
 (0)