Skip to content

Commit d3702bb

Browse files
authored
Merge pull request #2 from pyobs/develop
v0.14
2 parents a32b90d + 35b6b6e commit d3702bb

File tree

5 files changed

+87
-73
lines changed

5 files changed

+87
-73
lines changed

pyobs_alpaca/device.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ class ServerGetResponse(NamedTuple):
2525

2626

2727
class AlpacaDevice(Object):
28-
def __init__(self, server: str = None, port: int = None, type: str = None, device: int = None, version: str = 'v1',
29-
alive_parameter: str = 'Connected', *args, **kwargs):
28+
def __init__(self, server: str, port: int, type: str, device: int, version: str = 'v1',
29+
alive_parameter: str = 'Connected', **kwargs: Any):
3030
"""Initializes a new ASCOM Alpaca device.
3131
3232
Args:
@@ -37,7 +37,7 @@ def __init__(self, server: str = None, port: int = None, type: str = None, devic
3737
version: Alpaca version.
3838
alive_parameter: Name of parameter to request in alive ping.
3939
"""
40-
Object.__init__(self, *args, **kwargs)
40+
Object.__init__(self, **kwargs)
4141

4242
# variables
4343
self._server = server
@@ -61,10 +61,10 @@ def __init__(self, server: str = None, port: int = None, type: str = None, devic
6161
self._session = requests.session()
6262

6363
@property
64-
def connected(self):
64+
def connected(self) -> bool:
6565
return self._connected
6666

67-
def open(self):
67+
def open(self) -> None:
6868
"""Open device."""
6969
Object.open(self)
7070

@@ -73,13 +73,13 @@ def open(self):
7373
if not self._connected:
7474
log.warning('Could not connect to ASCOM server.')
7575

76-
def _check_connected_thread(self):
76+
def _check_connected_thread(self) -> None:
7777
"""Periodically check, whether we're connected to ASCOM."""
7878
while not self.closing.is_set():
7979
self._check_connected()
8080
self.closing.wait(5)
8181

82-
def _check_connected(self):
82+
def _check_connected(self) -> None:
8383
"""Check, whether we're connected to ASCOM"""
8484

8585
# get new status
@@ -156,7 +156,7 @@ def get(self, name: str) -> Any:
156156
raise ValueError('Not connected to ASCOM.')
157157
return self._get(name)
158158

159-
def put(self, name: str, timeout: float = 5, **values):
159+
def put(self, name: str, timeout: float = 5, **values: Any) -> None:
160160
"""Calls PUT on Alpaca server with given variable, which might set a variable or call a method.
161161
162162
Args:

pyobs_alpaca/dome.py

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import logging
22
import threading
3-
from typing import Tuple
3+
from typing import Tuple, Optional, Any
44

55
from pyobs.events import RoofOpenedEvent, RoofClosingEvent
66
from pyobs.mixins import FollowMixin
77

8-
from pyobs.interfaces import IMotion, IAltAz
8+
from pyobs.interfaces import IPointingAltAz
99
from pyobs.modules import timeout
1010
from pyobs.modules.roof import BaseDome
1111
from pyobs.utils.enums import MotionStatus
@@ -18,19 +18,18 @@
1818
class 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

pyobs_alpaca/focuser.py

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import logging
22
import threading
33
import time
4-
from typing import List, Dict, Tuple, Any
4+
from typing import List, Dict, Tuple, Any, Optional
55

66
from pyobs.modules import Module
7-
from pyobs.interfaces import IFocuser, IFitsHeaderProvider, IMotion
7+
from pyobs.interfaces import IFocuser, IFitsHeaderBefore
88
from pyobs.mixins import MotionStatusMixin
99
from pyobs.modules import timeout
1010
from pyobs.utils.enums import MotionStatus
@@ -14,18 +14,18 @@
1414
log = logging.getLogger(__name__)
1515

1616

17-
class AlpacaFocuser(MotionStatusMixin, IFocuser, IFitsHeaderProvider, Module):
17+
class AlpacaFocuser(MotionStatusMixin, IFocuser, IFitsHeaderBefore, Module):
1818
__module__ = 'pyobs_alpaca'
1919

20-
def __init__(self, *args, **kwargs):
21-
Module.__init__(self, *args, **kwargs)
20+
def __init__(self, **kwargs: Any):
21+
Module.__init__(self, **kwargs)
2222

2323
# device
24-
self._device = AlpacaDevice(*args, **kwargs)
24+
self._device = AlpacaDevice(**kwargs)
2525
self.add_child_object(self._device)
2626

2727
# variables
28-
self._focus_offset = 0
28+
self._focus_offset = 0.
2929

3030
# allow to abort motion
3131
self._lock_motion = threading.Lock()
@@ -34,7 +34,7 @@ def __init__(self, *args, **kwargs):
3434
# init mixins
3535
MotionStatusMixin.__init__(self, motion_status_interfaces=['IFocuser'])
3636

37-
def open(self):
37+
def open(self) -> None:
3838
"""Open module."""
3939
Module.open(self)
4040

@@ -44,23 +44,23 @@ def open(self):
4444
# init status
4545
self._change_motion_status(MotionStatus.IDLE, interface='IFocuser')
4646

47-
def init(self, *args, **kwargs):
47+
def init(self, **kwargs: Any) -> None:
4848
"""Initialize device.
4949
5050
Raises:
5151
ValueError: If device could not be initialized.
5252
"""
5353
pass
5454

55-
def park(self, *args, **kwargs):
55+
def park(self, **kwargs: Any) -> None:
5656
"""Park device.
5757
5858
Raises:
5959
ValueError: If device could not be parked.
6060
"""
6161
pass
6262

63-
def get_fits_headers(self, namespaces: List[str] = None, *args, **kwargs) -> Dict[str, Tuple[Any, str]]:
63+
def get_fits_header_before(self, namespaces: Optional[List[str]] = None, **kwargs: Any) -> Dict[str, Tuple[Any, str]]:
6464
"""Returns FITS header for the current status of this module.
6565
6666
Args:
@@ -86,7 +86,7 @@ def get_fits_headers(self, namespaces: List[str] = None, *args, **kwargs) -> Dic
8686
return {}
8787

8888
@timeout(60000)
89-
def set_focus(self, focus: float, *args, **kwargs):
89+
def set_focus(self, focus: float, **kwargs: Any) -> None:
9090
"""Sets new focus.
9191
9292
Args:
@@ -96,7 +96,7 @@ def set_focus(self, focus: float, *args, **kwargs):
9696
# set focus + offset
9797
self._set_focus(focus + self._focus_offset)
9898

99-
def set_focus_offset(self, offset: float, *args, **kwargs):
99+
def set_focus_offset(self, offset: float, **kwargs: Any) -> None:
100100
"""Sets focus offset.
101101
102102
Args:
@@ -107,15 +107,15 @@ def set_focus_offset(self, offset: float, *args, **kwargs):
107107
"""
108108

109109
# get current focus (without offset)
110-
focus = self._device.get_focus()
110+
focus = self.get_focus()
111111

112112
# set offset
113113
self._focus_offset = offset
114114

115115
# go to focus
116116
self._set_focus(focus + self._focus_offset)
117117

118-
def _set_focus(self, focus):
118+
def _set_focus(self, focus: float) -> None:
119119
"""Actually sets new focus.
120120
121121
Args:
@@ -147,7 +147,7 @@ def _set_focus(self, focus):
147147
log.info('Reached new focus of %.2fmm.', self._device.get('Position') / step / 1000.)
148148
self._change_motion_status(MotionStatus.POSITIONED, interface='IFocuser')
149149

150-
def get_focus(self, *args, **kwargs) -> float:
150+
def get_focus(self, **kwargs: Any) -> float:
151151
"""Return current focus.
152152
153153
Returns:
@@ -156,21 +156,21 @@ def get_focus(self, *args, **kwargs) -> float:
156156

157157
# get pos and step size
158158
# StepSize is in microns, so multiply with 1000
159-
pos = self._device.get('Position')
160-
step = self._device.get('StepSize') * 1000.
159+
pos = float(self._device.get('Position'))
160+
step = float(self._device.get('StepSize')) * 1000.
161161

162162
# return current focus - offset
163163
return pos / step - self._focus_offset
164164

165-
def get_focus_offset(self, *args, **kwargs) -> float:
165+
def get_focus_offset(self, **kwargs: Any) -> float:
166166
"""Return current focus offset.
167167
168168
Returns:
169169
Current focus offset.
170170
"""
171171
return self._focus_offset
172172

173-
def stop_motion(self, device: str = None, *args, **kwargs):
173+
def stop_motion(self, device: Optional[str] = None, **kwargs: Any) -> None:
174174
"""Stop the motion.
175175
176176
Args:
@@ -180,7 +180,7 @@ def stop_motion(self, device: str = None, *args, **kwargs):
180180
# stop motion
181181
self._device.put('Halt')
182182

183-
def is_ready(self, *args, **kwargs) -> bool:
183+
def is_ready(self, **kwargs: Any) -> bool:
184184
"""Returns the device is "ready", whatever that means for the specific device.
185185
186186
Returns:

0 commit comments

Comments
 (0)