test_kogan_kawfhtp_heater.py 7.0 KB

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