test_eberg_qubo_q40hd_heatpump.py 10.0 KB

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