test_tadiran_wind_heatpump.py 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. from homeassistant.components.climate.const import (
  2. HVAC_MODE_HEAT_COOL,
  3. HVAC_MODE_COOL,
  4. HVAC_MODE_DRY,
  5. HVAC_MODE_FAN_ONLY,
  6. HVAC_MODE_HEAT,
  7. HVAC_MODE_OFF,
  8. SUPPORT_FAN_MODE,
  9. SUPPORT_TARGET_TEMPERATURE,
  10. )
  11. from homeassistant.const import STATE_UNAVAILABLE
  12. from ..const import TADIRAN_HEATPUMP_PAYLOAD
  13. from ..helpers import assert_device_properties_set
  14. from .base_device_tests import TuyaDeviceTestCase
  15. POWER_DPS = "1"
  16. TEMPERATURE_DPS = "2"
  17. CURRENTTEMP_DPS = "3"
  18. HVACMODE_DPS = "4"
  19. FAN_DPS = "5"
  20. class TestTadiranWindHeatpump(TuyaDeviceTestCase):
  21. __test__ = True
  22. def setUp(self):
  23. self.setUpForConfig("tadiran_wind_heatpump.yaml", TADIRAN_HEATPUMP_PAYLOAD)
  24. self.subject = self.entities.get("climate")
  25. def test_supported_features(self):
  26. self.assertEqual(
  27. self.subject.supported_features,
  28. SUPPORT_FAN_MODE | SUPPORT_TARGET_TEMPERATURE,
  29. )
  30. def test_icon(self):
  31. self.dps[POWER_DPS] = True
  32. self.dps[HVACMODE_DPS] = "auto"
  33. self.assertEqual(self.subject.icon, "mdi:hvac")
  34. self.dps[HVACMODE_DPS] = "cooling"
  35. self.assertEqual(self.subject.icon, "mdi:snowflake")
  36. self.dps[HVACMODE_DPS] = "heating"
  37. self.assertEqual(self.subject.icon, "mdi:fire")
  38. self.dps[HVACMODE_DPS] = "dehum"
  39. self.assertEqual(self.subject.icon, "mdi:water")
  40. self.dps[HVACMODE_DPS] = "fan"
  41. self.assertEqual(self.subject.icon, "mdi:fan")
  42. self.dps[POWER_DPS] = False
  43. self.assertEqual(self.subject.icon, "mdi:hvac-off")
  44. def test_temperature_unit_returns_device_temperature_unit(self):
  45. self.assertEqual(
  46. self.subject.temperature_unit, self.subject._device.temperature_unit
  47. )
  48. def test_target_temperature(self):
  49. self.dps[TEMPERATURE_DPS] = 25
  50. self.assertEqual(self.subject.target_temperature, 25)
  51. def test_target_temperature_step(self):
  52. self.assertEqual(self.subject.target_temperature_step, 1)
  53. def test_minimum_target_temperature(self):
  54. self.assertEqual(self.subject.min_temp, 16)
  55. def test_maximum_target_temperature(self):
  56. self.assertEqual(self.subject.max_temp, 32)
  57. async def test_legacy_set_temperature_with_temperature(self):
  58. async with assert_device_properties_set(
  59. self.subject._device, {TEMPERATURE_DPS: 24}
  60. ):
  61. await self.subject.async_set_temperature(temperature=24)
  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_fails_outside_valid_range(self):
  72. with self.assertRaisesRegex(
  73. ValueError, "temperature \\(15\\) must be between 16 and 32"
  74. ):
  75. await self.subject.async_set_target_temperature(15)
  76. with self.assertRaisesRegex(
  77. ValueError, "temperature \\(33\\) must be between 16 and 32"
  78. ):
  79. await self.subject.async_set_target_temperature(33)
  80. def test_current_temperature(self):
  81. self.dps[CURRENTTEMP_DPS] = 250
  82. self.assertEqual(self.subject.current_temperature, 25)
  83. def test_hvac_mode(self):
  84. self.dps[POWER_DPS] = True
  85. self.dps[HVACMODE_DPS] = "heating"
  86. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_HEAT)
  87. self.dps[HVACMODE_DPS] = "cooling"
  88. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_COOL)
  89. self.dps[HVACMODE_DPS] = "dehum"
  90. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_DRY)
  91. self.dps[HVACMODE_DPS] = "fan"
  92. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_FAN_ONLY)
  93. self.dps[HVACMODE_DPS] = "auto"
  94. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_HEAT_COOL)
  95. self.dps[HVACMODE_DPS] = None
  96. self.assertEqual(self.subject.hvac_mode, STATE_UNAVAILABLE)
  97. self.dps[HVACMODE_DPS] = "auto"
  98. self.dps[POWER_DPS] = False
  99. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_OFF)
  100. def test_hvac_modes(self):
  101. self.assertCountEqual(
  102. self.subject.hvac_modes,
  103. [
  104. HVAC_MODE_OFF,
  105. HVAC_MODE_HEAT,
  106. HVAC_MODE_HEAT_COOL,
  107. HVAC_MODE_COOL,
  108. HVAC_MODE_DRY,
  109. HVAC_MODE_FAN_ONLY,
  110. ],
  111. )
  112. async def test_turn_on(self):
  113. async with assert_device_properties_set(
  114. self.subject._device, {POWER_DPS: True, HVACMODE_DPS: "heating"}
  115. ):
  116. await self.subject.async_set_hvac_mode(HVAC_MODE_HEAT)
  117. async def test_turn_off(self):
  118. async with assert_device_properties_set(
  119. self.subject._device, {POWER_DPS: False}
  120. ):
  121. await self.subject.async_set_hvac_mode(HVAC_MODE_OFF)
  122. def test_fan_modes(self):
  123. self.assertCountEqual(
  124. self.subject.fan_modes,
  125. ["auto", "low", "medium", "high"],
  126. )
  127. def test_fan_mode(self):
  128. self.dps[FAN_DPS] = "low"
  129. self.assertEqual(self.subject.fan_mode, "low")
  130. self.dps[FAN_DPS] = "middle"
  131. self.assertEqual(self.subject.fan_mode, "medium")
  132. self.dps[FAN_DPS] = "high"
  133. self.assertEqual(self.subject.fan_mode, "high")
  134. self.dps[FAN_DPS] = "auto"
  135. self.assertEqual(self.subject.fan_mode, "auto")
  136. async def test_set_fan_to_low(self):
  137. async with assert_device_properties_set(
  138. self.subject._device,
  139. {FAN_DPS: "low"},
  140. ):
  141. await self.subject.async_set_fan_mode("low")
  142. async def test_set_fan_to_medium(self):
  143. async with assert_device_properties_set(
  144. self.subject._device,
  145. {FAN_DPS: "middle"},
  146. ):
  147. await self.subject.async_set_fan_mode("medium")
  148. async def test_set_fan_to_high(self):
  149. async with assert_device_properties_set(
  150. self.subject._device,
  151. {FAN_DPS: "high"},
  152. ):
  153. await self.subject.async_set_fan_mode("high")
  154. async def test_set_fan_to_auto(self):
  155. async with assert_device_properties_set(
  156. self.subject._device,
  157. {FAN_DPS: "auto"},
  158. ):
  159. await self.subject.async_set_fan_mode("auto")
  160. def test_device_state_attributes(self):
  161. self.dps["101"] = 101
  162. self.dps["102"] = 102
  163. self.dps["103"] = 103
  164. self.dps["104"] = "unknown104"
  165. self.dps["105"] = "unknown105"
  166. self.dps["106"] = 106
  167. self.dps["107"] = True
  168. self.dps["108"] = False
  169. self.assertDictEqual(
  170. self.subject.device_state_attributes,
  171. {
  172. "unknown_101": 101,
  173. "unknown_102": 102,
  174. "unknown_103": 103,
  175. "unknown_104": "unknown104",
  176. "unknown_105": "unknown105",
  177. "unknown_106": 106,
  178. "unknown_107": True,
  179. "unknown_108": False,
  180. },
  181. )