diff --git a/finesse/hardware/plugins/sensors/decades.py b/finesse/hardware/plugins/sensors/decades.py index 9e154838..3dcb6e79 100644 --- a/finesse/hardware/plugins/sensors/decades.py +++ b/finesse/hardware/plugins/sensors/decades.py @@ -120,7 +120,7 @@ def __init__( self._params: list[DecadesParameter] """Parameters returned by the server.""" - super().__init__(poll_interval, start_polling=False) + super().__init__(poll_interval) # Obtain full parameter list in order to parse received data self.obtain_parameter_list( diff --git a/finesse/hardware/plugins/sensors/em27_sensors.py b/finesse/hardware/plugins/sensors/em27_sensors.py index 1e9f6163..6a5d290c 100644 --- a/finesse/hardware/plugins/sensors/em27_sensors.py +++ b/finesse/hardware/plugins/sensors/em27_sensors.py @@ -69,7 +69,7 @@ def __init__(self, url: str, poll_interval: float = float("nan")) -> None: self._requester = HTTPRequester() self._connected = False - super().__init__(poll_interval, start_polling=False) + super().__init__(poll_interval) self.request_readings() diff --git a/finesse/hardware/plugins/sensors/sensors_base.py b/finesse/hardware/plugins/sensors/sensors_base.py index 4256060d..103a6572 100644 --- a/finesse/hardware/plugins/sensors/sensors_base.py +++ b/finesse/hardware/plugins/sensors/sensors_base.py @@ -23,15 +23,12 @@ class SensorsBase( calling send_readings_message() with new sensor values (at some point). """ - def __init__( - self, poll_interval: float = float("nan"), start_polling: bool = True - ) -> None: + def __init__(self, poll_interval: float = float("nan")) -> None: """Create a new SensorsBase. Args: poll_interval: How often to poll the sensor device (seconds). If set to nan, the device will only be polled once on device open - start_polling: Whether to start polling the device immediately """ super().__init__() @@ -39,9 +36,6 @@ def __init__( self._poll_timer.timeout.connect(self.request_readings) self._poll_interval = poll_interval - if start_polling: - self.start_polling() - def start_polling(self) -> None: """Begin polling the device.""" if not isnan(self._poll_interval): diff --git a/tests/hardware/plugins/sensors/test_sensors_base.py b/tests/hardware/plugins/sensors/test_sensors_base.py index 0f872992..04362c5c 100644 --- a/tests/hardware/plugins/sensors/test_sensors_base.py +++ b/tests/hardware/plugins/sensors/test_sensors_base.py @@ -16,34 +16,27 @@ def device(timer_mock: Mock) -> SensorsBase: class _MockSensorsDevice(SensorsBase, description="Mock sensors device"): - def __init__(self, poll_interval: float = float("nan"), start_polling=True): + def __init__(self, poll_interval: float = float("nan")): self.request_readings_mock = MagicMock() - super().__init__(poll_interval, start_polling) + super().__init__(poll_interval) def request_readings(self) -> None: self.request_readings_mock() -@pytest.mark.parametrize("start_polling", (False, True)) @patch("finesse.hardware.plugins.sensors.sensors_base.QTimer") -def test_init(timer_mock: Mock, start_polling: bool) -> None: +def test_init(timer_mock: Mock) -> None: """Test for the constructor.""" - with patch.object(_MockSensorsDevice, "start_polling") as start_mock: - device = _MockSensorsDevice(1.0, start_polling) - assert device._poll_interval == 1.0 - timer = cast(Mock, device._poll_timer) - timer.timeout.connect.assert_called_once_with(device.request_readings) - - if start_polling: - start_mock.assert_called_once_with() - else: - start_mock.assert_not_called() + device = _MockSensorsDevice(1.0) + assert device._poll_interval == 1.0 + timer = cast(Mock, device._poll_timer) + timer.timeout.connect.assert_called_once_with(device.request_readings) @patch("finesse.hardware.plugins.sensors.sensors_base.QTimer") def test_start_polling_oneshot(timer_mock: Mock) -> None: """Test the start_polling() method when polling is only done once.""" - device = _MockSensorsDevice(start_polling=False) + device = _MockSensorsDevice() device.start_polling() timer = cast(Mock, device._poll_timer) @@ -53,7 +46,7 @@ def test_start_polling_oneshot(timer_mock: Mock) -> None: @patch("finesse.hardware.plugins.sensors.sensors_base.QTimer") def test_start_polling_repeated(timer_mock: Mock) -> None: """Test the start_polling() method when polling is only done repeatedly.""" - device = _MockSensorsDevice(1.0, start_polling=False) + device = _MockSensorsDevice(1.0) device.start_polling() timer = cast(Mock, device._poll_timer)