test_kogan_kawfpac09ya_airconditioner.py 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. from homeassistant.components.climate.const import (
  2. HVAC_MODE_COOL,
  3. HVAC_MODE_DRY,
  4. HVAC_MODE_FAN_ONLY,
  5. HVAC_MODE_OFF,
  6. SUPPORT_FAN_MODE,
  7. SUPPORT_TARGET_TEMPERATURE,
  8. )
  9. from homeassistant.const import STATE_UNAVAILABLE, TEMP_CELSIUS, TEMP_FAHRENHEIT
  10. from ..const import KOGAN_KAWFPAC09YA_AIRCON_PAYLOAD
  11. from ..helpers import assert_device_properties_set
  12. from .base_device_tests import TuyaDeviceTestCase
  13. POWER_DPS = "1"
  14. TEMPERATURE_DPS = "2"
  15. CURRENTTEMP_DPS = "3"
  16. HVACMODE_DPS = "4"
  17. FAN_DPS = "5"
  18. UNIT_DPS = "19"
  19. COUNTDOWN_DPS = "105"
  20. UNKNOWN106_DPS = "106"
  21. UNKNOWN107_DPS = "107"
  22. class TestKoganKAWFPAC09YA(TuyaDeviceTestCase):
  23. __test__ = True
  24. def setUp(self):
  25. self.setUpForConfig(
  26. "kogan_kawfpac09ya_airconditioner.yaml",
  27. KOGAN_KAWFPAC09YA_AIRCON_PAYLOAD,
  28. )
  29. self.subject = self.entities.get("climate")
  30. def test_supported_features(self):
  31. self.assertEqual(
  32. self.subject.supported_features,
  33. SUPPORT_TARGET_TEMPERATURE | SUPPORT_FAN_MODE,
  34. )
  35. def test_icon(self):
  36. self.dps[POWER_DPS] = True
  37. self.dps[HVACMODE_DPS] = "COOL"
  38. self.assertEqual(self.subject.icon, "mdi:snowflake")
  39. self.dps[HVACMODE_DPS] = "DRY"
  40. self.assertEqual(self.subject.icon, "mdi:water")
  41. self.dps[HVACMODE_DPS] = "FAN"
  42. self.assertEqual(self.subject.icon, "mdi:fan")
  43. self.dps[POWER_DPS] = False
  44. self.assertEqual(self.subject.icon, "mdi:hvac-off")
  45. def test_temperature_unit(self):
  46. self.dps[UNIT_DPS] = "C"
  47. self.assertEqual(self.subject.temperature_unit, TEMP_CELSIUS)
  48. self.dps[UNIT_DPS] = "F"
  49. self.assertEqual(self.subject.temperature_unit, TEMP_FAHRENHEIT)
  50. def test_target_temperature(self):
  51. self.dps[TEMPERATURE_DPS] = 25
  52. self.assertEqual(self.subject.target_temperature, 25)
  53. def test_target_temperature_step(self):
  54. self.assertEqual(self.subject.target_temperature_step, 1)
  55. def test_minimum_target_temperature(self):
  56. self.dps[UNIT_DPS] = "C"
  57. self.assertEqual(self.subject.min_temp, 16)
  58. self.dps[UNIT_DPS] = "F"
  59. self.assertEqual(self.subject.min_temp, 60)
  60. def test_maximum_target_temperature(self):
  61. self.dps[UNIT_DPS] = "C"
  62. self.assertEqual(self.subject.max_temp, 30)
  63. self.dps[UNIT_DPS] = "F"
  64. self.assertEqual(self.subject.max_temp, 86)
  65. async def test_legacy_set_temperature_with_temperature(self):
  66. async with assert_device_properties_set(
  67. self.subject._device, {TEMPERATURE_DPS: 24}
  68. ):
  69. await self.subject.async_set_temperature(temperature=24)
  70. async def test_legacy_set_temperature_with_no_valid_properties(self):
  71. await self.subject.async_set_temperature(something="else")
  72. self.subject._device.async_set_property.assert_not_called()
  73. async def test_set_target_temperature_succeeds_within_valid_range(self):
  74. async with assert_device_properties_set(
  75. self.subject._device,
  76. {TEMPERATURE_DPS: 25},
  77. ):
  78. await self.subject.async_set_target_temperature(25)
  79. async def test_set_target_temperature_rounds_value_to_closest_integer(self):
  80. async with assert_device_properties_set(
  81. self.subject._device, {TEMPERATURE_DPS: 23}
  82. ):
  83. await self.subject.async_set_target_temperature(22.6)
  84. async def test_set_target_temperature_fails_outside_valid_range(self):
  85. with self.assertRaisesRegex(
  86. ValueError, "temperature \\(15\\) must be between 16 and 30"
  87. ):
  88. await self.subject.async_set_target_temperature(15)
  89. with self.assertRaisesRegex(
  90. ValueError, "temperature \\(31\\) must be between 16 and 30"
  91. ):
  92. await self.subject.async_set_target_temperature(31)
  93. def test_current_temperature(self):
  94. self.dps[CURRENTTEMP_DPS] = 25
  95. self.assertEqual(self.subject.current_temperature, 25)
  96. def test_hvac_mode(self):
  97. self.dps[POWER_DPS] = True
  98. self.dps[HVACMODE_DPS] = "COOL"
  99. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_COOL)
  100. self.dps[HVACMODE_DPS] = "DRY"
  101. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_DRY)
  102. self.dps[HVACMODE_DPS] = "FAN"
  103. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_FAN_ONLY)
  104. self.dps[HVACMODE_DPS] = None
  105. self.assertEqual(self.subject.hvac_mode, STATE_UNAVAILABLE)
  106. self.dps[HVACMODE_DPS] = "FAN"
  107. self.dps[POWER_DPS] = False
  108. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_OFF)
  109. def test_hvac_modes(self):
  110. self.assertCountEqual(
  111. self.subject.hvac_modes,
  112. [
  113. HVAC_MODE_OFF,
  114. HVAC_MODE_COOL,
  115. HVAC_MODE_DRY,
  116. HVAC_MODE_FAN_ONLY,
  117. ],
  118. )
  119. async def test_turn_on(self):
  120. async with assert_device_properties_set(
  121. self.subject._device, {POWER_DPS: True, HVACMODE_DPS: "COOL"}
  122. ):
  123. await self.subject.async_set_hvac_mode(HVAC_MODE_COOL)
  124. async def test_turn_off(self):
  125. async with assert_device_properties_set(
  126. self.subject._device, {POWER_DPS: False}
  127. ):
  128. await self.subject.async_set_hvac_mode(HVAC_MODE_OFF)
  129. def test_fan_mode(self):
  130. self.dps[FAN_DPS] = "1"
  131. self.assertEqual(self.subject.fan_mode, "low")
  132. self.dps[FAN_DPS] = "2"
  133. self.assertEqual(self.subject.fan_mode, "high")
  134. def test_fan_modes(self):
  135. self.assertCountEqual(
  136. self.subject.fan_modes,
  137. [
  138. "low",
  139. "high",
  140. ],
  141. )
  142. async def test_set_fan_mode_to_low(self):
  143. async with assert_device_properties_set(
  144. self.subject._device,
  145. {FAN_DPS: "1"},
  146. ):
  147. await self.subject.async_set_fan_mode("low")
  148. async def test_set_fan_mode_to_high(self):
  149. async with assert_device_properties_set(
  150. self.subject._device,
  151. {FAN_DPS: "2"},
  152. ):
  153. await self.subject.async_set_fan_mode("high")
  154. def test_device_state_attribures(self):
  155. self.dps[COUNTDOWN_DPS] = 105
  156. self.dps[UNKNOWN106_DPS] = 106
  157. self.dps[UNKNOWN107_DPS] = True
  158. self.assertDictEqual(
  159. self.subject.device_state_attributes,
  160. {
  161. "countdown": 105,
  162. "unknown_106": 106,
  163. "unknown_107": True,
  164. },
  165. )