4
0

test_climate.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536
  1. """Tests for the light 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_CLIMATE,
  6. CONF_DEVICE_ID,
  7. CONF_TYPE,
  8. CONF_TYPE_AUTO,
  9. CONF_TYPE_GPPH_HEATER,
  10. DOMAIN,
  11. )
  12. from custom_components.tuya_local.heater.climate import GoldairHeater
  13. from custom_components.tuya_local.climate import async_setup_entry
  14. async def test_init_entry(hass):
  15. """Test the initialisation."""
  16. entry = MockConfigEntry(
  17. domain=DOMAIN,
  18. data={CONF_TYPE: CONF_TYPE_AUTO, CONF_DEVICE_ID: "dummy"},
  19. )
  20. # although async, the async_add_entities function passed to
  21. # async_setup_entry is called truly asynchronously. If we use
  22. # AsyncMock, it expects us to await the result.
  23. m_add_entities = Mock()
  24. m_device = AsyncMock()
  25. m_device.async_inferred_type = AsyncMock(return_value=CONF_TYPE_GPPH_HEATER)
  26. hass.data[DOMAIN] = {}
  27. hass.data[DOMAIN]["dummy"] = {}
  28. hass.data[DOMAIN]["dummy"]["device"] = m_device
  29. await async_setup_entry(hass, entry, m_add_entities)
  30. assert type(hass.data[DOMAIN]["dummy"][CONF_CLIMATE]) == GoldairHeater
  31. m_add_entities.assert_called_once()