Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(td-tools): add support for more TD dataSchema terms #1137

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -904,6 +904,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 @@ -913,6 +922,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 @@ -496,6 +496,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 @@ -585,7 +597,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 @@ -597,6 +609,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 @@ -635,29 +648,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