test_eberg_qubo_q40hd_heatpump.py 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  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[POWER_DPS] = False
  70. self.assertEqual(self.subject.icon, "mdi:hvac-off")
  71. def test_temperature_unit(self):
  72. self.dps[UNIT_DPS] = "c"
  73. self.assertEqual(self.subject.temperature_unit, TEMP_CELSIUS)
  74. self.dps[UNIT_DPS] = "f"
  75. self.assertEqual(self.subject.temperature_unit, TEMP_FAHRENHEIT)
  76. def test_minimum_target_temperature_f(self):
  77. self.dps[UNIT_DPS] = "f"
  78. self.assertEqual(self.subject.min_temp, 63)
  79. def test_maximum_target_temperature_f(self):
  80. self.dps[UNIT_DPS] = "f"
  81. self.assertEqual(self.subject.max_temp, 86)
  82. def test_current_temperature(self):
  83. self.dps[CURRENTTEMP_DPS] = 25
  84. self.assertEqual(self.subject.current_temperature, 25)
  85. def test_hvac_mode(self):
  86. self.dps[POWER_DPS] = True
  87. self.dps[HVACMODE_DPS] = "cold"
  88. self.assertEqual(self.subject.hvac_mode, HVACMode.COOL)
  89. self.dps[HVACMODE_DPS] = "hot"
  90. self.assertEqual(self.subject.hvac_mode, HVACMode.HEAT)
  91. self.dps[HVACMODE_DPS] = "cold"
  92. self.dps[POWER_DPS] = False
  93. self.assertEqual(self.subject.hvac_mode, HVACMode.OFF)
  94. def test_hvac_modes(self):
  95. self.assertCountEqual(
  96. self.subject.hvac_modes,
  97. [
  98. HVACMode.OFF,
  99. HVACMode.COOL,
  100. HVACMode.HEAT,
  101. ],
  102. )
  103. async def test_turn_on(self):
  104. async with assert_device_properties_set(
  105. self.subject._device, {POWER_DPS: True, HVACMODE_DPS: "cold"}
  106. ):
  107. await self.subject.async_set_hvac_mode(HVACMode.COOL)
  108. async def test_turn_off(self):
  109. async with assert_device_properties_set(
  110. self.subject._device, {POWER_DPS: False}
  111. ):
  112. await self.subject.async_set_hvac_mode(HVACMode.OFF)
  113. def test_fan_mode(self):
  114. self.dps[FAN_DPS] = "low"
  115. self.assertEqual(self.subject.fan_mode, "low")
  116. self.dps[FAN_DPS] = "middle"
  117. self.assertEqual(self.subject.fan_mode, "medium")
  118. self.dps[FAN_DPS] = "high"
  119. self.assertEqual(self.subject.fan_mode, "high")
  120. self.dps[FAN_DPS] = "auto"
  121. self.assertEqual(self.subject.fan_mode, "auto")
  122. def test_fan_modes(self):
  123. self.assertCountEqual(
  124. self.subject.fan_modes,
  125. [
  126. "auto",
  127. "low",
  128. "medium",
  129. "high",
  130. ],
  131. )
  132. async def test_set_fan_mode_to_low(self):
  133. async with assert_device_properties_set(
  134. self.subject._device,
  135. {FAN_DPS: "low"},
  136. ):
  137. await self.subject.async_set_fan_mode("low")
  138. async def test_set_fan_mode_to_medium(self):
  139. async with assert_device_properties_set(
  140. self.subject._device,
  141. {FAN_DPS: "middle"},
  142. ):
  143. await self.subject.async_set_fan_mode("medium")
  144. async def test_set_fan_mode_to_high(self):
  145. async with assert_device_properties_set(
  146. self.subject._device,
  147. {FAN_DPS: "high"},
  148. ):
  149. await self.subject.async_set_fan_mode("high")
  150. async def test_set_fan_mode_to_auto(self):
  151. async with assert_device_properties_set(
  152. self.subject._device,
  153. {FAN_DPS: "auto"},
  154. ):
  155. await self.subject.async_set_fan_mode("auto")
  156. def test_swing_mode(self):
  157. self.dps[SWING_DPS] = True
  158. self.assertEqual(self.subject.swing_mode, SWING_VERTICAL)
  159. self.dps[SWING_DPS] = False
  160. self.assertEqual(self.subject.swing_mode, SWING_OFF)
  161. def test_swing_modes(self):
  162. self.assertCountEqual(
  163. self.subject.swing_modes,
  164. [
  165. SWING_VERTICAL,
  166. SWING_OFF,
  167. ],
  168. )
  169. async def test_set_swing_mode_to_vertical(self):
  170. async with assert_device_properties_set(
  171. self.subject._device,
  172. {SWING_DPS: True},
  173. ):
  174. await self.subject.async_set_swing_mode(SWING_VERTICAL)
  175. async def test_set_swing_mode_to_off(self):
  176. async with assert_device_properties_set(
  177. self.subject._device,
  178. {SWING_DPS: False},
  179. ):
  180. await self.subject.async_set_swing_mode(SWING_OFF)
  181. def test_preset_mode(self):
  182. self.dps[PRESET_DPS] = True
  183. self.assertEqual(self.subject.preset_mode, PRESET_SLEEP)
  184. self.dps[PRESET_DPS] = False
  185. self.assertEqual(self.subject.preset_mode, PRESET_COMFORT)
  186. def test_preset_modes(self):
  187. self.assertCountEqual(
  188. self.subject.preset_modes,
  189. [
  190. PRESET_COMFORT,
  191. PRESET_SLEEP,
  192. ],
  193. )
  194. async def test_set_preset_mode_to_sleep(self):
  195. async with assert_device_properties_set(
  196. self.subject._device,
  197. {PRESET_DPS: True},
  198. ):
  199. await self.subject.async_set_preset_mode(PRESET_SLEEP)
  200. async def test_set_preset_mode_to_normal(self):
  201. async with assert_device_properties_set(
  202. self.subject._device,
  203. {PRESET_DPS: False},
  204. ):
  205. await self.subject.async_set_preset_mode(PRESET_COMFORT)
  206. def test_hvac_action(self):
  207. self.dps[POWER_DPS] = True
  208. self.dps[HVACACTION_DPS] = "heat_s"
  209. self.assertEqual(self.subject.hvac_action, HVACAction.HEATING)
  210. self.dps[HVACACTION_DPS] = "hot"
  211. self.assertEqual(self.subject.hvac_action, HVACAction.HEATING)
  212. self.dps[HVACACTION_DPS] = "heating"
  213. self.assertEqual(self.subject.hvac_action, HVACAction.HEATING)
  214. self.dps[HVACACTION_DPS] = "cool_s"
  215. self.assertEqual(self.subject.hvac_action, HVACAction.COOLING)
  216. self.dps[HVACACTION_DPS] = "cooling"
  217. self.assertEqual(self.subject.hvac_action, HVACAction.COOLING)
  218. self.dps[HVACACTION_DPS] = "anti-clockwise"
  219. self.assertEqual(self.subject.hvac_action, HVACAction.FAN)
  220. self.dps[HVACACTION_DPS] = "ventilation"
  221. self.assertEqual(self.subject.hvac_action, HVACAction.FAN)
  222. self.dps[HVACACTION_DPS] = "wind"
  223. self.assertEqual(self.subject.hvac_action, HVACAction.FAN)
  224. self.dps[HVACACTION_DPS] = "appointment"
  225. self.assertEqual(self.subject.hvac_action, HVACAction.IDLE)
  226. self.dps[HVACACTION_DPS] = "auto"
  227. self.assertEqual(self.subject.hvac_action, HVACAction.IDLE)
  228. self.dps[HVACACTION_DPS] = "auto_clean"
  229. self.assertEqual(self.subject.hvac_action, HVACAction.IDLE)
  230. self.dps[HVACACTION_DPS] = "eco"
  231. self.assertEqual(self.subject.hvac_action, HVACAction.IDLE)
  232. self.dps[HVACACTION_DPS] = "wet"
  233. self.assertEqual(self.subject.hvac_action, HVACAction.DRYING)
  234. self.dps[HVACACTION_DPS] = "off"
  235. self.assertEqual(self.subject.hvac_action, HVACAction.IDLE)
  236. self.dps[POWER_DPS] = False
  237. self.assertEqual(self.subject.hvac_action, HVACAction.OFF)
  238. def test_extra_state_attributes(self):
  239. self.dps[TIMER_DPS] = 22
  240. self.assertDictEqual(
  241. self.subject.extra_state_attributes,
  242. {
  243. "timer": 22,
  244. },
  245. )