Skip to content

Commit

Permalink
OpusInterface: Set initial status to None
Browse files Browse the repository at this point in the history
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
  • Loading branch information
alexdewar committed Dec 11, 2024
1 parent ca44260 commit 9e5d3ad
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions finesse/hardware/plugins/spectrometer/opus_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def __init__(
self._url = f"http://{host}:{port}/opusrs"
"""URL to make requests."""

self._status = SpectrometerStatus.UNDEFINED
self._status: SpectrometerStatus | None = None
"""The last known status of the spectrometer."""
self._status_timer = QTimer()
self._status_timer.timeout.connect(self._request_status)
Expand Down Expand Up @@ -124,7 +124,7 @@ 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:
if self._status is None:
self.signal_is_opened()

self._status = new_status
Expand Down
2 changes: 1 addition & 1 deletion tests/hardware/plugins/spectrometer/test_opus_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def test_init(timer_mock: Mock, subscribe_mock: Mock) -> None:
assert opus._url == f"http://{DEFAULT_OPUS_HOST}:{DEFAULT_OPUS_PORT}/opusrs"
status_mock.assert_called_once_with()

assert opus._status == SpectrometerStatus.UNDEFINED
assert opus._status is None
timer.setSingleShot.assert_called_once_with(True)
timer.setInterval.assert_called_once_with(1000)
timer.timeout.connect.assert_called_once_with(opus._request_status)
Expand Down

0 comments on commit 9e5d3ad

Please sign in to comment.