pyobs-zwoeaf 2.0.0.dev7__tar.gz → 2.0.0.dev9__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. pyobs_zwoeaf-2.0.0.dev9/.readthedocs.yml +17 -0
  2. {pyobs_zwoeaf-2.0.0.dev7 → pyobs_zwoeaf-2.0.0.dev9}/PKG-INFO +1 -1
  3. pyobs_zwoeaf-2.0.0.dev9/docs/Makefile +31 -0
  4. pyobs_zwoeaf-2.0.0.dev9/docs/make.bat +36 -0
  5. pyobs_zwoeaf-2.0.0.dev9/docs/requirements.txt +1 -0
  6. pyobs_zwoeaf-2.0.0.dev9/docs/source/_static/pyobs.gif +0 -0
  7. pyobs_zwoeaf-2.0.0.dev9/docs/source/conf.py +117 -0
  8. pyobs_zwoeaf-2.0.0.dev9/docs/source/index.rst +35 -0
  9. pyobs_zwoeaf-2.0.0.dev9/lib/lib/mac/libEAFFocuser.dylib.1.6 +0 -0
  10. {pyobs_zwoeaf-2.0.0.dev7 → pyobs_zwoeaf-2.0.0.dev9}/pyproject.toml +1 -1
  11. pyobs_zwoeaf-2.0.0.dev9/src/pyobs_zwoeaf/eaffocuser.py +246 -0
  12. {pyobs_zwoeaf-2.0.0.dev7 → pyobs_zwoeaf-2.0.0.dev9}/uv.lock +1 -1
  13. pyobs_zwoeaf-2.0.0.dev7/DEVELOPMENT.md +0 -337
  14. pyobs_zwoeaf-2.0.0.dev7/lib/lib/mac/libEAFFocuser.dylib +0 -1
  15. pyobs_zwoeaf-2.0.0.dev7/src/pyobs_zwoeaf/eaffocuser.py +0 -148
  16. {pyobs_zwoeaf-2.0.0.dev7 → pyobs_zwoeaf-2.0.0.dev9}/.github/workflows/pypi.yml +0 -0
  17. {pyobs_zwoeaf-2.0.0.dev7 → pyobs_zwoeaf-2.0.0.dev9}/.github/workflows/ruff.yml +0 -0
  18. {pyobs_zwoeaf-2.0.0.dev7 → pyobs_zwoeaf-2.0.0.dev9}/.gitignore +0 -0
  19. {pyobs_zwoeaf-2.0.0.dev7 → pyobs_zwoeaf-2.0.0.dev9}/.pre-commit-config.yaml +0 -0
  20. {pyobs_zwoeaf-2.0.0.dev7 → pyobs_zwoeaf-2.0.0.dev9}/CMakeLists.txt +0 -0
  21. {pyobs_zwoeaf-2.0.0.dev7 → pyobs_zwoeaf-2.0.0.dev9}/LICENSE +0 -0
  22. {pyobs_zwoeaf-2.0.0.dev7 → pyobs_zwoeaf-2.0.0.dev9}/README.md +0 -0
  23. {pyobs_zwoeaf-2.0.0.dev7 → pyobs_zwoeaf-2.0.0.dev9}/lib/demo/c/Makefile +0 -0
  24. {pyobs_zwoeaf-2.0.0.dev7 → pyobs_zwoeaf-2.0.0.dev9}/lib/demo/c/bin/x86/test_console +0 -0
  25. {pyobs_zwoeaf-2.0.0.dev7 → pyobs_zwoeaf-2.0.0.dev9}/lib/demo/c/main.cpp +0 -0
  26. {pyobs_zwoeaf-2.0.0.dev7 → pyobs_zwoeaf-2.0.0.dev9}/lib/include/EAF_focuser.h +0 -0
  27. {pyobs_zwoeaf-2.0.0.dev7 → pyobs_zwoeaf-2.0.0.dev9}/lib/lib/armv6/libEAFFocuser.a +0 -0
  28. {pyobs_zwoeaf-2.0.0.dev7 → pyobs_zwoeaf-2.0.0.dev9}/lib/lib/armv6/libEAFFocuser.so.1.6 +0 -0
  29. {pyobs_zwoeaf-2.0.0.dev7 → pyobs_zwoeaf-2.0.0.dev9}/lib/lib/armv7/libEAFFocuser.a +0 -0
  30. {pyobs_zwoeaf-2.0.0.dev7 → pyobs_zwoeaf-2.0.0.dev9}/lib/lib/armv7/libEAFFocuser.so.1.6 +0 -0
  31. {pyobs_zwoeaf-2.0.0.dev7 → pyobs_zwoeaf-2.0.0.dev9}/lib/lib/armv8/libEAFFocuser.a +0 -0
  32. {pyobs_zwoeaf-2.0.0.dev7 → pyobs_zwoeaf-2.0.0.dev9}/lib/lib/armv8/libEAFFocuser.so.1.6 +0 -0
  33. {pyobs_zwoeaf-2.0.0.dev7 → pyobs_zwoeaf-2.0.0.dev9}/lib/lib/eaf.rules +0 -0
  34. {pyobs_zwoeaf-2.0.0.dev7 → pyobs_zwoeaf-2.0.0.dev9}/lib/lib/mac/libEAFFocuser.a +0 -0
  35. /pyobs_zwoeaf-2.0.0.dev7/lib/lib/mac/libEAFFocuser.dylib.1.6 → /pyobs_zwoeaf-2.0.0.dev9/lib/lib/mac/libEAFFocuser.dylib +0 -0
  36. {pyobs_zwoeaf-2.0.0.dev7 → pyobs_zwoeaf-2.0.0.dev9}/lib/lib/x64/libEAFFocuser.a +0 -0
  37. {pyobs_zwoeaf-2.0.0.dev7 → pyobs_zwoeaf-2.0.0.dev9}/lib/lib/x64/libEAFFocuser.so.1.6 +0 -0
  38. {pyobs_zwoeaf-2.0.0.dev7 → pyobs_zwoeaf-2.0.0.dev9}/lib/lib/x86/libEAFFocuser.a +0 -0
  39. {pyobs_zwoeaf-2.0.0.dev7 → pyobs_zwoeaf-2.0.0.dev9}/lib/lib/x86/libEAFFocuser.so.1.6 +0 -0
  40. {pyobs_zwoeaf-2.0.0.dev7 → pyobs_zwoeaf-2.0.0.dev9}/lib/license.txt +0 -0
  41. {pyobs_zwoeaf-2.0.0.dev7 → pyobs_zwoeaf-2.0.0.dev9}/src/pyobs_zwoeaf/EAF_focuser.cpp +0 -0
  42. {pyobs_zwoeaf-2.0.0.dev7 → pyobs_zwoeaf-2.0.0.dev9}/src/pyobs_zwoeaf/__init__.py +0 -0
  43. {pyobs_zwoeaf-2.0.0.dev7 → pyobs_zwoeaf-2.0.0.dev9}/src/pyobs_zwoeaf/cli.py +0 -0
