test_eberg_qubo_q40hd_heatpump.py 9.6 KB

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