conftest.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import pytest
  2. from unittest.mock import AsyncMock, patch
  3. from pytest_homeassistant_custom_component.common import MockConfigEntry
  4. from custom_components.zlock_slots.const import DOMAIN, CONF_LOCK_ENTITY_IDS
  5. pytest_plugins = ["pytest_homeassistant_custom_component"]
  6. LOCK_ENTITY_ID = "lock.front_door"
  7. ALARM_TYPE_ENTITY = "sensor.front_door_alarm_type"
  8. ALARM_LEVEL_ENTITY = "sensor.front_door_alarm_level"
  9. DOOR_SENSOR_ENTITY = "binary_sensor.front_door_contact"
  10. class FakeUserData:
  11. def __init__(self, user_id: int, active: bool = True):
  12. self.user_id = user_id
  13. self.active = active
  14. class FakeAccessControl:
  15. def __init__(self, users=None):
  16. self._users = list(users or [])
  17. self.set_user = AsyncMock()
  18. async def get_users_cached(self):
  19. return list(self._users)
  20. class FakeNode:
  21. def __init__(self, users=None):
  22. self.access_control = FakeAccessControl(users)
  23. @pytest.fixture(autouse=True)
  24. def auto_enable_custom_integrations(enable_custom_integrations):
  25. yield
  26. @pytest.fixture(autouse=True)
  27. def bypass_manifest_dependencies():
  28. """zwave_js/frontend/lovelace can't be set up in the test harness."""
  29. with patch(
  30. "homeassistant.setup._async_process_dependencies", return_value=[]
  31. ):
  32. yield
  33. @pytest.fixture
  34. def mock_node():
  35. return FakeNode(users=[
  36. FakeUserData(1, active=True),
  37. FakeUserData(2, active=False),
  38. ])
  39. @pytest.fixture
  40. def config_entry():
  41. return MockConfigEntry(
  42. domain=DOMAIN,
  43. data={CONF_LOCK_ENTITY_IDS: [LOCK_ENTITY_ID]},
  44. options={},
  45. entry_id="test_entry",
  46. )