| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- import pytest
- from unittest.mock import AsyncMock
- 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"
- 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
- 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",
- )
|