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

Align value function to Scripting API #1217

Merged
merged 4 commits into from
Jan 17, 2024
Merged

Conversation

relu91
Copy link
Member

@relu91 relu91 commented Jan 16, 2024

As discussed in #1216, the current implementation of the value function didn't take into account the validation of the DataSchema of the target affordance. This PR fix #1216 but it also introduces some required changes to take into account the new behavior in other places of the codebase. In particular, it updates the exploreDirectory method and ThingDiscoveryProcess class moving the fetching of the list of ThingDescirption from the method to the async iterator. The main reason for this change is that I figured out that with a DataSchema the readProperty would throw before entering even starting the ThingDiscoveryProcess which would be strange and violate the contract of the method exploreDirectory (errors for the list should be conveyed as errors in the ThingDesscovery object). Plus it has the benefit of lazy loading the list of TDs and they might be even controlled with limit and offset later. Handling the case in which the TDD does not have the DataSchema declared is still a TODO (but I can include in this PR).

Finally, I fixed a minor problem in the binding-file that was preventing a clean test run on my local machine.

@relu91
Copy link
Member Author

relu91 commented Jan 16, 2024

Ah it seems that I didn't properly rebase with master, after lunch I'll fix it. Sorry!

…th spec

Note that the exploreDirectory method has to be updated to reflect the
new check for the presence of DataSchema in the value function.
Tests have been updated too. In particular opcua required an ad hoc
parsing.

fix eclipse-thingweb#1216
Copy link

codecov bot commented Jan 16, 2024

Codecov Report

Attention: 5 lines in your changes are missing coverage. Please review.

Comparison is base (6901b5a) 77.73% compared to head (ac4e5ae) 77.75%.

Files Patch % Lines
packages/core/src/interaction-output.ts 87.80% 5 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1217      +/-   ##
==========================================
+ Coverage   77.73%   77.75%   +0.01%     
==========================================
  Files          84       84              
  Lines       17443    17444       +1     
  Branches     1761     1765       +4     
==========================================
+ Hits        13559    13563       +4     
+ Misses       3848     3845       -3     
  Partials       36       36              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@JKRhb JKRhb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, @relu91! See a couple of initial comments below.

let rawThingDescriptions: WoT.ThingDescription[];
try {
const thingsPropertyOutput = await this.directory.readProperty("things");
rawThingDescriptions = (await thingsPropertyOutput.value()) as WoT.ThingDescription[];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we use the generic "version" of value<T> here to avoid the casting?

Suggested change
rawThingDescriptions = (await thingsPropertyOutput.value()) as WoT.ThingDescription[];
rawThingDescriptions = await thingsPropertyOutput.value<WoT.ThingDescription[]>());

Copy link
Member Author

@relu91 relu91 Jan 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sadly no, Given the fact that CosumeThing implementation returns WoT.InteractionOutput and not our InteractionOutput. As I said another time the generic in the value function is mostly experimental... we should think if it makes sense to have it in the public APIs.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, then we can mark this thread as resolved :) Or should we open an issue for the evaluation of the generic in the value function?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the issue should be raised in the Scripting API repo, first (maybe it is already there?) and if it fails we have to evaluate how to do it here. @danielpeintner what do you think?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not aware of a related issue in the Scripting API repo. Raising the aspect makes sense and maybe gives some more feedback from others...

packages/core/src/interaction-output.ts Outdated Show resolved Hide resolved
packages/core/src/interaction-output.ts Outdated Show resolved Hide resolved
Copy link
Member

@danielpeintner danielpeintner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

Some minor proposals below.

packages/binding-opcua/test/full-opcua-thing-test.ts Outdated Show resolved Hide resolved
Co-authored-by: danielpeintner <daniel.peintner@gmail.com>
@relu91 relu91 merged commit cee07c2 into eclipse-thingweb:master Jan 17, 2024
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Should InteractionOutput.value() require a DataSchema?
3 participants