test_lock.py 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. from unittest import IsolatedAsyncioTestCase
  2. from unittest.mock import AsyncMock, patch
  3. from custom_components.goldair_climate.heater.const import (
  4. ATTR_CHILD_LOCK,
  5. ATTR_HVAC_MODE,
  6. PROPERTY_TO_DPS_ID,
  7. )
  8. from custom_components.goldair_climate.heater.lock import GoldairHeaterChildLock
  9. from ..const import GPPH_HEATER_PAYLOAD
  10. from ..helpers import assert_device_properties_set
  11. class TestLock(IsolatedAsyncioTestCase):
  12. def setUp(self):
  13. device_patcher = patch(
  14. "custom_components.goldair_climate.heater.lock.GoldairTuyaDevice"
  15. )
  16. self.addCleanup(device_patcher.stop)
  17. self.mock_device = device_patcher.start()
  18. self.subject = GoldairHeaterChildLock(self.mock_device())
  19. self.dps = GPPH_HEATER_PAYLOAD.copy()
  20. self.subject._device.get_property.side_effect = lambda id: self.dps[id]
  21. def test_should_poll(self):
  22. self.assertTrue(self.subject.should_poll)
  23. def test_name_returns_device_name(self):
  24. self.assertEqual(self.subject.name, self.subject._device.name)
  25. def test_unique_id_returns_device_unique_id(self):
  26. self.assertEqual(self.subject.unique_id, self.subject._device.unique_id)
  27. def test_device_info_returns_device_info_from_device(self):
  28. self.assertEqual(self.subject.device_info, self.subject._device.device_info)
  29. def test_is_locked(self):
  30. self.dps[PROPERTY_TO_DPS_ID[ATTR_CHILD_LOCK]] = True
  31. self.assertEqual(self.subject.is_locked, True)
  32. self.dps[PROPERTY_TO_DPS_ID[ATTR_CHILD_LOCK]] = False
  33. self.assertEqual(self.subject.is_locked, False)
  34. async def test_lock(self):
  35. async with assert_device_properties_set(
  36. self.subject._device, {PROPERTY_TO_DPS_ID[ATTR_CHILD_LOCK]: True}
  37. ):
  38. await self.subject.async_lock()
  39. async def test_unlock(self):
  40. async with assert_device_properties_set(
  41. self.subject._device, {PROPERTY_TO_DPS_ID[ATTR_CHILD_LOCK]: False}
  42. ):
  43. await self.subject.async_unlock()
  44. async def test_update(self):
  45. result = AsyncMock()
  46. self.subject._device.async_refresh.return_value = result()
  47. await self.subject.async_update()
  48. self.subject._device.async_refresh.assert_called_once()
  49. result.assert_awaited()