Skip to content

Commit

Permalink
Monitor and close dome during daytime
Browse files Browse the repository at this point in the history
  • Loading branch information
albireox committed Dec 25, 2024
1 parent fba6100 commit 098b7ea
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
16 changes: 16 additions & 0 deletions python/lvmecp/actor/actor.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ def __init__(
self.semaphore = asyncio.Semaphore(5)

self._emit_status_task: asyncio.Task | None = None
self._monitor_dome_task: asyncio.Task | None = None

self._engineering_mode: bool = False
self._engineering_mode_task: asyncio.Task | None = None
Expand All @@ -81,13 +82,16 @@ async def start(self, **kwargs):
await self.plc.start_modules()

self._emit_status_task = asyncio.create_task(self.emit_status())
self._monitor_dome_task = asyncio.create_task(self.monitor_dome())

Check warning on line 85 in python/lvmecp/actor/actor.py

View check run for this annotation

Codecov / codecov/patch

python/lvmecp/actor/actor.py#L85

Added line #L85 was not covered by tests

return self

async def stop(self, **kwargs):
"""Stops the actor."""

self._emit_status_task = await cancel_task(self._emit_status_task)
self._monitor_dome_task = await cancel_task(self._monitor_dome_task)

self._engineering_mode_task = await cancel_task(self._engineering_mode_task)

await super().stop(**kwargs)
Expand All @@ -102,6 +106,18 @@ async def emit_status(self, delay: float = 30.0):
await self.send_command(self.name, "status", internal=True)
await asyncio.sleep(delay)

async def monitor_dome(self, delay: float = 30.0):
"""Monitors the dome and closes during daytime."""

while True:
await asyncio.sleep(delay)

if self._engineering_mode:
pass
elif self.plc.dome.is_daytime():
self.write("w", text="Dome found open during daytime. Closing.")
await self.plc.dome.close()

async def engineering_mode(
self,
enable: bool,
Expand Down
28 changes: 28 additions & 0 deletions tests/test_command_dome.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

from __future__ import annotations

import asyncio

from typing import TYPE_CHECKING

import lvmecp.dome
Expand Down Expand Up @@ -81,3 +83,29 @@ async def test_command_dome_daytime_eng_mode(actor: ECPActor, mocker: MockerFixt
await cmd

assert cmd.status.did_succeed


async def test_actor_daytime_task(actor: ECPActor, mocker: MockerFixture):
mocker.patch.object(actor.plc.dome, "is_daytime", return_value=True)
dome_close_mock = mocker.patch.object(actor.plc.dome, "close")

task = asyncio.create_task(actor.monitor_dome(delay=0.1))
await asyncio.sleep(0.2)

dome_close_mock.assert_called_once()

task.cancel()


async def test_actor_daytime_task_eng_mode(actor: ECPActor, mocker: MockerFixture):
mocker.patch.object(actor.plc.dome, "is_daytime", return_value=True)
mocker.patch.object(actor, "_engineering_mode", return_value=True)

dome_close_mock = mocker.patch.object(actor.plc.dome, "close")

task = asyncio.create_task(actor.monitor_dome(delay=0.1))
await asyncio.sleep(0.2)

dome_close_mock.assert_not_called()

task.cancel()

0 comments on commit 098b7ea

Please sign in to comment.