test_lock.py 2.3 KB

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