test_eberg_qubo_q40hd_heatpump.py 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. from homeassistant.components.climate.const import (
  2. HVAC_MODE_COOL,
  3. HVAC_MODE_DRY,
  4. HVAC_MODE_FAN_ONLY,
  5. HVAC_MODE_HEAT,
  6. HVAC_MODE_OFF,
  7. SUPPORT_FAN_MODE,
  8. SUPPORT_TARGET_TEMPERATURE,
  9. )
  10. from homeassistant.const import STATE_UNAVAILABLE, TEMP_CELSIUS, TEMP_FAHRENHEIT
  11. from ..const import EBERG_QUBO_Q40HD_PAYLOAD
  12. from ..helpers import assert_device_properties_set
  13. from .base_device_tests import TuyaDeviceTestCase
  14. POWER_DPS = "1"
  15. TEMPERATURE_DPS = "2"
  16. CURRENTTEMP_DPS = "3"
  17. HVACMODE_DPS = "4"
  18. FAN_DPS = "5"
  19. UNIT_DPS = "19"
  20. TIMER_DPS = "22"
  21. UNKNOWN25_DPS = "25"
  22. UNKNOWN30_DPS = "30"
  23. UNKNOWN101_DPS = "101"
  24. class TestEbergQuboQ40HDHeatpump(TuyaDeviceTestCase):
  25. __test__ = True
  26. def setUp(self):
  27. self.setUpForConfig(
  28. "eberg_qubo_q40hd_heatpump.yaml",
  29. EBERG_QUBO_Q40HD_PAYLOAD,
  30. )
  31. self.subject = self.entities.get("climate")
  32. def test_supported_features(self):
  33. self.assertEqual(
  34. self.subject.supported_features,
  35. SUPPORT_TARGET_TEMPERATURE | SUPPORT_FAN_MODE,
  36. )
  37. def test_icon(self):
  38. self.dps[POWER_DPS] = True
  39. self.dps[HVACMODE_DPS] = "cold"
  40. self.assertEqual(self.subject.icon, "mdi:snowflake")
  41. self.dps[HVACMODE_DPS] = "hot"
  42. self.assertEqual(self.subject.icon, "mdi:fire")
  43. self.dps[HVACMODE_DPS] = "wet"
  44. self.assertEqual(self.subject.icon, "mdi:water")
  45. self.dps[HVACMODE_DPS] = "wind"
  46. self.assertEqual(self.subject.icon, "mdi:fan")
  47. self.dps[POWER_DPS] = False
  48. self.assertEqual(self.subject.icon, "mdi:hvac-off")
  49. def test_temperature_unit(self):
  50. self.dps[UNIT_DPS] = "c"
  51. self.assertEqual(self.subject.temperature_unit, TEMP_CELSIUS)
  52. self.dps[UNIT_DPS] = "f"
  53. self.assertEqual(self.subject.temperature_unit, TEMP_FAHRENHEIT)
  54. def test_target_temperature(self):
  55. self.dps[TEMPERATURE_DPS] = 25
  56. self.assertEqual(self.subject.target_temperature, 25)
  57. def test_target_temperature_step(self):
  58. self.assertEqual(self.subject.target_temperature_step, 1)
  59. def test_minimum_target_temperature(self):
  60. self.dps[UNIT_DPS] = "c"
  61. self.assertEqual(self.subject.min_temp, 15)
  62. self.dps[UNIT_DPS] = "f"
  63. self.assertEqual(self.subject.min_temp, 60)
  64. def test_maximum_target_temperature(self):
  65. self.dps[UNIT_DPS] = "c"
  66. self.assertEqual(self.subject.max_temp, 30)
  67. self.dps[UNIT_DPS] = "f"
  68. self.assertEqual(self.subject.max_temp, 86)
  69. async def test_legacy_set_temperature_with_temperature(self):
  70. async with assert_device_properties_set(
  71. self.subject._device, {TEMPERATURE_DPS: 24}
  72. ):
  73. await self.subject.async_set_temperature(temperature=24)
  74. async def test_legacy_set_temperature_with_no_valid_properties(self):
  75. await self.subject.async_set_temperature(something="else")
  76. self.subject._device.async_set_property.assert_not_called()
  77. async def test_set_target_temperature_succeeds_within_valid_range(self):
  78. async with assert_device_properties_set(
  79. self.subject._device,
  80. {TEMPERATURE_DPS: 25},
  81. ):
  82. await self.subject.async_set_target_temperature(25)
  83. self.dps[UNIT_DPS] = "f"
  84. async with assert_device_properties_set(
  85. self.subject._device,
  86. {TEMPERATURE_DPS: 70},
  87. ):
  88. await self.subject.async_set_target_temperature(70)
  89. async def test_set_target_temperature_rounds_value_to_closest_integer(self):
  90. async with assert_device_properties_set(
  91. self.subject._device, {TEMPERATURE_DPS: 23}
  92. ):
  93. await self.subject.async_set_target_temperature(22.6)
  94. async def test_set_target_temperature_fails_outside_valid_range(self):
  95. with self.assertRaisesRegex(
  96. ValueError, "temperature \\(14\\) must be between 15 and 30"
  97. ):
  98. await self.subject.async_set_target_temperature(14)
  99. with self.assertRaisesRegex(
  100. ValueError, "temperature \\(31\\) must be between 15 and 30"
  101. ):
  102. await self.subject.async_set_target_temperature(31)
  103. self.dps[UNIT_DPS] = "f"
  104. with self.assertRaisesRegex(
  105. ValueError, "temperature \\(59\\) must be between 60 and 86"
  106. ):
  107. await self.subject.async_set_target_temperature(59)
  108. with self.assertRaisesRegex(
  109. ValueError, "temperature \\(87\\) must be between 60 and 86"
  110. ):
  111. await self.subject.async_set_target_temperature(87)
  112. def test_current_temperature(self):
  113. self.dps[CURRENTTEMP_DPS] = 25
  114. self.assertEqual(self.subject.current_temperature, 25)
  115. def test_hvac_mode(self):
  116. self.dps[POWER_DPS] = True
  117. self.dps[HVACMODE_DPS] = "cold"
  118. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_COOL)
  119. self.dps[HVACMODE_DPS] = "hot"
  120. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_HEAT)
  121. self.dps[HVACMODE_DPS] = "wet"
  122. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_DRY)
  123. self.dps[HVACMODE_DPS] = "wind"
  124. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_FAN_ONLY)
  125. self.dps[HVACMODE_DPS] = None
  126. self.assertEqual(self.subject.hvac_mode, STATE_UNAVAILABLE)
  127. self.dps[HVACMODE_DPS] = "wind"
  128. self.dps[POWER_DPS] = False
  129. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_OFF)
  130. def test_hvac_modes(self):
  131. self.assertCountEqual(
  132. self.subject.hvac_modes,
  133. [
  134. HVAC_MODE_OFF,
  135. HVAC_MODE_COOL,
  136. HVAC_MODE_DRY,
  137. HVAC_MODE_FAN_ONLY,
  138. HVAC_MODE_HEAT,
  139. ],
  140. )
  141. async def test_turn_on(self):
  142. async with assert_device_properties_set(
  143. self.subject._device, {POWER_DPS: True, HVACMODE_DPS: "cold"}
  144. ):
  145. await self.subject.async_set_hvac_mode(HVAC_MODE_COOL)
  146. async def test_turn_off(self):
  147. async with assert_device_properties_set(
  148. self.subject._device, {POWER_DPS: False}
  149. ):
  150. await self.subject.async_set_hvac_mode(HVAC_MODE_OFF)
  151. def test_fan_mode(self):
  152. self.dps[HVACMODE_DPS] = "cold"
  153. self.dps[FAN_DPS] = "low"
  154. self.assertEqual(self.subject.fan_mode, "low")
  155. self.dps[FAN_DPS] = "middle"
  156. self.assertEqual(self.subject.fan_mode, "medium")
  157. self.dps[FAN_DPS] = "high"
  158. self.assertEqual(self.subject.fan_mode, "high")
  159. self.dps[FAN_DPS] = "auto"
  160. self.assertEqual(self.subject.fan_mode, "auto")
  161. def test_fan_modes(self):
  162. self.assertCountEqual(
  163. self.subject.fan_modes,
  164. [
  165. "auto",
  166. "low",
  167. "medium",
  168. "high",
  169. ],
  170. )
  171. async def test_set_fan_mode_to_low(self):
  172. self.dps[HVACMODE_DPS] = "cold"
  173. async with assert_device_properties_set(
  174. self.subject._device,
  175. {FAN_DPS: "low"},
  176. ):
  177. await self.subject.async_set_fan_mode("low")
  178. async def test_set_fan_mode_to_low_fails_when_heating(self):
  179. self.dps[HVACMODE_DPS] = "hot"
  180. with self.assertRaises(AttributeError):
  181. await self.subject.async_set_fan_mode("low")
  182. async def test_set_fan_mode_to_medium(self):
  183. self.dps[HVACMODE_DPS] = "cold"
  184. async with assert_device_properties_set(
  185. self.subject._device,
  186. {FAN_DPS: "middle"},
  187. ):
  188. await self.subject.async_set_fan_mode("medium")
  189. async def test_set_fan_mode_to_medium_fails_when_heating_or_drying(self):
  190. self.dps[HVACMODE_DPS] = "hot"
  191. with self.assertRaises(AttributeError):
  192. await self.subject.async_set_fan_mode("medium")
  193. self.dps[HVACMODE_DPS] = "wet"
  194. with self.assertRaises(AttributeError):
  195. await self.subject.async_set_fan_mode("medium")
  196. async def test_set_fan_mode_to_high(self):
  197. self.dps[HVACMODE_DPS] = "cold"
  198. async with assert_device_properties_set(
  199. self.subject._device,
  200. {FAN_DPS: "high"},
  201. ):
  202. await self.subject.async_set_fan_mode("high")
  203. async def test_set_fan_mode_to_high_fails_when_drying(self):
  204. self.dps[HVACMODE_DPS] = "wet"
  205. with self.assertRaises(AttributeError):
  206. await self.subject.async_set_fan_mode("high")
  207. async def test_set_fan_mode_to_auto(self):
  208. self.dps[HVACMODE_DPS] = "cold"
  209. async with assert_device_properties_set(
  210. self.subject._device,
  211. {FAN_DPS: "auto"},
  212. ):
  213. await self.subject.async_set_fan_mode("auto")
  214. async def test_set_fan_mode_to_auto_fails_unless_cooling(self):
  215. self.dps[HVACMODE_DPS] = "hot"
  216. with self.assertRaises(AttributeError):
  217. await self.subject.async_set_fan_mode("auto")
  218. self.dps[HVACMODE_DPS] = "wet"
  219. with self.assertRaises(AttributeError):
  220. await self.subject.async_set_fan_mode("auto")
  221. self.dps[HVACMODE_DPS] = "wind"
  222. with self.assertRaises(AttributeError):
  223. await self.subject.async_set_fan_mode("auto")
  224. def test_device_state_attribures(self):
  225. self.dps[TIMER_DPS] = 22
  226. self.dps[UNKNOWN25_DPS] = True
  227. self.dps[UNKNOWN30_DPS] = False
  228. self.dps[UNKNOWN101_DPS] = "101"
  229. self.assertDictEqual(
  230. self.subject.device_state_attributes,
  231. {
  232. "timer": 22,
  233. "unknown_25": True,
  234. "unknown_30": False,
  235. "unknown_101": "101",
  236. },
  237. )