test_eberg_qubo_q40hd_heatpump.py 12 KB

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