test_goldair_gpcv_heater.py 7.3 KB

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