11import logging
22import threading
3- from typing import Tuple
3+ from typing import Tuple , Optional , Any
44
55from pyobs .events import RoofOpenedEvent , RoofClosingEvent
66from pyobs .mixins import FollowMixin
77
8- from pyobs .interfaces import IMotion , IAltAz
8+ from pyobs .interfaces import IPointingAltAz
99from pyobs .modules import timeout
1010from pyobs .modules .roof import BaseDome
1111from pyobs .utils .enums import MotionStatus
1818class AlpacaDome (FollowMixin , BaseDome ):
1919 __module__ = 'pyobs_alpaca'
2020
21- def __init__ (self , tolerance : float = 3 , park_az : float = 180 , follow : str = None ,
22- * args , ** kwargs ):
21+ def __init__ (self , tolerance : float = 3 , park_az : float = 180 , follow : Optional [str ] = None , ** kwargs : Any ):
2322 """Initializes a new ASCOM Alpaca telescope.
2423
2524 Args:
2625 tolerance: Tolerance for azimuth.
2726 park_az: Azimuth for park position.
2827 follow: Name of other device (e.g. telescope) to follow.
2928 """
30- BaseDome .__init__ (self , * args , * *kwargs , motion_status_interfaces = ['IDome' ])
29+ BaseDome .__init__ (self , ** kwargs , motion_status_interfaces = ['IDome' ])
3130
3231 # device
33- self ._device = AlpacaDevice (* args , * *kwargs )
32+ self ._device = AlpacaDevice (** kwargs )
3433 self .add_child_object (self ._device )
3534
3635 # store
@@ -45,32 +44,36 @@ def __init__(self, tolerance: float = 3, park_az: float = 180, follow: str = Non
4544
4645 # status
4746 self ._shutter = None
48- self ._altitude = 0
49- self ._azimuth = 0
50- self ._set_az = 0
47+ self ._altitude = 0.
48+ self ._azimuth = 0.
49+ self ._set_az = 0.
5150
5251 # start thread
5352 self .add_thread_func (self ._update_status )
5453
5554 # mixins
56- FollowMixin .__init__ (self , device = follow , interval = 10 , tolerance = tolerance , mode = IAltAz ,
55+ FollowMixin .__init__ (self , device = follow , interval = 10 , tolerance = tolerance , mode = IPointingAltAz ,
5756 only_follow_when_ready = False )
5857
59- def open (self ):
58+ def open (self ) -> None :
6059 """Open module."""
6160 BaseDome .open (self )
6261
6362 # init status to IDLE
6463 self ._change_motion_status (MotionStatus .IDLE )
6564
6665 @timeout (1200000 )
67- def init (self , * args , ** kwargs ) :
66+ def init (self , ** kwargs : Any ) -> None :
6867 """Open dome.
6968
7069 Raises:
7170 ValueError: If dome cannot be opened.
7271 """
7372
73+ # if already opening, ignore
74+ if self .get_motion_status () == MotionStatus .INITIALIZING :
75+ return
76+
7477 # acquire lock
7578 with LockWithAbort (self ._lock_shutter , self ._abort_shutter ):
7679 # log
@@ -99,7 +102,7 @@ def init(self, *args, **kwargs):
99102 self .comm .send_event (RoofOpenedEvent ())
100103
101104 @timeout (1200000 )
102- def park (self , * args , ** kwargs ) :
105+ def park (self , ** kwargs : Any ) -> None :
103106 """Close dome.
104107
105108 Raises:
@@ -138,7 +141,7 @@ def park(self, *args, **kwargs):
138141 log .info ('Dome closed.' )
139142 self ._change_motion_status (MotionStatus .PARKED )
140143
141- def _move (self , az : float , abort : threading .Event ):
144+ def _move (self , az : float , abort : threading .Event ) -> None :
142145 """Move the roof and wait for it.
143146
144147 Args:
@@ -171,7 +174,7 @@ def _move(self, az: float, abort: threading.Event):
171174 log .info ('Moved to az=%.2f.' , az )
172175
173176 @timeout (1200000 )
174- def move_altaz (self , alt : float , az : float , * args , ** kwargs ) :
177+ def move_altaz (self , alt : float , az : float , ** kwargs : Any ) -> None :
175178 """Moves to given coordinates.
176179
177180 Args:
@@ -182,6 +185,10 @@ def move_altaz(self, alt: float, az: float, *args, **kwargs):
182185 ValueError: If device could not move.
183186 """
184187
188+ # do nothing, if not ready
189+ if not self .is_ready ():
190+ return
191+
185192 # destination az already set?
186193 if az == self ._set_az :
187194 return
@@ -207,15 +214,15 @@ def move_altaz(self, alt: float, az: float, *args, **kwargs):
207214 # change status to TRACKING or POSITIONED, depending on whether we're tracking
208215 self ._change_motion_status (MotionStatus .TRACKING if self .is_following else MotionStatus .POSITIONED )
209216
210- def get_altaz (self , * args , ** kwargs ) -> Tuple [float , float ]:
217+ def get_altaz (self , ** kwargs : Any ) -> Tuple [float , float ]:
211218 """Returns current Alt and Az.
212219
213220 Returns:
214221 Tuple of current Alt and Az in degrees.
215222 """
216223 return self ._altitude , self ._azimuth
217224
218- def stop_motion (self , device : str = None , * args , ** kwargs ) :
225+ def stop_motion (self , device : Optional [ str ] = None , ** kwargs : Any ) -> None :
219226 """Stop the motion.
220227
221228 Args:
@@ -225,7 +232,7 @@ def stop_motion(self, device: str = None, *args, **kwargs):
225232 # not supported, but don't want to raise an exception
226233 pass
227234
228- def is_ready (self , * args , ** kwargs ) -> bool :
235+ def is_ready (self , ** kwargs : Any ) -> bool :
229236 """Returns the device is "ready", whatever that means for the specific device.
230237
231238 Returns:
@@ -237,7 +244,7 @@ def is_ready(self, *args, **kwargs) -> bool:
237244 self .get_motion_status () not in [MotionStatus .PARKED , MotionStatus .INITIALIZING ,
238245 MotionStatus .PARKING , MotionStatus .ERROR , MotionStatus .UNKNOWN ]
239246
240- def _update_status (self ):
247+ def _update_status (self ) -> None :
241248 """Update status from dome."""
242249
243250 # loop forever
0 commit comments