diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml index 9a1f3247..aee2f966 100644 --- a/.github/workflows/lint.yaml +++ b/.github/workflows/lint.yaml @@ -18,8 +18,8 @@ jobs: - name: Install run: | $CONDA/bin/conda config --set solver classic - $CONDA/bin/conda install -c lsstts -c conda-forge pre-commit ts-pre-commit-config python=3.11 -y - $CONDA/bin/conda install -c conda-forge pre-commit -y + $CONDA/bin/conda install -c lsstts -c conda-forge pre-commit ts-pre-commit-config python=3.11 identify>=2.6 -y + $CONDA/bin/conda install -c conda-forge pre-commit identify>=2.6 -y $CONDA/bin/generate_pre_commit_conf --skip-pre-commit-install - name: Run pre commit checks diff --git a/doc/news/DM-47890.feature.2.rst b/doc/news/DM-47890.feature.2.rst new file mode 100644 index 00000000..097b2e3f --- /dev/null +++ b/doc/news/DM-47890.feature.2.rst @@ -0,0 +1 @@ +In maintel/mtcs.py, remove settling time after clearing slew flag (currently refered to as close booster valve in the code). diff --git a/doc/news/DM-47890.feature.3.rst b/doc/news/DM-47890.feature.3.rst new file mode 100644 index 00000000..510dde6a --- /dev/null +++ b/doc/news/DM-47890.feature.3.rst @@ -0,0 +1 @@ +In maintel/mtcs.py, add a context manager to ensure m1m3 is in engineering mode before/after some operation and add unit tests. diff --git a/python/lsst/ts/observatory/control/maintel/mtcs.py b/python/lsst/ts/observatory/control/maintel/mtcs.py index 5ddb34ed..c8e35bc6 100644 --- a/python/lsst/ts/observatory/control/maintel/mtcs.py +++ b/python/lsst/ts/observatory/control/maintel/mtcs.py @@ -1707,6 +1707,22 @@ async def exit_m1m3_engineering_mode(self) -> None: else: self.log.warning("M1M3 not in engineering mode.") + @contextlib.asynccontextmanager + async def m1m3_in_engineering_mode(self) -> typing.AsyncIterator[None]: + """Context manager to ensure m1m3 enters and exists engineering + mode before/after an operation. + + If M1M3 is in engineering mode before, this context manager is a + nop, e.g. it will leave M1M3 in engineering mode afterwards. + """ + try: + m1m3_in_engineering_mode_before = await self.is_m1m3_in_engineering_mode() + await self.enter_m1m3_engineering_mode() + yield + finally: + if not m1m3_in_engineering_mode_before: + await self.exit_m1m3_engineering_mode() + async def run_m1m3_hard_point_test(self, hp: int) -> None: """Test an M1M3 hard point. @@ -2628,7 +2644,6 @@ async def close_m1m3_booster_valve(self) -> None: """Close M1M3 booster valves.""" if self.check.mtm1m3: await self._handle_m1m3_booster_valve(open=False) - await asyncio.sleep(self.fast_timeout) async def _handle_m1m3_booster_valve(self, open: bool) -> None: """Handle opening the M1M3 booster valves""" diff --git a/tests/maintel/test_mtcs.py b/tests/maintel/test_mtcs.py index 9534c59f..cb470afa 100644 --- a/tests/maintel/test_mtcs.py +++ b/tests/maintel/test_mtcs.py @@ -2455,3 +2455,22 @@ async def assert_m1m3_slew_settings_applied( assert ( actual_settings[setting] == expected_value ), f"Setting {setting} expected to be {expected_value} but was {actual_settings[setting]}" + + async def test_m1m3_in_engineering_mode(self) -> None: + + async with self.mtcs.m1m3_in_engineering_mode(): + await asyncio.sleep(0) + + self.mtcs.rem.mtm1m3.cmd_enterEngineering.start.assert_awaited_once() + self.mtcs.rem.mtm1m3.cmd_exitEngineering.start.assert_awaited_once() + + async def test_m1m3_in_engineering_mode_with_failed_op(self) -> None: + + try: + async with self.mtcs.m1m3_in_engineering_mode(): + raise RuntimeError("This is a test.") + except RuntimeError: + pass + + self.mtcs.rem.mtm1m3.cmd_enterEngineering.start.assert_awaited_once() + self.mtcs.rem.mtm1m3.cmd_exitEngineering.start.assert_awaited_once()