test_lock.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. """Tests for the lock entity."""
  2. import pytest
  3. from pytest_homeassistant_custom_component.common import MockConfigEntry
  4. from unittest.mock import AsyncMock
  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. @pytest.mark.asyncio
  16. async def test_init_entry(hass):
  17. """Test the initialisation."""
  18. entry = MockConfigEntry(
  19. domain=DOMAIN, data={CONF_TYPE: CONF_TYPE_AUTO, CONF_DEVICE_ID: "dummy"},
  20. )
  21. m_add_entities = AsyncMock()
  22. m_device = AsyncMock()
  23. m_device.async_inferred_type = AsyncMock(return_value=CONF_TYPE_GPPH_HEATER)
  24. hass.data[DOMAIN] = {}
  25. hass.data[DOMAIN]["dummy"] = {}
  26. hass.data[DOMAIN]["dummy"]["device"] = m_device
  27. await async_setup_entry(hass, entry, m_add_entities)
  28. assert type(hass.data[DOMAIN]["dummy"][CONF_CHILD_LOCK]) == GoldairHeaterChildLock
  29. m_add_entities.assert_called_once()