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 async open support for various network-based devices #720

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

alexdewar
Copy link
Collaborator

@alexdewar alexdewar commented Nov 27, 2024

Description

This PR changes the various network-based devices to use the async_open feature. While I haven't been able to test this on the real hardware, unfortunately, I have checked that HTTP requests are sent after device opening (of course, they time out). I'm pretty confident it will work with the real hardware as the changes are pretty minimal, though you can never be sure. Jon has volunteered to test it while he's away, so I think we should just merge it; if it breaks things we can always revert and we don't want to be hanging around waiting to merge this.

Closes #415. Closes #666. Closes #667.

Type of change

  • New feature (non-breaking change which adds functionality)
  • Bug fix (non-breaking change which fixes an issue)
  • Documentation (non-breaking change that adds or improves the documentation)
  • Optimisation (non-breaking, back-end change that speeds up the code)

Key checklist

  • Pre-commit hooks run successfully (pre-commit run -a)
  • All tests pass (pytest)
  • The documentation builds without warnings (mkdocs build -s)
  • Check the GUI still works (if relevant)
  • Check the code works with actual hardware (if relevant)
  • Check the pyinstaller-built executable works (if relevant)

Further checks

  • Code is commented, particularly in hard-to-understand areas
  • Tests have been added or an issue has been opened to tackle that in the future. (Indicate issue here: # (issue))

Copy link

codecov bot commented Nov 27, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 86.88%. Comparing base (e225669) to head (9e5d3ad).
Report is 9 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #720      +/-   ##
==========================================
+ Coverage   86.87%   86.88%   +0.01%     
==========================================
  Files          69       69              
  Lines        3559     3562       +3     
==========================================
+ Hits         3092     3095       +3     
  Misses        467      467              

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

@alexdewar alexdewar requested review from dc2917, jamesturner246 and dalonsoa and removed request for dc2917 December 9, 2024 18:29
@alexdewar alexdewar marked this pull request as ready for review December 9, 2024 18:29
Copy link
Contributor

@dc2917 dc2917 left a comment

Choose a reason for hiding this comment

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

Seems sensible to me!

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.

The changes look good to me. Of course, only testing with the real hardware will reveal any issues.

@@ -122,6 +123,10 @@ def _on_reply_received(self, reply: QNetworkReply) -> None:

# If the status has changed, notify listeners
if new_status != self._status:
# On first update, we need to signal that the device is now open
if self._status == SpectrometerStatus.UNDEFINED:
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't it a bit odd that when it's undefined, it is set as open?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It is kinda ugly. Plus, if the server actually returned a status of UNDEFINED (this would be dumb -- but sometimes hardware does dumb things) then that would actually break our code.

I've changed it to be None instead.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sorry, to clarify -- I set it to UNDEFINED in __init__ before we actually have a status, so it's a sentinel value. But it's probably not a good idea, for the reason I mentioned

Previously we were using `SpectrometerStatus.UNDEFINED` as the initial value, but this is a bad idea because:

1. It's a bit ugly
2. The server could conceivably return `UNDEFINED` as a status, which would break our code -- probably best not to rely on this not happening
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants