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

Enumerate devices in plan schemas #526

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Enumerate devices in plan schemas #526

wants to merge 1 commit into from

Conversation

tpoliaw
Copy link
Contributor

@tpoliaw tpoliaw commented Jun 25, 2024

When a plan is expecting a device name, there is a limited number of
valid devices available to choose from. Making these available in the
schema allows clients to restrict input to valid options only.

Addresses #518

When a plan is expecting a device name, there is a limited number of
valid devices available to choose from. Making these available in the
schema allows clients to restrict input to valid options only.
@tpoliaw
Copy link
Contributor Author

tpoliaw commented Jun 25, 2024

Example schema (for set_relative)

{
    'additionalProperties': False,
     'properties': {'group': {'title': 'Group',
                              'type': 'string'},
                    'movable': {'enum': ['sample_pressure',
                                         'x_err',
                                         'theta',
                                         'z',
                                         'y',
                                         'x',
                                         'sample_temperature'],
                                'target_type': 'bluesky.protocols.Movable',
                                'title': 'Movable',
                                'type': 'string'},
                    'value': {'title': 'Value'},
                    'wait': {'title': 'Wait',
                             'type': 'boolean'}},
     'required': ['movable'],
     'title': 'set_relative',
     'type': 'object'}
}

Copy link

codecov bot commented Jun 25, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 91.06%. Comparing base (f0248fb) to head (eb887c6).
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #526   +/-   ##
=======================================
  Coverage   91.06%   91.06%           
=======================================
  Files          40       40           
  Lines        1779     1780    +1     
=======================================
+ Hits         1620     1621    +1     
  Misses        159      159           

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

"type": "string",
"enum": [
k
for k, v in self.devices.items()
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't believe there is any guaranteed order for registration of plans and devices, meaning that some devices may not be registered yet.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Isn't this method only called when the schema is called for? Does anything query schemas before everything is loaded?

Copy link
Contributor

Choose a reason for hiding this comment

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

No, the schemas are generated upfront when the plan is registered with the context. I don't mind if you make them lazy instead though.

@keithralphs
Copy link
Contributor

Example schema (for set_relative)

{
    'additionalProperties': False,
     'properties': {'group': {'title': 'Group',
                              'type': 'string'},
                    'movable': {'enum': ['sample_pressure',
                                         'x_err',
                                         'theta',
                                         'z',
                                         'y',
                                         'x',
                                         'sample_temperature'],
                                'target_type': 'bluesky.protocols.Movable',
                                'title': 'Movable',
                                'type': 'string'},
                    'value': {'title': 'Value'},
                    'wait': {'title': 'Wait',
                             'type': 'boolean'}},
     'required': ['movable'],
     'title': 'set_relative',
     'type': 'object'}
}

This seems to have an extra curly bracket in it (according to JSON validation) , typo maybe?, also shouldn't the False in additional properties be false? Apart from them it seems to render correctly in the browser via JSON when these are corrected.

@tpoliaw
Copy link
Contributor Author

tpoliaw commented Jun 26, 2024

Copy/paste/reformat error on my part I think copying from the output. Is the json returned in the response correct? And yes, I copied it from the test which uses Python

@keithralphs
Copy link
Contributor

Copy/paste/reformat error on my part I think copying from the output. Is the json returned in the response correct? And yes, I copied it from the test which uses Python

Haven't tried it dynamically yet, just copy/pasted it myself, corrected the errors and checked :). I'll run it up later and test it live.

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.

3 participants