mirror of
https://github.com/ipnet-mesh/meshcore-hub.git
synced 2026-05-01 11:02:42 +02:00
This commit adds the complete Interface component for MeshCore device communication: Device abstraction (interface/device.py): - BaseMeshCoreDevice abstract class - MeshCoreDevice for real hardware (placeholder for meshcore_py) - DeviceConfig for connection settings - EventType enumeration for all MeshCore events - Event handler registration and dispatching Mock device (interface/mock_device.py): - MockMeshCoreDevice for testing without hardware - Configurable event generation - Simulated network with multiple mock nodes - Support for injecting custom events RECEIVER mode (interface/receiver.py): - Subscribes to device events - Publishes events to MQTT broker - Signal handling for graceful shutdown SENDER mode (interface/sender.py): - Subscribes to MQTT command topics - Dispatches commands to MeshCore device - Handles send_msg, send_channel_msg, send_advert, etc. CLI (interface/cli.py): - Click commands for running interface - Convenience commands for receiver/sender modes - Environment variable support for all options Tests: - Device abstraction tests - Mock device tests - Receiver and sender mode tests
36 lines
987 B
Python
36 lines
987 B
Python
"""Fixtures for interface component tests."""
|
|
|
|
import pytest
|
|
|
|
from meshcore_hub.interface.device import DeviceConfig, EventType
|
|
from meshcore_hub.interface.mock_device import MockDeviceConfig, MockMeshCoreDevice
|
|
|
|
|
|
@pytest.fixture
|
|
def device_config() -> DeviceConfig:
|
|
"""Create a device configuration for testing."""
|
|
return DeviceConfig(
|
|
port="/dev/ttyUSB0",
|
|
baud=115200,
|
|
timeout=1.0,
|
|
)
|
|
|
|
|
|
@pytest.fixture
|
|
def mock_device_config() -> MockDeviceConfig:
|
|
"""Create a mock device configuration for testing."""
|
|
return MockDeviceConfig(
|
|
public_key="a" * 64,
|
|
name="TestNode",
|
|
enable_auto_events=False, # Disable auto events for testing
|
|
)
|
|
|
|
|
|
@pytest.fixture
|
|
def mock_device(device_config, mock_device_config) -> MockMeshCoreDevice:
|
|
"""Create a mock device instance for testing."""
|
|
device = MockMeshCoreDevice(device_config, mock_device_config)
|
|
yield device
|
|
if device.is_connected:
|
|
device.disconnect()
|