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

Add support for typed device parameters #428

Merged
merged 10 commits into from
Nov 23, 2023
Merged

Add support for typed device parameters #428

merged 10 commits into from
Nov 23, 2023

Conversation

alexdewar
Copy link
Collaborator

This PR adds support for specifying arbitrary device parameters via a text box, rather than having to choose from a set list in a combo box (#377).

The changes to the frontend are fairly minimal. The device management dialog will now display text boxes or combo boxes for each of the parameters, depending on which is appropriate. While there are no labels saying what each parameter is, a description is provided in a tooltip so the user can find out by hovering.

The backend changes were a bit more invasive. I refactored the device plugin code, so now the user just has to specify the names of the parameters along with a description and, optionally, the list of possible values.

For example, the signature for the EM27Sensors class now looks like this:

class EM27Sensors(
    EM27SensorsBase,
    description="EM27 sensors",
    parameters={
        "host": "The IP address or hostname of the EM27 device",
        "poll_interval": "How often to poll the device in seconds",
    },
):

(Both of these are typed device params, i.e. their values can be arbitrary.)

The types and default values are automatically worked out from the constructor's signature:

    def __init__(
        self, host: str = EM27_HOST, poll_interval: float = EM27_SENSORS_POLL_INTERVAL
    ) -> None:

If a child class changes/adds a default value for these params in its own constructor, then these will be used instead. This feature was added with SerialDevices in mind: it now means that devices can specify a default baudrate in their constructors, without having to provide an extra default_baudrate class argument, as it was before.

(I also implemented #403 at the same time.)

Closes #377. Closes #403.

@alexdewar alexdewar requested review from CWestICL, dalonsoa and dc2917 and removed request for CWestICL November 21, 2023 14:47
Copy link

codecov bot commented Nov 21, 2023

Codecov Report

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

Comparison is base (cc9f81c) 78.87% compared to head (5764459) 79.04%.

Files Patch % Lines
finesse/hardware/device.py 90.00% 4 Missing ⚠️
finesse/device_info.py 88.23% 2 Missing ⚠️
finesse/hardware/plugins/temperature/dp9800.py 66.66% 1 Missing ⚠️
finesse/hardware/plugins/temperature/senecak107.py 50.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #428      +/-   ##
==========================================
+ Coverage   78.87%   79.04%   +0.16%     
==========================================
  Files          56       56              
  Lines        2874     2925      +51     
==========================================
+ Hits         2267     2312      +45     
- Misses        607      613       +6     

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

@alexdewar
Copy link
Collaborator Author

@CWestICL This feature could be used for the SenecaK107 class, to let the user set the voltage and temperature ranges, which would be handy for Jon. I'll open an issue for it once this PR is ready to go

Copy link
Contributor

@dalonsoa dalonsoa left a comment

Choose a reason for hiding this comment

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

This is really neat! Just a question, but nothing to change.

Comment on lines +64 to +73
class SerialDevice(
AbstractDevice,
parameters={
"port": (
"USB port, including vendor ID, product ID and serial number",
tuple(_get_usb_serial_ports().keys()),
),
"baudrate": ("Baud rate", BAUDRATES),
},
):
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you have mentioned this before, but I do not remember the answer:

This will retrieve the available USB ports that have "something" connected to them when this module is loaded, right? So, if the device of interest is off because we forgot to switch it on, then it will not be found. If we switch on the device, the collection of available USB ports will not be updated, so it will not be possible to connect to the device, anyway, the only solution being to restart the software.

Is this correct or am I misunderstanding anything? Nor that you need to change anything, just checking what the protocol is in that, very common, situation.

Copy link
Collaborator Author

@alexdewar alexdewar Nov 22, 2023

Choose a reason for hiding this comment

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

Correct! This is the same as the existing behaviour and there is already an open issue for it: #335

I have an idea of how to fix it: the frontend could send a message to force a refresh of the COM ports before re-requesting the list of plugins. But it's more of a "could have" feature, so I haven't looked at it yet.

@alexdewar alexdewar merged commit 5138d67 into main Nov 23, 2023
12 of 13 checks passed
@alexdewar alexdewar deleted the typed_device_params branch November 23, 2023 11:08
alexdewar added a commit that referenced this pull request Apr 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants