|
|
|
|
@@ -5,11 +5,9 @@ import pytest
|
|
|
|
|
import respx
|
|
|
|
|
from httpx import Response
|
|
|
|
|
|
|
|
|
|
from wled_controller.core.processor_manager import (
|
|
|
|
|
ProcessorManager,
|
|
|
|
|
ProcessingSettings,
|
|
|
|
|
)
|
|
|
|
|
from wled_controller.core.calibration import create_default_calibration
|
|
|
|
|
from wled_controller.core.processing.processor_manager import ProcessorManager
|
|
|
|
|
from wled_controller.core.processing.processing_settings import ProcessingSettings
|
|
|
|
|
from wled_controller.core.capture.calibration import create_default_calibration
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
|
@@ -68,7 +66,7 @@ def test_add_device_duplicate(processor_manager):
|
|
|
|
|
led_count=150,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
with pytest.raises(ValueError, match="already exists"):
|
|
|
|
|
with pytest.raises(ValueError, match="already registered"):
|
|
|
|
|
processor_manager.add_device(
|
|
|
|
|
device_id="test_device",
|
|
|
|
|
device_url="http://192.168.1.100",
|
|
|
|
|
@@ -95,24 +93,85 @@ def test_remove_device_not_found(processor_manager):
|
|
|
|
|
processor_manager.remove_device("nonexistent")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_update_settings(processor_manager):
|
|
|
|
|
"""Test updating device settings."""
|
|
|
|
|
def test_add_target(processor_manager):
|
|
|
|
|
"""Test adding a WLED target."""
|
|
|
|
|
processor_manager.add_device(
|
|
|
|
|
device_id="test_device",
|
|
|
|
|
device_url="http://192.168.1.100",
|
|
|
|
|
led_count=150,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
processor_manager.add_target(
|
|
|
|
|
target_id="target_1",
|
|
|
|
|
device_id="test_device",
|
|
|
|
|
settings=ProcessingSettings(fps=60, display_index=1),
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
state = processor_manager.get_target_state("target_1")
|
|
|
|
|
assert state["target_id"] == "target_1"
|
|
|
|
|
assert state["fps_target"] == 60
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_add_target_duplicate(processor_manager):
|
|
|
|
|
"""Test adding duplicate target fails."""
|
|
|
|
|
processor_manager.add_device(
|
|
|
|
|
device_id="test_device",
|
|
|
|
|
device_url="http://192.168.1.100",
|
|
|
|
|
led_count=150,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
processor_manager.add_target(
|
|
|
|
|
target_id="target_1",
|
|
|
|
|
device_id="test_device",
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
with pytest.raises(ValueError, match="already registered"):
|
|
|
|
|
processor_manager.add_target(
|
|
|
|
|
target_id="target_1",
|
|
|
|
|
device_id="test_device",
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_remove_target(processor_manager):
|
|
|
|
|
"""Test removing a target."""
|
|
|
|
|
processor_manager.add_device(
|
|
|
|
|
device_id="test_device",
|
|
|
|
|
device_url="http://192.168.1.100",
|
|
|
|
|
led_count=150,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
processor_manager.add_target(
|
|
|
|
|
target_id="target_1",
|
|
|
|
|
device_id="test_device",
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
processor_manager.remove_target("target_1")
|
|
|
|
|
|
|
|
|
|
with pytest.raises(ValueError, match="not found"):
|
|
|
|
|
processor_manager.get_target_state("target_1")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_update_target_settings(processor_manager):
|
|
|
|
|
"""Test updating target settings."""
|
|
|
|
|
processor_manager.add_device(
|
|
|
|
|
device_id="test_device",
|
|
|
|
|
device_url="http://192.168.1.100",
|
|
|
|
|
led_count=150,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
processor_manager.add_target(
|
|
|
|
|
target_id="target_1",
|
|
|
|
|
device_id="test_device",
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
new_settings = ProcessingSettings(
|
|
|
|
|
display_index=1,
|
|
|
|
|
fps=60,
|
|
|
|
|
border_width=20,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
processor_manager.update_settings("test_device", new_settings)
|
|
|
|
|
processor_manager.update_target_settings("target_1", new_settings)
|
|
|
|
|
|
|
|
|
|
# Verify settings updated
|
|
|
|
|
state = processor_manager.get_state("test_device")
|
|
|
|
|
state = processor_manager.get_target_state("target_1")
|
|
|
|
|
assert state["fps_target"] == 60
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -143,97 +202,80 @@ def test_update_calibration_led_count_mismatch(processor_manager):
|
|
|
|
|
processor_manager.update_calibration("test_device", wrong_calibration)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
|
|
|
@respx.mock
|
|
|
|
|
async def test_start_processing(processor_manager, wled_url, mock_wled_responses):
|
|
|
|
|
"""Test starting processing."""
|
|
|
|
|
respx.get(f"{wled_url}/json/info").mock(
|
|
|
|
|
return_value=Response(200, json=mock_wled_responses["info"])
|
|
|
|
|
)
|
|
|
|
|
respx.post(f"{wled_url}/json/state").mock(
|
|
|
|
|
return_value=Response(200, json={"success": True})
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
processor_manager.add_device(
|
|
|
|
|
device_id="test_device",
|
|
|
|
|
device_url=wled_url,
|
|
|
|
|
led_count=150,
|
|
|
|
|
settings=ProcessingSettings(fps=5), # Low FPS for testing
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
await processor_manager.start_processing("test_device")
|
|
|
|
|
|
|
|
|
|
assert processor_manager.is_processing("test_device") is True
|
|
|
|
|
|
|
|
|
|
# Let it process a few frames
|
|
|
|
|
await asyncio.sleep(0.5)
|
|
|
|
|
|
|
|
|
|
# Stop processing
|
|
|
|
|
await processor_manager.stop_processing("test_device")
|
|
|
|
|
|
|
|
|
|
assert processor_manager.is_processing("test_device") is False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
|
|
|
async def test_start_processing_already_running(processor_manager):
|
|
|
|
|
"""Test starting processing when already running fails."""
|
|
|
|
|
# This test would need mocked WLED responses
|
|
|
|
|
# Skipping actual connection for simplicity
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
|
|
|
async def test_stop_processing_not_running(processor_manager):
|
|
|
|
|
"""Test stopping processing when not running."""
|
|
|
|
|
def test_get_target_state(processor_manager):
|
|
|
|
|
"""Test getting target state."""
|
|
|
|
|
processor_manager.add_device(
|
|
|
|
|
device_id="test_device",
|
|
|
|
|
device_url="http://192.168.1.100",
|
|
|
|
|
led_count=150,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
# Should not raise error
|
|
|
|
|
await processor_manager.stop_processing("test_device")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_get_state(processor_manager):
|
|
|
|
|
"""Test getting device state."""
|
|
|
|
|
processor_manager.add_device(
|
|
|
|
|
processor_manager.add_target(
|
|
|
|
|
target_id="target_1",
|
|
|
|
|
device_id="test_device",
|
|
|
|
|
device_url="http://192.168.1.100",
|
|
|
|
|
led_count=150,
|
|
|
|
|
settings=ProcessingSettings(fps=30, display_index=0),
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
state = processor_manager.get_state("test_device")
|
|
|
|
|
state = processor_manager.get_target_state("target_1")
|
|
|
|
|
|
|
|
|
|
assert state["device_id"] == "test_device"
|
|
|
|
|
assert state["target_id"] == "target_1"
|
|
|
|
|
assert state["processing"] is False
|
|
|
|
|
assert state["fps_target"] == 30
|
|
|
|
|
assert state["display_index"] == 0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_get_state_not_found(processor_manager):
|
|
|
|
|
"""Test getting state for non-existent device."""
|
|
|
|
|
def test_get_target_state_not_found(processor_manager):
|
|
|
|
|
"""Test getting state for non-existent target."""
|
|
|
|
|
with pytest.raises(ValueError, match="not found"):
|
|
|
|
|
processor_manager.get_state("nonexistent")
|
|
|
|
|
processor_manager.get_target_state("nonexistent")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_get_metrics(processor_manager):
|
|
|
|
|
"""Test getting device metrics."""
|
|
|
|
|
def test_get_target_metrics(processor_manager):
|
|
|
|
|
"""Test getting target metrics."""
|
|
|
|
|
processor_manager.add_device(
|
|
|
|
|
device_id="test_device",
|
|
|
|
|
device_url="http://192.168.1.100",
|
|
|
|
|
led_count=150,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
metrics = processor_manager.get_metrics("test_device")
|
|
|
|
|
processor_manager.add_target(
|
|
|
|
|
target_id="target_1",
|
|
|
|
|
device_id="test_device",
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
assert metrics["device_id"] == "test_device"
|
|
|
|
|
metrics = processor_manager.get_target_metrics("target_1")
|
|
|
|
|
|
|
|
|
|
assert metrics["target_id"] == "target_1"
|
|
|
|
|
assert metrics["processing"] is False
|
|
|
|
|
assert metrics["frames_processed"] == 0
|
|
|
|
|
assert metrics["errors_count"] == 0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_is_kc_target(processor_manager):
|
|
|
|
|
"""Test KC target type detection."""
|
|
|
|
|
from wled_controller.storage.key_colors_picture_target import KeyColorsSettings
|
|
|
|
|
|
|
|
|
|
processor_manager.add_device(
|
|
|
|
|
device_id="test_device",
|
|
|
|
|
device_url="http://192.168.1.100",
|
|
|
|
|
led_count=150,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
processor_manager.add_target(
|
|
|
|
|
target_id="wled_target",
|
|
|
|
|
device_id="test_device",
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
processor_manager.add_kc_target(
|
|
|
|
|
target_id="kc_target",
|
|
|
|
|
picture_source_id="src_1",
|
|
|
|
|
settings=KeyColorsSettings(),
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
assert processor_manager.is_kc_target("kc_target") is True
|
|
|
|
|
assert processor_manager.is_kc_target("wled_target") is False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
|
|
|
async def test_stop_all(processor_manager):
|
|
|
|
|
"""Test stopping all processors."""
|
|
|
|
|
@@ -248,7 +290,16 @@ async def test_stop_all(processor_manager):
|
|
|
|
|
led_count=150,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
processor_manager.add_target(
|
|
|
|
|
target_id="target_1",
|
|
|
|
|
device_id="test_device1",
|
|
|
|
|
)
|
|
|
|
|
processor_manager.add_target(
|
|
|
|
|
target_id="target_2",
|
|
|
|
|
device_id="test_device2",
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
await processor_manager.stop_all()
|
|
|
|
|
|
|
|
|
|
assert processor_manager.is_processing("test_device1") is False
|
|
|
|
|
assert processor_manager.is_processing("test_device2") is False
|
|
|
|
|
assert processor_manager.is_target_processing("target_1") is False
|
|
|
|
|
assert processor_manager.is_target_processing("target_2") is False
|
|
|
|
|
|