Skip to content

Commit

Permalink
Emit notification when closing due to daytime
Browse files Browse the repository at this point in the history
  • Loading branch information
albireox committed Dec 25, 2024
1 parent 5fd2388 commit cafb522
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
5 changes: 5 additions & 0 deletions python/lvmecp/actor/actor.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import time

from lvmopstools.actor import ErrorCodesBase, LVMActor
from lvmopstools.notifications import send_notification

from clu.tools import ActorHandler
from sdsstools.utils import cancel_task
Expand Down Expand Up @@ -116,6 +117,10 @@ async def monitor_dome(self, delay: float = 30.0):
pass
elif self.plc.dome.is_daytime():
self.write("w", text="Dome found open during daytime. Closing.")
await send_notification(
"Dome found open during daytime. Closing.",
level="warning",
)
await self.plc.dome.close()

async def engineering_mode(
Expand Down
1 change: 1 addition & 0 deletions python/lvmecp/dome.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ def is_allowed(self):
text="Daytime detected but engineering mode is active. "
"Allowing to open the dome.",
)

return True

return False
Expand Down
6 changes: 5 additions & 1 deletion tests/test_command_dome.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

from typing import TYPE_CHECKING

import lvmecp.actor.actor
import lvmecp.dome
from lvmecp.maskbits import DomeStatus

Expand Down Expand Up @@ -87,19 +88,22 @@ async def test_command_dome_daytime_eng_mode(actor: ECPActor, mocker: MockerFixt

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

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()
dome_close_mock.assert_called()

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)
mocker.patch.object(lvmecp.actor.actor, "send_notification")

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

Expand Down

0 comments on commit cafb522

Please sign in to comment.