Skip to main content

matterlab_relays

matterlab_relays provides drivers for the relay boards used in the Matter Lab. It includes relay-specific implementations for several serial and Modbus-controlled boards, along with a small shared base interface for switching channels on and off.

Supported Devices

  • Relay: shared abstract base class
  • R421B16Relay
  • JYdaqRelay
  • CE221ARelay

Installation

Install the package:

pip install matterlab_relays

For development:

pip install -e .[dev]

The package depends on:

  • matterlab_serial_device
  • modbus_tk

Quick Start

Example with an R421B16 relay:

from matterlab_relays import R421B16Relay

relay = R421B16Relay(com_port="COM5", address=1, channel=1)
print("Current state:", relay.on)
relay.on = True
relay.on = False

Core API

The shared Relay interface exposes:

  • on

Concrete device classes add protocol-specific helpers:

  • R421B16Relay: _generate_query_command(...), _generate_execute_command(...), query_relay(...), set_relay(...)
  • JYdaqRelay: _add_rtu_master(), set_multiple_relays(...), query_multiple_relays(...)
  • CE221ARelay: cached on state with _generate_execution_command(...)

Testing

Simulation Tests

Simulation tests are the default validation layer and are safe for CI.

One-click run:

python examples/test_sim.py

Direct pytest run:

pytest tests/test_base_relay.py tests/test_r421b16_sim.py tests/test_jydaq_sim.py tests/test_ce221a_sim.py

Hardware Tests

Hardware tests are opt-in because real relay hardware may not be connected in every environment.

Available hardware test files:

  • tests/test_r421b16_real.py
  • tests/test_jydaq_real.py
  • tests/test_ce221a_real.py

They are marked with @pytest.mark.real and are skipped unless --run-real is supplied.

Examples:

pytest tests/test_r421b16_real.py --run-real --com-port COM5 --address 1 --channel 1
pytest tests/test_jydaq_real.py --run-real --com-port COM5 --address 1 --channel 1
pytest tests/test_ce221a_real.py --run-real --com-port COM5 --channel 1

You can also provide hardware configuration through environment variables:

  • RELAY_COM_PORT
  • RELAY_ADDRESS
  • RELAY_CHANNEL

Examples

The examples/ directory contains the recommended entry points:

  • examples/test_sim.py: one-click simulation-only test runner
  • examples/real_devices.py: readable examples for all supported relay drivers
  • examples/README.md: short guide to the examples directory

Development

Useful commands:

pytest
ruff check .
ruff format .

The default pytest configuration includes retries, timeouts, coverage output, and uses src as the import root for local development.

Package Layout

src/matterlab_relays/
  base_relay.py
  cer221a_relay.py
  jydao_relay.py
  r421b16_relay.py
tests/
examples/

License

This project is distributed under the MIT License. See LICENSE for details.

Metadata

Release files for matterlab-relays 1.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for matterlab-relays 1.2.1
File Size Uploaded
matterlab_relays-1.2.1.tar.gz 14.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for matterlab-relays 1.2.1
File Interpreter ABI Platform
matterlab_relays-1.2.1-py3-none-any.whl Python 3 none any Details

Total release size: 26.2 kB

Release files / matterlab_relays-1.2.1.tar.gz

Download URL matterlab_relays-1.2.1.tar.gz
Size 14.0 kB
Tags Source
SHA-256 checksum
How to use checksums
a846a462bbfb5eecbe2739a9f94be3a0d6326e7714ce5e0df5466f32a1b9c5db
BLAKE2b-256 checksum
How to use checksums
fb40f3bef2811910e2ac1ba98316742db0b3d9c689396fca9533d8cacba5c624
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.13

Release files / matterlab_relays-1.2.1-py3-none-any.whl

Download URL matterlab_relays-1.2.1-py3-none-any.whl
Size 12.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
de6589ce2770aaee06b42fdbb9cf845de88e8b67e89d442b85e659288d8407f7
BLAKE2b-256 checksum
How to use checksums
9caa3c674d39e6c23bec52975ff4e93832d2804b279e814eeefb6722c9ab6bcd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.13

Release history Release notifications | RSS feed

This release

1.2.1 This release

2 release files

1.1.0

2 release files

1.0.6

2 release files

1.0.5

2 release files

1.0.4

2 release files

1.0.3

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page