Files
localthings/tests/conftest.py
T
Marc Billow cc2c1e5a1f refactor: move samsung_appliance/ into custom_components/localthings/ocf/
Makes the integration fully self-contained for HACS distribution.
Users installing via HACS get everything in one directory; no external
samsung_appliance package needed.

All component imports updated to relative (.ocf.*); all test imports
updated to custom_components.localthings.ocf.*. ocf_root_ca.pem moves
with the package and resolves correctly via Path(__file__).parent.
2026-06-30 16:34:20 -05:00

39 lines
1.0 KiB
Python

import json
from pathlib import Path
import pytest
FIXTURES = Path(__file__).resolve().parent / 'fixtures'
def _resources_from_dump(dump: dict) -> dict[str, dict]:
from custom_components.localthings.ocf.batch import parse_device0_batch
return parse_device0_batch(dump['device0'])
def _load_device(name: str) -> dict[str, dict]:
data = json.loads((FIXTURES / f'{name}_device.json').read_text())
return _resources_from_dump(data)
def _load_resources(ip: str) -> dict[str, dict]:
"""Legacy IP-based loader — maps known IPs to named fixtures."""
_ip_to_name = {
'10.0.0.129': 'dishwasher',
'10.0.0.254': 'refrigerator',
}
name = _ip_to_name.get(ip)
if name is None:
raise ValueError(f"No fixture for IP {ip!r} — add a scrubbed fixture to tests/fixtures/")
return _load_device(name)
@pytest.fixture
def dishwasher_resources() -> dict[str, dict]:
return _load_device('dishwasher')
@pytest.fixture
def fridge_resources() -> dict[str, dict]:
return _load_device('refrigerator')