test_goldair_geco_heater.py 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. from homeassistant.components.climate.const import (
  2. HVAC_MODE_HEAT,
  3. HVAC_MODE_OFF,
  4. SUPPORT_TARGET_TEMPERATURE,
  5. )
  6. from homeassistant.components.lock import STATE_LOCKED, STATE_UNLOCKED
  7. from homeassistant.const import STATE_UNAVAILABLE
  8. from ..const import GECO_HEATER_PAYLOAD
  9. from ..helpers import assert_device_properties_set
  10. from .base_device_tests import TuyaDeviceTestCase
  11. HVACMODE_DPS = "1"
  12. LOCK_DPS = "2"
  13. TEMPERATURE_DPS = "3"
  14. CURRENTTEMP_DPS = "4"
  15. TIMER_DPS = "5"
  16. ERROR_DPS = "6"
  17. class TestGoldairGECOHeater(TuyaDeviceTestCase):
  18. __test__ = True
  19. def setUp(self):
  20. self.setUpForConfig("goldair_geco_heater.yaml", GECO_HEATER_PAYLOAD)
  21. self.subject = self.entities.get("climate")
  22. self.lock = self.entities.get("lock")
  23. def test_supported_features(self):
  24. self.assertEqual(
  25. self.subject.supported_features,
  26. SUPPORT_TARGET_TEMPERATURE,
  27. )
  28. def test_icon(self):
  29. self.dps[HVACMODE_DPS] = True
  30. self.assertEqual(self.subject.icon, "mdi:radiator")
  31. self.dps[HVACMODE_DPS] = False
  32. self.assertEqual(self.subject.icon, "mdi:radiator-disabled")
  33. def test_temperature_unit_returns_device_temperature_unit(self):
  34. self.assertEqual(
  35. self.subject.temperature_unit, self.subject._device.temperature_unit
  36. )
  37. def test_target_temperature(self):
  38. self.dps[TEMPERATURE_DPS] = 25
  39. self.assertEqual(self.subject.target_temperature, 25)
  40. def test_target_temperature_step(self):
  41. self.assertEqual(self.subject.target_temperature_step, 1)
  42. def test_minimum_target_temperature(self):
  43. self.assertEqual(self.subject.min_temp, 15)
  44. def test_maximum_target_temperature(self):
  45. self.assertEqual(self.subject.max_temp, 35)
  46. async def test_legacy_set_temperature_with_temperature(self):
  47. async with assert_device_properties_set(
  48. self.subject._device, {TEMPERATURE_DPS: 24}
  49. ):
  50. await self.subject.async_set_temperature(temperature=24)
  51. async def test_legacy_set_temperature_with_no_valid_properties(self):
  52. await self.subject.async_set_temperature(something="else")
  53. self.subject._device.async_set_property.assert_not_called()
  54. async def test_set_target_temperature_succeeds_within_valid_range(self):
  55. async with assert_device_properties_set(
  56. self.subject._device,
  57. {TEMPERATURE_DPS: 25},
  58. ):
  59. await self.subject.async_set_target_temperature(25)
  60. async def test_set_target_temperature_rounds_value_to_closest_integer(self):
  61. async with assert_device_properties_set(
  62. self.subject._device, {TEMPERATURE_DPS: 23}
  63. ):
  64. await self.subject.async_set_target_temperature(22.6)
  65. async def test_set_target_temperature_fails_outside_valid_range(self):
  66. with self.assertRaisesRegex(
  67. ValueError, "temperature \\(14\\) must be between 15 and 35"
  68. ):
  69. await self.subject.async_set_target_temperature(14)
  70. with self.assertRaisesRegex(
  71. ValueError, "temperature \\(36\\) must be between 15 and 35"
  72. ):
  73. await self.subject.async_set_target_temperature(36)
  74. def test_current_temperature(self):
  75. self.dps[CURRENTTEMP_DPS] = 25
  76. self.assertEqual(self.subject.current_temperature, 25)
  77. def test_hvac_mode(self):
  78. self.dps[HVACMODE_DPS] = True
  79. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_HEAT)
  80. self.dps[HVACMODE_DPS] = False
  81. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_OFF)
  82. self.dps[HVACMODE_DPS] = None
  83. self.assertEqual(self.subject.hvac_mode, STATE_UNAVAILABLE)
  84. def test_hvac_modes(self):
  85. self.assertCountEqual(self.subject.hvac_modes, [HVAC_MODE_OFF, HVAC_MODE_HEAT])
  86. async def test_turn_on(self):
  87. async with assert_device_properties_set(
  88. self.subject._device, {HVACMODE_DPS: True}
  89. ):
  90. await self.subject.async_set_hvac_mode(HVAC_MODE_HEAT)
  91. async def test_turn_off(self):
  92. async with assert_device_properties_set(
  93. self.subject._device, {HVACMODE_DPS: False}
  94. ):
  95. await self.subject.async_set_hvac_mode(HVAC_MODE_OFF)
  96. def test_state_attributes(self):
  97. # There are currently no known error states; update this as
  98. # they are discovered
  99. self.dps[ERROR_DPS] = "something"
  100. self.dps[TIMER_DPS] = 10
  101. self.assertCountEqual(
  102. self.subject.device_state_attributes, {"error": "something", "timer": 10}
  103. )
  104. self.dps[ERROR_DPS] = "0"
  105. self.dps[TIMER_DPS] = 0
  106. self.assertCountEqual(
  107. self.subject.device_state_attributes, {"error": "OK", "timer": 0}
  108. )
  109. def test_lock_state(self):
  110. self.dps[LOCK_DPS] = True
  111. self.assertEqual(self.lock.state, STATE_LOCKED)
  112. self.dps[LOCK_DPS] = False
  113. self.assertEqual(self.lock.state, STATE_UNLOCKED)
  114. self.dps[LOCK_DPS] = None
  115. self.assertEqual(self.lock.state, STATE_UNAVAILABLE)
  116. def test_lock_is_locked(self):
  117. self.dps[LOCK_DPS] = True
  118. self.assertTrue(self.lock.is_locked)
  119. self.dps[LOCK_DPS] = False
  120. self.assertFalse(self.lock.is_locked)
  121. self.dps[LOCK_DPS] = None
  122. self.assertFalse(self.lock.is_locked)
  123. async def test_lock_locks(self):
  124. async with assert_device_properties_set(self.lock._device, {LOCK_DPS: True}):
  125. await self.lock.async_lock()
  126. async def test_lock_unlocks(self):
  127. async with assert_device_properties_set(self.lock._device, {LOCK_DPS: False}):
  128. await self.lock.async_unlock()