test_lock.py 1.3 KB

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