| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- import pytest
- from unittest.mock import AsyncMock, patch
- from pytest_homeassistant_custom_component.common import MockConfigEntry
- from custom_components.zlock_slots.const import DOMAIN, CONF_LOCK_ENTITY_IDS
- pytest_plugins = ["pytest_homeassistant_custom_component"]
- LOCK_ENTITY_ID = "lock.front_door"
- ALARM_TYPE_ENTITY = "sensor.front_door_alarm_type"
- ALARM_LEVEL_ENTITY = "sensor.front_door_alarm_level"
- DOOR_SENSOR_ENTITY = "binary_sensor.front_door_contact"
- class FakeUserData:
- def __init__(self, user_id: int, active: bool = True):
- self.user_id = user_id
- self.active = active
- class FakeAccessControl:
- def __init__(self, users=None):
- self._users = list(users or [])
- self.set_user = AsyncMock()
- async def get_users_cached(self):
- return list(self._users)
- class FakeNode:
- def __init__(self, users=None):
- self.access_control = FakeAccessControl(users)
- @pytest.fixture(autouse=True)
- def auto_enable_custom_integrations(enable_custom_integrations):
- yield
- @pytest.fixture(autouse=True)
- def bypass_manifest_dependencies():
- """zwave_js/frontend/lovelace can't be set up in the test harness."""
- with patch(
- "homeassistant.setup._async_process_dependencies", return_value=[]
- ):
- yield
- @pytest.fixture
- def mock_node():
- return FakeNode(users=[
- FakeUserData(1, active=True),
- FakeUserData(2, active=False),
- ])
- @pytest.fixture
- def config_entry():
- return MockConfigEntry(
- domain=DOMAIN,
- data={CONF_LOCK_ENTITY_IDS: [LOCK_ENTITY_ID]},
- options={},
- entry_id="test_entry",
- )
|