@@ -0,0 +1,17 @@
1
+ version: 2
2
+
3
+ build:
4
+ os: ubuntu-24.04
5
+ tools:
6
+ python: "3.11"
7
+ apt_packages:
8
+ - libudev-dev
9
+
10
+ sphinx:
11
+ configuration: docs/source/conf.py
12
+
13
+ python:
14
+ install:
15
+ - method: pip
16
+ path: .
17
+ - requirements: docs/requirements.txt
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pyobs-zwoeaf
3
- Version: 2.0.0.dev7
3
+ Version: 2.0.0.dev9
4
4
  Summary: pyobs model for ZWO EAF focus motors
5
5
  Author-Email: Lennart Jonas Buhrke <l.buhrke@stud.uni-goettingen.de>, Tim-Oliver Husser <thusser@uni-goettingen.de>
6
6
  License-Expression: MIT
@@ -0,0 +1,31 @@
1
+ # Minimal makefile for Sphinx documentation
2
+ #
3
+
4
+ # You can set these variables from the command line.
5
+ SPHINXOPTS =
6
+ SPHINXBUILD = sphinx-build
7
+ SPHINXPROJ = pyobs
8
+ SOURCEDIR = source
9
+ BUILDDIR = ../.doc-build
10
+
11
+ #.EXPORT_ALL_VARIABLES:
12
+
13
+ #PYTHONPATH:=../pyobs-core/:../pyobs-sbig/:../pyobs-fli:../pyobs-weather:../pyobs-archive:${PYTHONPATH}
14
+
15
+ # Put it first so that "make" without argument is like "make help".
16
+ help:
17
+ @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
18
+
19
+ .PHONY: help Makefile
20
+
21
+ html:
22
+ @$(SPHINXBUILD) -M html "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS)
23
+
24
+ livehtml:
25
+ sphinx-autobuild -b html --watch ../src/pyobs_zwoeaf $(ALLSPHINXOPTS) "$(SOURCEDIR)/" "$(BUILDDIR)/html/"
26
+
27
+ # Catch-all target: route all unknown targets to Sphinx using the new
28
+ # "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
29
+ %: Makefile
30
+ @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
31
+
@@ -0,0 +1,36 @@
1
+ @ECHO OFF
2
+
3
+ pushd %~dp0
4
+
5
+ REM Command file for Sphinx documentation
6
+
7
+ if "%SPHINXBUILD%" == "" (
8
+ set SPHINXBUILD=sphinx-build
9
+ )
10
+ set SOURCEDIR=source
11
+ set BUILDDIR=build
12
+ set SPHINXPROJ=pyobs
13
+
14
+ if "%1" == "" goto help
15
+
16
+ %SPHINXBUILD% >NUL 2>NUL
17
+ if errorlevel 9009 (
18
+ echo.
19
+ echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
20
+ echo.installed, then set the SPHINXBUILD environment variable to point
21
+ echo.to the full path of the 'sphinx-build' executable. Alternatively you
22
+ echo.may add the Sphinx directory to PATH.
23
+ echo.
24
+ echo.If you don't have Sphinx installed, grab it from
25
+ echo.http://sphinx-doc.org/
26
+ exit /b 1
27
+ )
28
+
29
+ %SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS%
30
+ goto end
31
+
32
+ :help
33
+ %SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS%
34
+
35
+ :end
36
+ popd
@@ -0,0 +1 @@
1
+ sphinx-rtd-theme
@@ -0,0 +1,117 @@
1
+ # Configuration file for the Sphinx documentation builder.
2
+ #
3
+ # This file does only contain a selection of the most common options. For a
4
+ # full list see the documentation:
5
+ # http://www.sphinx-doc.org/en/stable/config
6
+
7
+ # -- Path setup --------------------------------------------------------------
8
+
9
+ # If extensions (or modules to document with autodoc) are in another directory,
10
+ # add these directories to sys.path here. If the directory is relative to the
11
+ # documentation root, use os.path.abspath to make it absolute, like shown here.
12
+ #
13
+ import os
14
+ import sys
15
+
16
+ sys.path.insert(0, os.path.abspath("../../src"))
17
+
18
+
19
+ # -- Project information -----------------------------------------------------
20
+
21
+ project = "pyobs-zwoeaf"
22
+ copyright = "2024, Tim-Oliver Husser"
23
+ author = "Tim-Oliver Husser"
24
+
25
+ # The short X.Y version
26
+ # version = "0.16"
27
+ # The full version, including alpha/beta/rc tags
28
+ # release = "0.16.0"
29
+
30
+
31
+ # -- General configuration ---------------------------------------------------
32
+
33
+ add_module_names = False
34
+
35
+ # If your documentation needs a minimal Sphinx version, state it here.
36
+ #
37
+ # needs_sphinx = '1.0'
38
+
39
+ # Add any Sphinx extension module names here, as strings. They can be
40
+ # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
41
+ # ones.
42
+ extensions = [
43
+ "sphinx.ext.autodoc",
44
+ "sphinx.ext.githubpages",
45
+ "sphinx.ext.napoleon",
46
+ "sphinx.ext.viewcode",
47
+ "sphinx.ext.autosectionlabel",
48
+ "sphinx.ext.intersphinx",
49
+ #'sphinx_autodoc_typehints'
50
+ ]
51
+
52
+ intersphinx_mapping = {"http://docs.python.org/3": None}
53
+
54
+ # napoleon settings
55
+ napoleon_google_docstring = True
56
+ napoleon_numpy_docstring = False
57
+ napoleon_use_param = False
58
+ napoleon_use_ivar = True
59
+
60
+ # typehints
61
+ # set_type_checking_flag = True
62
+ # autodoc_typehints = "description"
63
+
64
+ # show c'tor parameters in class only
65
+ autoclass_content = "both"
66
+
67
+ # Add any paths that contain templates here, relative to this directory.
68
+ templates_path = ["_templates"]
69
+
70
+ # The suffix(es) of source filenames.
71
+ # You can specify multiple suffix as a list of string:
72
+ #
73
+ source_suffix = ".rst"
74
+
75
+ # The master toctree document.
76
+ master_doc = "index"
77
+
78
+ # The language for content autogenerated by Sphinx. Refer to documentation
79
+ # for a list of supported languages.
80
+ #
81
+ # This is also used if you do content translation via gettext catalogs.
82
+ # Usually you set "language" from the command line for these cases.
83
+ language = "en"
84
+
85
+ # List of patterns, relative to source directory, that match files and
86
+ # directories to ignore when looking for source files.
87
+ # This pattern also affects html_static_path and html_extra_path .
88
+ exclude_patterns = []
89
+
90
+ # The name of the Pygments (syntax highlighting) style to use.
91
+ pygments_style = "sphinx"
92
+
93
+ # Be a little nitpicky
94
+ nitpicky = True
95
+ nitpick_ignore = []
96
+
97
+ # intersphinx
98
+ intersphinx_mapping = {
99
+ "pyobs": ("https://pyobs-core.readthedocs.io/en/latest/", None),
100
+ }
101
+
102
+ # -- Options for HTML output -------------------------------------------------
103
+
104
+ # The theme to use for HTML and HTML Help pages. See the documentation for
105
+ # a list of builtin themes.
106
+ html_theme = "sphinx_rtd_theme"
107
+ html_theme_options = {
108
+ "collapse_navigation": False,
109
+ "sticky_navigation": True,
110
+ "navigation_depth": 4,
111
+ "display_version": False,
112
+ "logo_only": False,
113
+ "prev_next_buttons_location": "bottom",
114
+ "titles_only": False,
115
+ "style_nav_header_background": "#cccccc",
116
+ }
117
+ html_logo = "_static/pyobs.gif"
@@ -0,0 +1,35 @@
1
+ pyobs-zwoeaf
2
+ ############
3
+
4
+ This is a `pyobs <https://www.pyobs.org>`_ (`documentation <https://docs.pyobs.org>`_) module for the
5
+ `ZWO Electronic Auto Focuser (EAF) <https://astronomy-imaging-camera.com/product/zwo-eaf>`_.
6
+
7
+
8
+ Example configuration
9
+ *********************
10
+
11
+ This is an example configuration::
12
+
13
+ class: pyobs_zwoeaf.EAFFocuser
14
+ device_number: 0
15
+ max_steps: 60000
16
+ backlash: 0
17
+ direction: true
18
+ sound: true
19
+
20
+ # communication
21
+ comm:
22
+ jid: test@example.com
23
+ password: ***
24
+
25
+
26
+ Available classes
27
+ *****************
28
+
29
+ There is one single class for the ZWO EAF.
30
+
31
+ EAFFocuser
32
+ ==========
33
+ .. autoclass:: pyobs_zwoeaf.EAFFocuser
34
+ :members:
35
+ :show-inheritance:
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "pyobs-zwoeaf"
3
- version = "2.0.0.dev7"
3
+ version = "2.0.0.dev9"
4
4
  description = "pyobs model for ZWO EAF focus motors"
