test_kogan_kahtp_heater.py 6.2 KB

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