Skip to content

Commit bb15d10

Browse files
authored
v0.1.0
version 0.1.0
2 parents 8345471 + 71db8a4 commit bb15d10

File tree

4 files changed

+128
-7
lines changed

4 files changed

+128
-7
lines changed

pyobs_brot/brotdome.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ async def _update_status(self) -> None:
7878
new_state = MotionStatus.POSITIONED
7979
if new_state != current_state:
8080
await self._change_motion_status(new_state)
81+
except asyncio.CancelledError:
82+
return
8183
except:
8284
pass
8385
await asyncio.sleep(1)

pyobs_brot/brotroof.py

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
import asyncio
2+
import logging
3+
from typing import Any
4+
5+
from pyobs.events import RoofOpenedEvent, RoofClosingEvent
6+
from pyobs.modules.roof.baseroof import BaseRoof
7+
from pyobs.modules import timeout
8+
from pyobs.utils.enums import MotionStatus
9+
10+
from pybrotlib import BROT
11+
from pybrotlib.mqtttransport import MQTTTransport
12+
from pybrotlib.roof import RoofStatus
13+
14+
log = logging.getLogger(__name__)
15+
16+
17+
class BrotRoof(BaseRoof):
18+
def __init__(
19+
self,
20+
host: str,
21+
name: str,
22+
port: int = 1883,
23+
**kwargs: Any,
24+
):
25+
BaseRoof.__init__(self, **kwargs)
26+
self.mqtt = MQTTTransport(host, port)
27+
self.brot = BROT(self.mqtt, name)
28+
29+
# add thread for pulling the status constantly
30+
self.add_background_task(self._update_status_task)
31+
32+
async def open(self) -> None:
33+
await BaseRoof.open(self)
34+
asyncio.create_task(self.mqtt.run())
35+
36+
await self.comm.register_event(RoofOpenedEvent)
37+
await self.comm.register_event(RoofClosingEvent)
38+
39+
async def _update_status_task(self) -> None:
40+
while True:
41+
if self.mqtt.connected:
42+
await self._update_status()
43+
await asyncio.sleep(1)
44+
45+
async def _update_status(self) -> None:
46+
# check whats up
47+
match self.brot.roof.status:
48+
case RoofStatus.ERROR:
49+
await self._error_state()
50+
case RoofStatus.CLOSED:
51+
await self._change_motion_status(MotionStatus.PARKED)
52+
case RoofStatus.OPENING:
53+
await self._change_motion_status(MotionStatus.INITIALIZING)
54+
case RoofStatus.CLOSING:
55+
await self._change_motion_status(MotionStatus.PARKING)
56+
case RoofStatus.OPEN:
57+
await self._change_motion_status(MotionStatus.POSITIONED)
58+
case RoofStatus.STOPPED:
59+
await self._change_motion_status(MotionStatus.IDLE)
60+
61+
@timeout(300)
62+
async def init(self, **kwargs: Any) -> None:
63+
log.info("Opening roof")
64+
if self.brot.roof.status == RoofStatus.OPEN:
65+
return
66+
elif self.brot.roof.status == RoofStatus.ERROR:
67+
await self._error_state("Roof is in error state. Cannot open.")
68+
return
69+
70+
await self._change_motion_status(MotionStatus.INITIALIZING)
71+
72+
# send open command
73+
await self.brot.roof.open()
74+
75+
while True:
76+
match self.brot.roof.shutter:
77+
case RoofStatus.OPEN:
78+
log.info("Roof is open.")
79+
break
80+
case _:
81+
pass
82+
await asyncio.sleep(1)
83+
84+
await self._change_motion_status(MotionStatus.POSITIONED)
85+
await self.comm.send_event(RoofOpenedEvent())
86+
87+
@timeout(300)
88+
async def park(self, **kwargs: Any) -> None:
89+
if self.brot.roof.status == RoofStatus.PARKED:
90+
return
91+
elif self.brot.roof.status == RoofStatus.ERROR:
92+
await self._error_state("Roof is in error state. Cannot close.")
93+
return
94+
95+
await self._change_motion_status(MotionStatus.PARKING)
96+
await self.comm.send_event(RoofClosingEvent())
97+
98+
# close shutter
99+
await self.brot.roof.close()
100+
while True:
101+
match self.brot.roof.shutter:
102+
case RoofStatus.CLOSED:
103+
log.info("Roof is closed.")
104+
break
105+
case _:
106+
pass
107+
await asyncio.sleep(1)
108+
109+
await self._change_motion_status(MotionStatus.PARKED)
110+
111+
async def stop_motion(self, device: str | None = None, **kwargs: Any) -> None:
112+
pass
113+
114+
async def _error_state(self, mess: str = "Roof is in error state.") -> None:
115+
log.error(mess)
116+
await self._change_motion_status(MotionStatus.ERROR)
117+
118+
119+
__all__ = ["BrotRoof"]

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "pyobs-brot"
3-
version = "0.0.7"
3+
version = "0.1.0"
44
description = "pyobs module for BROTlib telescopes"
55
authors = [{ name = "Tim-Oliver Husser", email = "thusser@uni-goettingen.de" }, { name = "Lukas Melzig", email = "lukas.melzig@stud.uni-goettingen.de" }]
66
requires-python = ">=3.11"
@@ -9,7 +9,7 @@ dependencies = [
99
"astropy>=7.0.1,<8",
1010
"pyobs-core>=1,<2",
1111
"paho-mqtt>=2.1.0",
12-
"pybrotlib>=0.1.3",
12+
"pybrotlib>=0.2.0",
1313
]
1414

1515
[dependency-groups]

uv.lock

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)