test_eberg_qubo_q40hd_heatpump.py 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  1. from homeassistant.components.climate.const import (
  2. CURRENT_HVAC_COOL,
  3. CURRENT_HVAC_DRY,
  4. CURRENT_HVAC_FAN,
  5. CURRENT_HVAC_HEAT,
  6. CURRENT_HVAC_IDLE,
  7. CURRENT_HVAC_OFF,
  8. HVAC_MODE_COOL,
  9. HVAC_MODE_HEAT,
  10. HVAC_MODE_OFF,
  11. PRESET_SLEEP,
  12. PRESET_COMFORT,
  13. SUPPORT_FAN_MODE,
  14. SUPPORT_PRESET_MODE,
  15. SUPPORT_SWING_MODE,
  16. SUPPORT_TARGET_TEMPERATURE,
  17. SWING_OFF,
  18. SWING_VERTICAL,
  19. )
  20. from homeassistant.const import STATE_UNAVAILABLE, TEMP_CELSIUS, TEMP_FAHRENHEIT
  21. from ..const import EBERG_QUBO_Q40HD_PAYLOAD
  22. from ..helpers import assert_device_properties_set
  23. from .base_device_tests import TuyaDeviceTestCase
  24. POWER_DPS = "1"
  25. TEMPERATURE_DPS = "2"
  26. CURRENTTEMP_DPS = "3"
  27. HVACMODE_DPS = "4"
  28. FAN_DPS = "5"
  29. UNIT_DPS = "19"
  30. TIMER_DPS = "22"
  31. PRESET_DPS = "25"
  32. SWING_DPS = "30"
  33. HVACACTION_DPS = "101"
  34. class TestEbergQuboQ40HDHeatpump(TuyaDeviceTestCase):
  35. __test__ = True
  36. def setUp(self):
  37. self.setUpForConfig(
  38. "eberg_qubo_q40hd_heatpump.yaml",
  39. EBERG_QUBO_Q40HD_PAYLOAD,
  40. )
  41. self.subject = self.entities.get("climate")
  42. def test_supported_features(self):
  43. self.assertEqual(
  44. self.subject.supported_features,
  45. (
  46. SUPPORT_TARGET_TEMPERATURE
  47. | SUPPORT_FAN_MODE
  48. | SUPPORT_PRESET_MODE
  49. | SUPPORT_SWING_MODE
  50. ),
  51. )
  52. def test_icon(self):
  53. self.dps[POWER_DPS] = True
  54. self.dps[HVACMODE_DPS] = "cold"
  55. self.assertEqual(self.subject.icon, "mdi:snowflake")
  56. self.dps[HVACMODE_DPS] = "hot"
  57. self.assertEqual(self.subject.icon, "mdi:fire")
  58. self.dps[POWER_DPS] = False
  59. self.assertEqual(self.subject.icon, "mdi:hvac-off")
  60. def test_temperature_unit(self):
  61. self.dps[UNIT_DPS] = "c"
  62. self.assertEqual(self.subject.temperature_unit, TEMP_CELSIUS)
  63. self.dps[UNIT_DPS] = "f"
  64. self.assertEqual(self.subject.temperature_unit, TEMP_FAHRENHEIT)
  65. def test_target_temperature(self):
  66. self.dps[TEMPERATURE_DPS] = 25
  67. self.assertEqual(self.subject.target_temperature, 25)
  68. def test_target_temperature_step(self):
  69. self.assertEqual(self.subject.target_temperature_step, 1)
  70. def test_minimum_target_temperature(self):
  71. self.dps[UNIT_DPS] = "c"
  72. self.assertEqual(self.subject.min_temp, 17)
  73. self.dps[UNIT_DPS] = "f"
  74. self.assertEqual(self.subject.min_temp, 63)
  75. def test_maximum_target_temperature(self):
  76. self.dps[UNIT_DPS] = "c"
  77. self.assertEqual(self.subject.max_temp, 30)
  78. self.dps[UNIT_DPS] = "f"
  79. self.assertEqual(self.subject.max_temp, 86)
  80. async def test_legacy_set_temperature_with_temperature(self):
  81. async with assert_device_properties_set(
  82. self.subject._device, {TEMPERATURE_DPS: 24}
  83. ):
  84. await self.subject.async_set_temperature(temperature=24)
  85. async def test_legacy_set_temperature_with_no_valid_properties(self):
  86. await self.subject.async_set_temperature(something="else")
  87. self.subject._device.async_set_property.assert_not_called()
  88. async def test_set_target_temperature_succeeds_within_valid_range(self):
  89. async with assert_device_properties_set(
  90. self.subject._device,
  91. {TEMPERATURE_DPS: 25},
  92. ):
  93. await self.subject.async_set_target_temperature(25)
  94. self.dps[UNIT_DPS] = "f"
  95. async with assert_device_properties_set(
  96. self.subject._device,
  97. {TEMPERATURE_DPS: 70},
  98. ):
  99. await self.subject.async_set_target_temperature(70)
  100. async def test_set_target_temperature_rounds_value_to_closest_integer(self):
  101. async with assert_device_properties_set(
  102. self.subject._device, {TEMPERATURE_DPS: 23}
  103. ):
  104. await self.subject.async_set_target_temperature(22.6)
  105. async def test_set_target_temperature_fails_outside_valid_range(self):
  106. with self.assertRaisesRegex(
  107. ValueError, "temperature \\(16\\) must be between 17 and 30"
  108. ):
  109. await self.subject.async_set_target_temperature(16)
  110. with self.assertRaisesRegex(
  111. ValueError, "temperature \\(31\\) must be between 17 and 30"
  112. ):
  113. await self.subject.async_set_target_temperature(31)
  114. self.dps[UNIT_DPS] = "f"
  115. with self.assertRaisesRegex(
  116. ValueError, "temperature \\(62\\) must be between 63 and 86"
  117. ):
  118. await self.subject.async_set_target_temperature(62)
  119. with self.assertRaisesRegex(
  120. ValueError, "temperature \\(87\\) must be between 63 and 86"
  121. ):
  122. await self.subject.async_set_target_temperature(87)
  123. def test_current_temperature(self):
  124. self.dps[CURRENTTEMP_DPS] = 25
  125. self.assertEqual(self.subject.current_temperature, 25)
  126. def test_hvac_mode(self):
  127. self.dps[POWER_DPS] = True
  128. self.dps[HVACMODE_DPS] = "cold"
  129. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_COOL)
  130. self.dps[HVACMODE_DPS] = "hot"
  131. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_HEAT)
  132. self.dps[HVACMODE_DPS] = None
  133. self.assertEqual(self.subject.hvac_mode, STATE_UNAVAILABLE)
  134. self.dps[HVACMODE_DPS] = "cold"
  135. self.dps[POWER_DPS] = False
  136. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_OFF)
  137. def test_hvac_modes(self):
  138. self.assertCountEqual(
  139. self.subject.hvac_modes,
  140. [
  141. HVAC_MODE_OFF,
  142. HVAC_MODE_COOL,
  143. HVAC_MODE_HEAT,
  144. ],
  145. )
  146. async def test_turn_on(self):
  147. async with assert_device_properties_set(
  148. self.subject._device, {POWER_DPS: True, HVACMODE_DPS: "cold"}
  149. ):
  150. await self.subject.async_set_hvac_mode(HVAC_MODE_COOL)
  151. async def test_turn_off(self):
  152. async with assert_device_properties_set(
  153. self.subject._device, {POWER_DPS: False}
  154. ):
  155. await self.subject.async_set_hvac_mode(HVAC_MODE_OFF)
  156. def test_fan_mode(self):
  157. self.dps[FAN_DPS] = "low"
  158. self.assertEqual(self.subject.fan_mode, "low")
  159. self.dps[FAN_DPS] = "middle"
  160. self.assertEqual(self.subject.fan_mode, "medium")
  161. self.dps[FAN_DPS] = "high"
  162. self.assertEqual(self.subject.fan_mode, "high")
  163. self.dps[FAN_DPS] = "auto"
  164. self.assertEqual(self.subject.fan_mode, "auto")
  165. def test_fan_modes(self):
  166. self.assertCountEqual(
  167. self.subject.fan_modes,
  168. [
  169. "auto",
  170. "low",
  171. "medium",
  172. "high",
  173. ],
  174. )
  175. async def test_set_fan_mode_to_low(self):
  176. async with assert_device_properties_set(
  177. self.subject._device,
  178. {FAN_DPS: "low"},
  179. ):
  180. await self.subject.async_set_fan_mode("low")
  181. async def test_set_fan_mode_to_medium(self):
  182. async with assert_device_properties_set(
  183. self.subject._device,
  184. {FAN_DPS: "middle"},
  185. ):
  186. await self.subject.async_set_fan_mode("medium")
  187. async def test_set_fan_mode_to_high(self):
  188. async with assert_device_properties_set(
  189. self.subject._device,
  190. {FAN_DPS: "high"},
  191. ):
  192. await self.subject.async_set_fan_mode("high")
  193. async def test_set_fan_mode_to_auto(self):
  194. async with assert_device_properties_set(
  195. self.subject._device,
  196. {FAN_DPS: "auto"},
  197. ):
  198. await self.subject.async_set_fan_mode("auto")
  199. def test_swing_mode(self):
  200. self.dps[SWING_DPS] = True
  201. self.assertEqual(self.subject.swing_mode, SWING_VERTICAL)
  202. self.dps[SWING_DPS] = False
  203. self.assertEqual(self.subject.swing_mode, SWING_OFF)
  204. def test_swing_modes(self):
  205. self.assertCountEqual(
  206. self.subject.swing_modes,
  207. [
  208. SWING_VERTICAL,
  209. SWING_OFF,
  210. ],
  211. )
  212. async def test_set_swing_mode_to_vertical(self):
  213. async with assert_device_properties_set(
  214. self.subject._device,
  215. {SWING_DPS: True},
  216. ):
  217. await self.subject.async_set_swing_mode(SWING_VERTICAL)
  218. async def test_set_swing_mode_to_off(self):
  219. async with assert_device_properties_set(
  220. self.subject._device,
  221. {SWING_DPS: False},
  222. ):
  223. await self.subject.async_set_swing_mode(SWING_OFF)
  224. def test_preset_mode(self):
  225. self.dps[PRESET_DPS] = True
  226. self.assertEqual(self.subject.preset_mode, PRESET_SLEEP)
  227. self.dps[PRESET_DPS] = False
  228. self.assertEqual(self.subject.preset_mode, PRESET_COMFORT)
  229. def test_preset_modes(self):
  230. self.assertCountEqual(
  231. self.subject.preset_modes,
  232. [
  233. PRESET_COMFORT,
  234. PRESET_SLEEP,
  235. ],
  236. )
  237. async def test_set_preset_mode_to_sleep(self):
  238. async with assert_device_properties_set(
  239. self.subject._device,
  240. {PRESET_DPS: True},
  241. ):
  242. await self.subject.async_set_preset_mode(PRESET_SLEEP)
  243. async def test_set_preset_mode_to_normal(self):
  244. async with assert_device_properties_set(
  245. self.subject._device,
  246. {PRESET_DPS: False},
  247. ):
  248. await self.subject.async_set_preset_mode(PRESET_COMFORT)
  249. def test_hvac_action(self):
  250. self.dps[POWER_DPS] = True
  251. self.dps[HVACACTION_DPS] = "heat_s"
  252. self.assertEqual(self.subject.hvac_action, CURRENT_HVAC_HEAT)
  253. self.dps[HVACACTION_DPS] = "hot"
  254. self.assertEqual(self.subject.hvac_action, CURRENT_HVAC_HEAT)
  255. self.dps[HVACACTION_DPS] = "heating"
  256. self.assertEqual(self.subject.hvac_action, CURRENT_HVAC_HEAT)
  257. self.dps[HVACACTION_DPS] = "cool_s"
  258. self.assertEqual(self.subject.hvac_action, CURRENT_HVAC_COOL)
  259. self.dps[HVACACTION_DPS] = "cooling"
  260. self.assertEqual(self.subject.hvac_action, CURRENT_HVAC_COOL)
  261. self.dps[HVACACTION_DPS] = "anti-clockwise"
  262. self.assertEqual(self.subject.hvac_action, CURRENT_HVAC_FAN)
  263. self.dps[HVACACTION_DPS] = "ventilation"
  264. self.assertEqual(self.subject.hvac_action, CURRENT_HVAC_FAN)
  265. self.dps[HVACACTION_DPS] = "wind"
  266. self.assertEqual(self.subject.hvac_action, CURRENT_HVAC_FAN)
  267. self.dps[HVACACTION_DPS] = "appointment"
  268. self.assertEqual(self.subject.hvac_action, CURRENT_HVAC_IDLE)
  269. self.dps[HVACACTION_DPS] = "auto"
  270. self.assertEqual(self.subject.hvac_action, CURRENT_HVAC_IDLE)
  271. self.dps[HVACACTION_DPS] = "auto_clean"
  272. self.assertEqual(self.subject.hvac_action, CURRENT_HVAC_IDLE)
  273. self.dps[HVACACTION_DPS] = "eco"
  274. self.assertEqual(self.subject.hvac_action, CURRENT_HVAC_IDLE)
  275. self.dps[HVACACTION_DPS] = "wet"
  276. self.assertEqual(self.subject.hvac_action, CURRENT_HVAC_DRY)
  277. self.dps[HVACACTION_DPS] = "off"
  278. self.assertEqual(self.subject.hvac_action, CURRENT_HVAC_IDLE)
  279. self.dps[POWER_DPS] = False
  280. self.assertEqual(self.subject.hvac_action, CURRENT_HVAC_OFF)
  281. def test_device_state_attribures(self):
  282. self.dps[TIMER_DPS] = 22
  283. self.assertDictEqual(
  284. self.subject.device_state_attributes,
  285. {
  286. "timer": 22,
  287. },
  288. )