5
5
  authors = [
6
6
  { name = "Lennart Jonas Buhrke", email = "l.buhrke@stud.uni-goettingen.de" },
@@ -0,0 +1,246 @@
1
+ import asyncio
2
+ import logging
3
+ import threading
4
+ import time
5
+ from collections.abc import Callable
6
+ from typing import Any
7
+
8
+ import pyobs.utils.exceptions as exc
9
+ from pyobs.interfaces import IFocuser, IReady, ITemperatures
10
+ from pyobs.interfaces.IFocuser import FocuserState
11
+ from pyobs.interfaces.IReady import ReadyState
12
+ from pyobs.interfaces.ITemperatures import SensorReading, TemperaturesState
13
+ from pyobs.mixins import MotionStatusMixin
14
+ from pyobs.modules import Module
15
+ from pyobs.utils.enums import MotionStatus
16
+
17
+ log = logging.getLogger(__name__)
18
+
19
+ _STEP_TO_MM = 0.00242105263
20
+
21
+ # the ZWO EAF SDK's calls are blocking and are made directly on the event loop thread (see
22
+ # _run_blocking). If the focuser has gone unresponsive, they can hang indefinitely, so they're
23
+ # bounded with a timeout rather than let a single dead connection freeze the whole module.
24
+ _SDK_CALL_TIMEOUT = 5.0
25
+
26
+ # set_focus()'s move-and-wait-until-done sequence legitimately takes longer than the other SDK
27
+ # calls above, so it gets its own, more generous timeout.
28
+ _MOVE_TIMEOUT = 60.0
29
+
30
+
31
+ class EAFFocuser(Module, MotionStatusMixin, IFocuser, ITemperatures):
32
+ """A pyobs module for the ZWO EAF electronic auto focuser."""
33
+
34
+ __module__ = "pyobs_zwoeaf"
35
+
36
+ def __init__(
37
+ self,
38
+ device_number: int = 0,
39
+ max_steps: int = 60000,
40
+ backlash: int = 0,
41
+ direction: bool = True,
42
+ sound: bool = True,
43
+ **kwargs: Any,
44
+ ) -> None:
45
+ Module.__init__(self, **kwargs)
46
+ MotionStatusMixin.__init__(self)
47
+
48
+ self._device_number = device_number
49
+ self._max_steps = max_steps
50
+ self._backlash = backlash
51
+ self._direction = direction
52
+ self._sound = sound
53
+ self._eaf: Any | None = None
54
+ self._focus_setpoint = 0.0
55
+ self._focus_offset = 0.0
56
+
57
+ self.add_background_task(self._poll_temperature)
58
+
59
+ @staticmethod
60
+ async def _run_blocking(
61
+ func: Callable[[], None], timeout: float = _SDK_CALL_TIMEOUT
62
+ ) -> bool:
63
+ """Run a blocking EAF SDK call in a daemon thread, so a hung call can't freeze the module.
64
+
65
+ A plain executor isn't used here, since its worker threads are non-daemon and Python joins
66
+ them on interpreter shutdown -- a hung call would then just move the freeze to process exit.
67
+
68
+ Returns:
69
+ True if func completed within timeout, False if it's still running in the background.
70
+ """
71
+ loop = asyncio.get_running_loop()
72
+ future: asyncio.Future[None] = loop.create_future()
73
+
74
+ def _wrapper() -> None:
75
+ try:
76
+ func()
77
+ finally:
78
+ loop.call_soon_threadsafe(future.set_result, None)
79
+
80
+ threading.Thread(target=_wrapper, daemon=True).start()
81
+ try:
82
+ await asyncio.wait_for(future, timeout=timeout)
83
+ return True
84
+ except TimeoutError:
85
+ return False
86
+
87
+ async def open(self) -> None:
88
+ """Open module."""
89
+ await Module.open(self)
90
+
91
+ from .EAF_focuser import EAF # type: ignore[import-untyped]
92
+
93
+ self._eaf = EAF()
94
+ eaf = self._eaf
95
+
96
+ result: list[tuple[bool, float, float]] = []
97
+
98
+ def _connect() -> None:
99
+ if not eaf.connect(self._device_number):
100
+ result.append((False, 0.0, 0.0))
101
+ return
102
+ eaf.setMaximalStep(self._max_steps)
103
+ eaf.setBacklash(self._backlash)
104
+ eaf.setDirection(self._direction)
105
+ eaf.setSound(self._sound)
106
+ result.append((True, eaf.getTemperature(), eaf.getPosition()))
107
+
108
+ if not await self._run_blocking(_connect):
109
+ raise TimeoutError(
110
+ f"Timed out connecting to EAF focuser after {_SDK_CALL_TIMEOUT}s."
111
+ )
112
+ connected, temperature, position = result[0]
113
+ if not connected:
114
+ raise ValueError(
115
+ "EAF focuser failed to connect. Is the device connected via USB? Correct device_number?"
116
+ )
117
+
118
+ log.info("Connected to EAF focuser, temperature: %.2f°C", temperature)
119
+
120
+ await MotionStatusMixin.open(self)
121
+ await self._change_motion_status(MotionStatus.IDLE)
122
+
123
+ self._focus_setpoint = position * _STEP_TO_MM
124
+ await self.comm.set_state(
125
+ IFocuser,
126
+ FocuserState(focus=self._focus_setpoint, focus_offset=self._focus_offset),
127
+ )
128
+ await self.comm.set_state(IReady, ReadyState(ready=True))
129
+
130
+ async def close(self) -> None:
131
+ """Close module."""
132
+ if self._eaf is not None:
133
+ eaf = self._eaf
134
+ self._eaf = None
135
+ if not await self._run_blocking(eaf.disconnect):
136
+ log.error(
137
+ "Timed out disconnecting EAF focuser after %.1fs.",
138
+ _SDK_CALL_TIMEOUT,
139
+ )
140
+ await Module.close(self)
141
+
142
+ async def init(self, **kwargs: Any) -> None:
143
+ pass
144
+
145
+ async def park(self, **kwargs: Any) -> None:
146
+ """Park focuser at position zero."""
147
+ await self.stop_motion()
148
+ await self.set_focus(0.0)
149
+
150
+ async def stop_motion(self, device: str | None = None, **kwargs: Any) -> None:
151
+ """Stop focuser motion."""
152
+ if self._eaf is not None:
153
+ if not await self._run_blocking(self._eaf.stop):
154
+ log.error(
155
+ "Timed out stopping EAF focuser motion after %.1fs.",
156
+ _SDK_CALL_TIMEOUT,
157
+ )
158
+ await self._change_motion_status(MotionStatus.IDLE)
159
+
160
+ async def set_focus(self, focus: float, **kwargs: Any) -> None:
161
+ """Move focuser to given position.
162
+
163
+ Args:
164
+ focus: New focus position in mm.
165
+
166
+ Raises:
167
+ MoveError: If focuser cannot be moved.
168
+ """
169
+ if self._eaf is None:
170
+ raise ValueError("Not connected.")
171
+ eaf = self._eaf
172
+
173
+ total_mm = focus + self._focus_offset
174
+ step = int(total_mm / _STEP_TO_MM)
175
+ log.info(
176
+ "Moving EAF to %.4f mm (offset %.4f mm, step %d)...",
177
+ focus,
178
+ self._focus_offset,
179
+ step,
180
+ )
181
+
182
+ await self._change_motion_status(MotionStatus.SLEWING)
183
+
184
+ result: list[bool] = []
185
+
186
+ def _move() -> None:
187
+ if not eaf.move(step):
188
+ result.append(False)
189
+ return
190
+ # run the whole "move, then poll until done" sequence as a single blocking call, so
191
+ # only one thread gets spawned per move rather than one per 0.5s poll (see _run_blocking)
192
+ while eaf.isMoving():
193
+ time.sleep(0.1)
194
+ result.append(True)
195
+
196
+ if not await self._run_blocking(_move, timeout=_MOVE_TIMEOUT):
197
+ await self._change_motion_status(MotionStatus.ERROR)
198
+ raise exc.MoveError(f"Timed out moving EAF motor after {_MOVE_TIMEOUT}s.")
199
+ if not result[0]:
200
+ await self._change_motion_status(MotionStatus.ERROR)
201
+ raise exc.MoveError("Could not move EAF motor.")
202
+
203
+ self._focus_setpoint = focus
204
+ await self._change_motion_status(MotionStatus.POSITIONED)
205
+ await self.comm.set_state(
206
+ IFocuser,
207
+ FocuserState(focus=self._focus_setpoint, focus_offset=self._focus_offset),
208
+ )
209
+
210
+ async def set_focus_offset(self, offset: float, **kwargs: Any) -> None:
211
+ """Set focus offset and re-apply.
212
+
213
+ Args:
214
+ offset: New focus offset in mm.
215
+
216
+ Raises:
217
+ MoveError: If focuser cannot be moved.
218
+ """
219
+ log.info("Setting focus offset to %.4f mm.", offset)
220
+ self._focus_offset = offset
221
+ await self.set_focus(self._focus_setpoint)
222
+
223
+ async def _poll_temperature(self) -> None:
224
+ """Background task: periodically reads EAF temperature."""
225
+ while True:
226
+ try:
227
+ if self._eaf is not None:
228
+ eaf = self._eaf
229
+ result: list[float] = []
230
+
231
+ def _get_temp() -> None:
232
+ result.append(eaf.getTemperature())
233
+
234
+ if await self._run_blocking(_get_temp):
235
+ await self.comm.set_state(
236
+ ITemperatures,
237
+ TemperaturesState(
238
+ readings=[SensorReading(name="EAF", value=result[0])]
239
+ ),
240
+ )
241
+ except Exception:
242
+ pass
243
+ await asyncio.sleep(10)
244
+
245
+
246
+ __all__ = ["EAFFocuser"]
@@ -1357,7 +1357,7 @@ wheels = [
1357
1357
 
1358
1358
  [[package]]
1359
1359
  name = "pyobs-zwoeaf"
1360
- version = "2.0.0.dev7"
1360
+ version = "2.0.0.dev9"
1361
1361
  source = { editable = "." }
1362
1362
  dependencies = [
1363
1363
  { name = "pyobs-core" },
@@ -1,337 +0,0 @@
1
- # pyobs 2.0 — Phase 5: External Hardware Modules
2
-
3
- This document covers the migration of this pyobs hardware module to the
4
- pyobs 2.0 API.
5
-
6
- ---
7
-
8
- ## Step 0 — Branch main/master into 1.x for legacy support
9
-
10
- Before making any changes, preserve the current state as a legacy branch.
11
- First check which branch is the default — it may be `main` or `master`:
12
-
13
- ```bash
14
- git remote show origin | grep "HEAD branch"
15
- ```
16
-
17
- **If the default branch is `master`, rename it to `main` first:**
18
-
19
- ```bash
20
- git checkout master
21
- git branch -m master main
22
- git push origin main
23
- git push origin --delete master
24
- # Update the default branch in GitHub repository settings to main
25
- ```
26
-
27
- Then branch off for legacy support:
28
-
29
- ```bash
30
- git checkout main
31
- git checkout -b 1.x
32
- git push origin 1.x
33
- ```
34
-
35
- Create `develop` for all 2.0 work:
36
-
37
- ```bash
38
- git checkout main
39
- git checkout -b develop
40
- git push origin develop
41
- ```
42
-
43
- Set `develop` as the default branch in GitHub repository settings.
44
-
45
- ---
46
-
47
- ## Step 1 — Add ruff, update tooling
48
-
49
- ### pyproject.toml changes
50
-
51
- 1. Bump `pyobs-core` to `>=2.0.0.dev1`.
52
-
53
- 2. In `[dependency-groups] dev`: add `ruff>=0.9.0`, remove `flake8` and any
54
- mypy stub packages (`pandas-stubs`, `pyside6-stubs`, etc.) — pyrefly
55
- doesn't use `.pyi` stubs from PyPI.
56
-
57
- 3. Add config sections (match pyobs-core develop exactly):
58
-
59
- ```toml
60
- [tool.ruff]
61
- target-version = "py311"
62
- line-length = 120
63
-
64
- [tool.ruff.lint]
65
- select = ["E", "F", "W", "I", "UP", "G"]
66
-
67
- [tool.pyrefly]
68
- python-version = "3.11"
69
- ```
70
-
71
- > **Note on the `G` rule**: it flags `log.info(f"...")` — all logging calls
72
- > must use `%`-style formatting: `log.info("value: %s", val)`.
73
-
74
- ### .pre-commit-config.yaml
75
-
76
- Replace the flake8 hook with ruff:
77
-
78
- ```yaml
79
- repos:
80
- - repo: https://github.com/psf/black-pre-commit-mirror
81
- rev: 25.1.0
82
- hooks:
83
- - id: black
84
- language_version: python3.11
85
- - repo: https://github.com/astral-sh/ruff-pre-commit
86
- rev: v0.9.0
87
- hooks:
88
- - id: ruff
89
- ```
90
-
91
- ### Delete .flake8
92
-
93
- ```bash
94
- rm .flake8
95
- ```
96
-
97
- ### Run once to fix existing issues
98
-
99
- ```bash
100
- uv run ruff check --fix .
101
- ```
102
-
103
- ---
104
-
105
- ## Step 2 — Replace get_* with state and capabilities
106
-
107
- ### Remove getter methods
108
-
109
- ```python
110
- # BEFORE (pyobs 1.x)
111
- async def get_binning(self) -> tuple[int, int]:
112
- return self._binning
113
-
114
- async def list_binnings(self) -> list[IBinning.State]:
115
- return [IBinning.State(x=1, y=1), IBinning.State(x=2, y=2)]
116
-
117
- async def get_full_frame(self) -> IWindow.State:
118
- return IWindow.State(x=0, y=0, width=self._width, height=self._height)
119
- ```
120
-
121
- ```python
122
- # AFTER (pyobs 2.0)
123
- # In open():
124
- await self.comm.set_capabilities(IWindow.Capabilities(
125
- full_frame=IWindow.State(x=0, y=0, width=self._width, height=self._height)
126
- ))
127
- await self.comm.set_capabilities(IBinning.Capabilities(
128
- binnings=[IBinning.State(x=1, y=1), IBinning.State(x=2, y=2)]
129
- ))
130
- # Initial states also in open():
131
- await self.comm.set_state(IWindow.State(x=0, y=0, width=self._width, height=self._height))
132
- await self.comm.set_state(IBinning.State(x=self._binning[0], y=self._binning[1]))
133
- # In set_binning():
134
- await self.comm.set_state(IBinning.State(x=x, y=y))
135
- ```
136
-
137
- ### Interface → change pattern
138
-
139
- | Old getter | New pattern |
140
- |---|---|
141
- | `get_full_frame()` | `set_capabilities(IWindow.Capabilities(full_frame=...))` in `open()` |
142
- | `get_window()` | remove — no equivalent; current window tracked in `_window` and published via `set_state(IWindow.State(...))` |
143
- | `list_binnings()` | `set_capabilities(IBinning.Capabilities(binnings=[...]))` in `open()` |
144
- | `list_image_formats()` | `set_capabilities(IImageFormat.Capabilities(image_formats=[...]))` in `open()` |
145
- | `get_binning()` | `set_state(IBinning.State(...))` in `set_binning()` + `open()` |
146
- | `get_exposure_status()` | `set_state(IExposure.State(...))` in `_change_exposure_status()` |
147
- | `get_exposure_time()` | `set_state(IExposureTime.State(...))` in `set_exposure_time()` + `open()` |
148
- | `get_image_type()` | `set_state(IImageType.State(...))` in `set_image_type()` + `open()` |
149
- | `get_filter()` | `set_state(IFilters.State(...))` in `set_filter()` + `open()` |
150
- | `list_filters()` | `set_capabilities(IFilters.Capabilities(filters=[...]))` in `open()` |
151
- | `get_focus()` | `set_state(IFocuser.State(...))` in `set_focus()` + `open()` |
152
- | `get_motion_status()` | handled by `MotionStatusMixin` — just call `_change_motion_status()` |
153
- | `is_ready()` | `set_state(IReady.State(ready=...))` in `open()` and when it changes |
154
- | `get_cooling()` | `set_state(ICooling.State(setpoint=..., power=..., enabled=...))` in `set_cooling()` and background task |
155
- | `get_temperatures()` | `set_state(ITemperatures.State(readings=[ITemperatures.Temperature(name=..., value=...)]))` in background polling task |
156
- | `get_gain()` / `get_offset()` | `set_state(IGain.State(gain=..., offset=...))` in `set_gain()`, `set_offset()` + `open()` |
157
- | `get_video()` | `set_capabilities(IVideo.Capabilities(url=...))` in `open()` |
158
-
159
- ### ICooling and ITemperatures
160
-
161
- `ICooling` extends `ITemperatures` but they have separate `State` dataclasses.
162
- Both must be published independently:
163
-
164
- ```python
165
- # temperatures (from background polling loop)
166
- await self.comm.set_state(
167
- ITemperatures.State(readings=[ITemperatures.Temperature(name="CCD", value=temp)])
168
- )
169
- # cooling control state
170
- await self.comm.set_state(
171
- ICooling.State(setpoint=self._setpoint, power=round(power_pct), enabled=True)
172
- )
173
- ```
174
-
175
- `ICooling.State.power` is typed `int | None` — convert the raw PWM fraction
176
- (`raw / 255 * 100`) with `round()` before passing it.
177
-
178
- ### __init__.py re-exports
179
-
180
- Ruff's `F401` rule requires explicit re-exports. Change:
181
-
182
- ```python
183
- # before
184
- from .mymodule import MyClass
185
- ```
186
-
187
- ```python
188
- # after
189
- from .mymodule import MyClass as MyClass
190
- ```
191
-
192
- ---
193
-
194
- ## Step 3 — Add pyobs-independent GUI
195
-
196
- Each hardware module should have a standalone Qt GUI that works without pyobs
197
- running — useful for testing hardware directly (e.g. during commissioning).
198
-
199
- The pattern from **pyobs-qhyccd** (`pyobs_qhyccd/gui.py`) is the reference.
200
- It uses reusable widgets from `pyobs.utils.gui.*` and talks directly to the
201
- hardware driver without going through pyobs Comm.
202
-
203
- ### Typical structure
204
-
205
- ```python
206
- # mymodule/gui.py
207
- import asyncio
208
- import sys
209
- import qasync
210
- from PySide6 import QtWidgets
211
- from pyobs.utils.gui.camera import (
212
- DataDisplayWidget, BinningWidget, ImageFormatWidget,
213
- ExposureTimeWidget, ExposeWidget,
214
- )
215
- from .driver import MyDriver
216
-
217
-
218
- class MainWindow(QtWidgets.QMainWindow):
219
- def __init__(self) -> None:
220
- super().__init__()
221
- self.driver = MyDriver()
222
- self.driver.open()
223
- # ... build UI from pyobs.utils.gui widgets ...
224
-
225
- @qasync.asyncSlot()
226
- async def _expose_clicked(self) -> None:
227
- # ... call driver directly ...
228
-
229
-
230
- def main() -> None:
231
- app = QtWidgets.QApplication(sys.argv)
232
- asyncio.run(async_main(app), loop_factory=qasync.QEventLoop)
233
-
234
-
235
- if __name__ == "__main__":
236
- main()
237
- ```
238
-
239
- Register as a console script in `pyproject.toml`:
240
-
241
- ```toml
242
- [project.scripts]
243
- mymodule-gui = "mymodule.gui:main"
244
- ```
245
-
246
- ### Available pyobs GUI widgets (`pyobs.utils.gui`)
247
-
248
- - `camera.DataDisplayWidget` — displays FITS images
249
- - `camera.BinningWidget` — binning selector
250
- - `camera.ImageFormatWidget` — INT8/INT16 selector
251
- - `camera.ExposureTimeWidget` — exposure time spinner
252
- - `camera.ExposeWidget` — expose/abort buttons with progress
253
- - `camera.windowingwidget.WindowingWidget` — ROI selector
254
-
255
- ---
256
-
257
- ## Step 4 — Testing
258
-
259
- Each module should have a `test/` directory with a `local.yaml` config that
260
- uses `LocalComm` so it can be tested without an XMPP server:
261
-
262
- ```yaml
263
- # test/local.yaml
264
- class: pyobs.modules.MultiModule
265
-
266
- vfs: &vfs
267
- class: pyobs.vfs.VirtualFileSystem
268
- roots:
269
- cache:
270
- class: pyobs.vfs.LocalFile
271
- root: /tmp/pyobs-test/
272
-
273
- modules:
274
- camera: # or telescope, focuser, etc.
275
- class: mymodule.MyCamera
276
- name: camera
277
- vfs: *vfs
278
- comm:
279
- class: pyobs.comm.local.LocalComm
280
- name: camera
281
-
282
- gui:
283
- class: pyobs_gui.GUI
284
- name: gui
285
- vfs: *vfs
286
- comm:
287
- class: pyobs.comm.local.LocalComm
288
- name: gui
289
- ```
290
-
291
- Run with:
292
- ```bash
293
- pyobs test/local.yaml
294
- ```
295
-
296
- ---
297
-
298
- ## Repo checklist
299
-
300
- For each external module repo, in order:
301
-
302
- - [ ] Branch `main` → `1.x` (legacy)
303
- - [ ] Create `develop` branch
304
- - [ ] Bump `pyobs-core` to `>=2.0.0.dev1` in `pyproject.toml`
305
- - [ ] Add `ruff>=0.9.0` to dev deps; remove `flake8` and mypy stub packages
306
- - [ ] Add `[tool.ruff]`, `[tool.ruff.lint]`, `[tool.pyrefly]` sections to `pyproject.toml`
307
- - [ ] Update `.pre-commit-config.yaml`: replace flake8 hook with ruff
308
- - [ ] Delete `.flake8`
309
- - [ ] Run `ruff check --fix .`
310
- - [ ] Fix re-exports in `__init__.py` (`Foo as Foo`)
311
- - [ ] Convert f-string log calls to `%`-style (`log.info("x: %s", x)`)
312
- - [ ] Remove all `get_*` / `list_*` / `is_ready` methods
313
- - [ ] Add `set_capabilities(...)` calls in `open()`
314
- - [ ] Add `set_state(...)` calls in `open()` (initial values) and wherever values change
315
- - [ ] Add standalone GUI in `<package>/gui.py`
316
- - [ ] Add `test/local.yaml`
317
- - [ ] Update `README.md` to mention pyobs 2.0 requirement
318
-
319
- ---
320
-
321
- ## Key pyobs-core 2.0 APIs
322
-
323
- ```python
324
- # In open() — publish static hardware info
325
- await self.comm.set_capabilities(IWindow.Capabilities(...))
326
- await self.comm.set_capabilities(IBinning.Capabilities(...))
327
-
328
- # In open() and wherever values change — publish live state
329
- await self.comm.set_state(IBinning.State(x=2, y=2))
330
- await self.comm.set_state(ICooling.State(setpoint=-20, power=80, enabled=True))
331
-
332
- # Presence — set by Module.set_state() automatically
333
- # No manual action needed
334
-
335
- # Reading remote state (e.g. telescope pointing for camera WCS)
336
- await self.comm.subscribe_state("telescope", IPointingRaDec, self._on_pointing)
337
- ```
@@ -1 +0,0 @@
1
- libEAFFocuser.dylib.1.6
@@ -1,148 +0,0 @@
1
- import asyncio
2
- import logging
3
- from typing import Any
4
-
5
- import pyobs.utils.exceptions as exc
6
- from pyobs.interfaces import IFocuser, IReady, ITemperatures
7
- from pyobs.interfaces.IFocuser import FocuserState
8
- from pyobs.interfaces.IReady import ReadyState
9
- from pyobs.interfaces.ITemperatures import SensorReading, TemperaturesState
10
- from pyobs.mixins import MotionStatusMixin
11
- from pyobs.modules import Module
12
- from pyobs.utils.enums import MotionStatus
13
-
14
- log = logging.getLogger(__name__)
15
-
16
- _STEP_TO_MM = 0.00242105263
17
-
18
-
19
- class EAFFocuser(Module, MotionStatusMixin, IFocuser, ITemperatures):
20
- """A pyobs module for the ZWO EAF electronic auto focuser."""
21
-
22
- __module__ = "pyobs_zwoeaf"
23
-
24
- def __init__(
25
- self,
26
- device_number: int = 0,
27
- max_steps: int = 60000,
28
- backlash: int = 0,
29
- direction: bool = True,
30
- sound: bool = True,
31
- **kwargs: Any,
32
- ) -> None:
33
- Module.__init__(self, **kwargs)
34
- MotionStatusMixin.__init__(self)
35
-
36
- self._device_number = device_number
37
- self._max_steps = max_steps
38
- self._backlash = backlash
39
- self._direction = direction
40
- self._sound = sound
41
- self._eaf: Any | None = None
42
- self._focus_setpoint = 0.0
43
- self._focus_offset = 0.0
44
-
45
- self.add_background_task(self._poll_temperature)
46
-
47
- async def open(self) -> None:
48
- """Open module."""
49
- await Module.open(self)
50
-
51
- from .EAF_focuser import EAF # type: ignore[import-untyped]
52
-
53
- self._eaf = EAF()
54
- if not self._eaf.connect(self._device_number):
55
- raise ValueError("EAF focuser failed to connect. Is the device connected via USB? Correct device_number?")
56
-
57
- self._eaf.setMaximalStep(self._max_steps)
58
- self._eaf.setBacklash(self._backlash)
59
- self._eaf.setDirection(self._direction)
60
- self._eaf.setSound(self._sound)
61
-
62
- log.info("Connected to EAF focuser, temperature: %.2f°C", self._eaf.getTemperature())
63
-
64
- await MotionStatusMixin.open(self)
65
- await self._change_motion_status(MotionStatus.IDLE)
66
-
67
- self._focus_setpoint = self._eaf.getPosition() * _STEP_TO_MM
68
- await self.comm.set_state(IFocuser, FocuserState(focus=self._focus_setpoint, focus_offset=self._focus_offset))
69
- await self.comm.set_state(IReady, ReadyState(ready=True))
70
-
71
- async def close(self) -> None:
72
- """Close module."""
73
- if self._eaf is not None:
74
- self._eaf.disconnect()
75
- self._eaf = None
76
- await Module.close(self)
77
-
78
- async def init(self, **kwargs: Any) -> None:
79
- pass
80
-
81
- async def park(self, **kwargs: Any) -> None:
82
- """Park focuser at position zero."""
83
- await self.stop_motion()
84
- await self.set_focus(0.0)
85
-
86
- async def stop_motion(self, device: str | None = None, **kwargs: Any) -> None:
87
- """Stop focuser motion."""
88
- if self._eaf is not None:
89
- self._eaf.stop()
90
- await self._change_motion_status(MotionStatus.IDLE)
91
-
92
- async def set_focus(self, focus: float, **kwargs: Any) -> None:
93
- """Move focuser to given position.
94
-
95
- Args:
96
- focus: New focus position in mm.
97
-
98
- Raises:
99
- MoveError: If focuser cannot be moved.
100
- """
101
- if self._eaf is None:
102
- raise ValueError("Not connected.")
103
-
104
- total_mm = focus + self._focus_offset
105
- step = int(total_mm / _STEP_TO_MM)
106
- log.info("Moving EAF to %.4f mm (offset %.4f mm, step %d)...", focus, self._focus_offset, step)
107
-
108
- await self._change_motion_status(MotionStatus.SLEWING)
109
- if not self._eaf.move(step):
110
- await self._change_motion_status(MotionStatus.ERROR)
111
- raise exc.MoveError("Could not move EAF motor.")
112
-
113
- while self._eaf.isMoving():
114
- await asyncio.sleep(0.5)
115
-
116
- self._focus_setpoint = focus
117
- await self._change_motion_status(MotionStatus.POSITIONED)
118
- await self.comm.set_state(IFocuser, FocuserState(focus=self._focus_setpoint, focus_offset=self._focus_offset))
119
-
120
- async def set_focus_offset(self, offset: float, **kwargs: Any) -> None:
121
- """Set focus offset and re-apply.
122
-
123
- Args:
124
- offset: New focus offset in mm.
125
-
126
- Raises:
127
- MoveError: If focuser cannot be moved.
128
- """
129
- log.info("Setting focus offset to %.4f mm.", offset)
130
- self._focus_offset = offset
131
- await self.set_focus(self._focus_setpoint)
132
-
133
- async def _poll_temperature(self) -> None:
134
- """Background task: periodically reads EAF temperature."""
135
- while True:
136
- try:
137
- if self._eaf is not None:
138
- temp = self._eaf.getTemperature()
139
- await self.comm.set_state(
140
- ITemperatures,
141
- TemperaturesState(readings=[SensorReading(name="EAF", value=temp)]),
142
- )
143
- except Exception:
144
- pass
145
- await asyncio.sleep(10)
146
-
147
-
148
- __all__ = ["EAFFocuser"]