Skip to content

Commit

Permalink
Move pubsub module from GORT and add tests (#10)
Browse files Browse the repository at this point in the history
* Move pubsub module from GORT and add tests

* Update changelog

* Remove use of ReprEnum which is only supported in 3.13

* Install RabbitMQ in the test workflow

* Another attempt at fixing the StrEnum issue

* Fix call to read_input_registers

* Import Self from typing_extensions

* Remove pinning of numpy

* One more attempt to fix the enum issue
  • Loading branch information
albireox authored Dec 21, 2024
1 parent db95aa4 commit 9cebf08
Show file tree
Hide file tree
Showing 11 changed files with 891 additions and 330 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ jobs:
with:
enable-cache: true

- name: Setup RabbitMQ
continue-on-error: true
run: |
sudo apt-get install --assume-yes rabbitmq-server
- name: Install dependencies
run: |
uv sync --no-dev --frozen --extra schedule
Expand All @@ -40,6 +45,9 @@ jobs:
run: |
uv pip install pytest pytest-mock pytest-asyncio pytest-cov
uv run pytest
env:
PYTEST_RABBITMQ_CTL: '/usr/lib/rabbitmq/bin/rabbitmqctl'
PYTEST_RABBITMQ_SERVER: '/usr/lib/rabbitmq/bin/rabbitmq-server'

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v5
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## Next version

### 🚀 New

* [#10](https://vscode.dev/github/sdss/lvmopstools/pull/10) Added a `pubsub` module with tools to emit and subscribe to events using RabbitMQ.


## 0.4.4 - December 5, 2024

### ✨ Improved
Expand Down
4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ dependencies = [
"httpx>=0.27.2",
"polars>=1.13.0",
"typing-extensions>=4.12.2",
"aio-pika>=9.5.3",
"pydantic>=2.10.3",
"strenum>=0.4.15",
]

[project.optional-dependencies]
Expand Down Expand Up @@ -61,6 +64,7 @@ dev-dependencies = [
"sphinx-autobuild>=2021.3.14",
"sphinx-autodoc-typehints>=1.23.2",
"ruff>=0.6.1",
"pytest-rabbitmq>=3.1.1",
]

[tool.ruff]
Expand Down
5 changes: 5 additions & 0 deletions src/lvmopstools/data/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ rabbitmq:

api: http://10.8.38.21:8090/api

pubsub:
connection_string: amqp://guest:guest@localhost:5672
exchange_name: lvmops
routing_key: data

devices:
thermistors:
host: 10.8.38.180
Expand Down
10 changes: 6 additions & 4 deletions src/lvmopstools/devices/ion.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import asyncio
import warnings

from typing import TypedDict
from typing import TypedDict, cast

from drift import Drift
from drift.convert import data_to_float32
Expand Down Expand Up @@ -61,10 +61,12 @@ async def _read_one_ion_controller(ion_config: dict) -> dict[str, IonPumpDict]:
signal_address = camera_config["signal_address"]
# on_off_address = camera_config["on_off_address"]

signal = await drift.client.read_input_registers(signal_address, 2)
# onoff = await drift.client.read_input_registers(on_off_address, 1)
signal = await drift.client.read_input_registers(signal_address, count=2)
# onoff = await drift.client.read_input_registers(on_off_address, count=1)

diff_volt = data_to_float32(tuple(signal.registers))
registers = cast(tuple[int, int], tuple(signal.registers))

diff_volt = data_to_float32(registers)
pressure = convert_pressure(diff_volt)

# onoff_status = bool(onoff.registers[0])
Expand Down
Loading

0 comments on commit 9cebf08

Please sign in to comment.