test_lock.py 1.1 KB

123456789101112131415161718192021222324252627282930313233
  1. """Tests for the lock entity."""
  2. from pytest_homeassistant_custom_component.common import MockConfigEntry
  3. from unittest.mock import AsyncMock, Mock
  4. from custom_components.tuya_local.const import (
  5. CONF_LOCK,
  6. CONF_DEVICE_ID,
  7. CONF_TYPE,
  8. DOMAIN,
  9. )
  10. from custom_components.tuya_local.generic.lock import TuyaLocalLock
  11. from custom_components.tuya_local.lock import async_setup_entry
  12. async def test_init_entry(hass):
  13. """Test the initialisation."""
  14. entry = MockConfigEntry(
  15. domain=DOMAIN,
  16. data={CONF_TYPE: "heater", CONF_DEVICE_ID: "dummy"},
  17. )
  18. # although async, the async_add_entities function passed to
  19. # async_setup_entry is called truly asynchronously. If we use
  20. # AsyncMock, it expects us to await the result.
  21. m_add_entities = Mock()
  22. m_device = AsyncMock()
  23. hass.data[DOMAIN] = {}
  24. hass.data[DOMAIN]["dummy"] = {}
  25. hass.data[DOMAIN]["dummy"]["device"] = m_device
  26. await async_setup_entry(hass, entry, m_add_entities)
  27. assert type(hass.data[DOMAIN]["dummy"][CONF_LOCK]) == TuyaLocalLock
  28. m_add_entities.assert_called_once()