Skip to content

Commit

Permalink
In maintel/mtcs.py, add a context manager to ensure m1m3 is in engine…
Browse files Browse the repository at this point in the history
…ering mode before/after some operation.
  • Loading branch information
tribeiro authored and edennihy committed Dec 13, 2024
1 parent 5939008 commit 21b18b3
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions python/lsst/ts/observatory/control/maintel/mtcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 21b18b3

Please sign in to comment.