test_eberg_qubo_q40hd_heatpump.py 9.6 KB

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