test_eberg_qubo_q40hd_heatpump.py 9.7 KB

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