test_electriq_12wminv_heatpump.py 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. from homeassistant.components.climate.const import (
  2. HVAC_MODE_HEAT_COOL,
  3. HVAC_MODE_COOL,
  4. HVAC_MODE_DRY,
  5. HVAC_MODE_FAN_ONLY,
  6. HVAC_MODE_HEAT,
  7. HVAC_MODE_OFF,
  8. SUPPORT_FAN_MODE,
  9. SUPPORT_SWING_MODE,
  10. SUPPORT_TARGET_TEMPERATURE,
  11. )
  12. from homeassistant.const import STATE_UNAVAILABLE
  13. from ..const import ELECTRIQ_12WMINV_HEATPUMP_PAYLOAD
  14. from ..helpers import assert_device_properties_set
  15. from ..mixins.climate import TargetTemperatureTests
  16. from ..mixins.light import BasicLightTests
  17. from ..mixins.switch import BasicSwitchTests
  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. UNKNOWN8_DPS = "8"
  25. UNKNOWN12_DPS = "12"
  26. SWITCH_DPS = "101"
  27. UNKNOWN102_DPS = "102"
  28. UNKNOWN103_DPS = "103"
  29. LIGHT_DPS = "104"
  30. VSWING_DPS = "106"
  31. HSWING_DPS = "107"
  32. UNKNOWN108_DPS = "108"
  33. UNKNOWN109_DPS = "109"
  34. UNKNOWN110_DPS = "110"
  35. class TestElectriq12WMINVHeatpump(
  36. BasicLightTests,
  37. BasicSwitchTests,
  38. TargetTemperatureTests,
  39. TuyaDeviceTestCase,
  40. ):
  41. __test__ = True
  42. def setUp(self):
  43. self.setUpForConfig(
  44. "electriq_12wminv_heatpump.yaml", ELECTRIQ_12WMINV_HEATPUMP_PAYLOAD
  45. )
  46. self.subject = self.entities.get("climate")
  47. self.setUpTargetTemperature(
  48. TEMPERATURE_DPS,
  49. self.subject,
  50. min=16,
  51. max=32,
  52. )
  53. self.setUpBasicLight(LIGHT_DPS, self.entities.get("light_display"))
  54. self.setUpBasicSwitch(SWITCH_DPS, self.entities.get("switch_sleep"))
  55. self.mark_secondary(["light_display", "lock_child_lock"])
  56. def test_supported_features(self):
  57. self.assertEqual(
  58. self.subject.supported_features,
  59. SUPPORT_TARGET_TEMPERATURE | SUPPORT_FAN_MODE | SUPPORT_SWING_MODE,
  60. )
  61. def test_icon(self):
  62. self.dps[POWER_DPS] = True
  63. self.dps[HVACMODE_DPS] = "auto"
  64. self.assertEqual(self.subject.icon, "mdi:hvac")
  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] = "wet"
  70. self.assertEqual(self.subject.icon, "mdi:water")
  71. self.dps[HVACMODE_DPS] = "wind"
  72. self.assertEqual(self.subject.icon, "mdi:fan")
  73. self.dps[POWER_DPS] = False
  74. self.assertEqual(self.subject.icon, "mdi:hvac-off")
  75. def test_temperature_unit_returns_device_temperature_unit(self):
  76. self.assertEqual(
  77. self.subject.temperature_unit, self.subject._device.temperature_unit
  78. )
  79. def test_current_temperature(self):
  80. self.dps[CURRENTTEMP_DPS] = 25
  81. self.assertEqual(self.subject.current_temperature, 25)
  82. def test_hvac_mode(self):
  83. self.dps[POWER_DPS] = True
  84. self.dps[HVACMODE_DPS] = "hot"
  85. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_HEAT)
  86. self.dps[HVACMODE_DPS] = "cold"
  87. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_COOL)
  88. self.dps[HVACMODE_DPS] = "wet"
  89. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_DRY)
  90. self.dps[HVACMODE_DPS] = "wind"
  91. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_FAN_ONLY)
  92. self.dps[HVACMODE_DPS] = "auto"
  93. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_HEAT_COOL)
  94. self.dps[HVACMODE_DPS] = None
  95. self.assertEqual(self.subject.hvac_mode, STATE_UNAVAILABLE)
  96. self.dps[HVACMODE_DPS] = "auto"
  97. self.dps[POWER_DPS] = False
  98. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_OFF)
  99. def test_hvac_modes(self):
  100. self.assertCountEqual(
  101. self.subject.hvac_modes,
  102. [
  103. HVAC_MODE_OFF,
  104. HVAC_MODE_HEAT,
  105. HVAC_MODE_HEAT_COOL,
  106. HVAC_MODE_COOL,
  107. HVAC_MODE_DRY,
  108. HVAC_MODE_FAN_ONLY,
  109. ],
  110. )
  111. async def test_turn_on(self):
  112. async with assert_device_properties_set(
  113. self.subject._device, {POWER_DPS: True, HVACMODE_DPS: "hot"}
  114. ):
  115. await self.subject.async_set_hvac_mode(HVAC_MODE_HEAT)
  116. async def test_turn_off(self):
  117. async with assert_device_properties_set(
  118. self.subject._device, {POWER_DPS: False}
  119. ):
  120. await self.subject.async_set_hvac_mode(HVAC_MODE_OFF)
  121. def test_fan_mode(self):
  122. self.dps[FAN_DPS] = 1
  123. self.assertEqual(self.subject.fan_mode, "auto")
  124. self.dps[FAN_DPS] = 2
  125. self.assertEqual(self.subject.fan_mode, "Turbo")
  126. self.dps[FAN_DPS] = 3
  127. self.assertEqual(self.subject.fan_mode, "low")
  128. self.dps[FAN_DPS] = 4
  129. self.assertEqual(self.subject.fan_mode, "medium")
  130. self.dps[FAN_DPS] = 5
  131. self.assertEqual(self.subject.fan_mode, "high")
  132. def test_fan_mode_invalid_in_dry_hvac_mode(self):
  133. self.dps[HVACMODE_DPS] = "wet"
  134. self.dps[FAN_DPS] = 1
  135. self.assertIs(self.subject.fan_mode, None)
  136. def test_fan_modes(self):
  137. self.assertCountEqual(
  138. self.subject.fan_modes,
  139. [
  140. "auto",
  141. "Turbo",
  142. "low",
  143. "medium",
  144. "high",
  145. ],
  146. )
  147. async def test_set_fan_mode_to_auto(self):
  148. async with assert_device_properties_set(
  149. self.subject._device,
  150. {FAN_DPS: 1},
  151. ):
  152. await self.subject.async_set_fan_mode("auto")
  153. async def test_set_fan_mode_to_turbo(self):
  154. async with assert_device_properties_set(
  155. self.subject._device,
  156. {FAN_DPS: 2},
  157. ):
  158. await self.subject.async_set_fan_mode("Turbo")
  159. async def test_set_fan_mode_to_low(self):
  160. async with assert_device_properties_set(
  161. self.subject._device,
  162. {FAN_DPS: 3},
  163. ):
  164. await self.subject.async_set_fan_mode("low")
  165. async def test_set_fan_mode_to_medium(self):
  166. async with assert_device_properties_set(
  167. self.subject._device,
  168. {FAN_DPS: 4},
  169. ):
  170. await self.subject.async_set_fan_mode("medium")
  171. async def test_set_fan_mode_to_high(self):
  172. async with assert_device_properties_set(
  173. self.subject._device,
  174. {FAN_DPS: 5},
  175. ):
  176. await self.subject.async_set_fan_mode("high")
  177. def test_swing_modes(self):
  178. self.assertCountEqual(
  179. self.subject.swing_modes,
  180. ["off", "horizontal", "vertical", "both"],
  181. )
  182. def test_swing_mode(self):
  183. self.dps[VSWING_DPS] = False
  184. self.dps[HSWING_DPS] = False
  185. self.assertEqual(self.subject.swing_mode, "off")
  186. self.dps[VSWING_DPS] = True
  187. self.assertEqual(self.subject.swing_mode, "vertical")
  188. self.dps[HSWING_DPS] = True
  189. self.assertEqual(self.subject.swing_mode, "both")
  190. self.dps[VSWING_DPS] = False
  191. self.assertEqual(self.subject.swing_mode, "horizontal")
  192. async def test_set_swing_mode_to_both(self):
  193. async with assert_device_properties_set(
  194. self.subject._device,
  195. {HSWING_DPS: True, VSWING_DPS: True},
  196. ):
  197. await self.subject.async_set_swing_mode("both")
  198. async def test_set_swing_mode_to_horizontal(self):
  199. async with assert_device_properties_set(
  200. self.subject._device,
  201. {HSWING_DPS: True, VSWING_DPS: False},
  202. ):
  203. await self.subject.async_set_swing_mode("horizontal")
  204. async def test_set_swing_mode_to_off(self):
  205. async with assert_device_properties_set(
  206. self.subject._device,
  207. {HSWING_DPS: False, VSWING_DPS: False},
  208. ):
  209. await self.subject.async_set_swing_mode("off")
  210. async def test_set_swing_mode_to_vertical(self):
  211. async with assert_device_properties_set(
  212. self.subject._device,
  213. {HSWING_DPS: False, VSWING_DPS: True},
  214. ):
  215. await self.subject.async_set_swing_mode("vertical")
  216. def test_extra_state_attribures(self):
  217. self.dps[UNKNOWN8_DPS] = True
  218. self.dps[UNKNOWN12_DPS] = False
  219. self.dps[UNKNOWN102_DPS] = True
  220. self.dps[UNKNOWN103_DPS] = False
  221. self.dps[UNKNOWN108_DPS] = 108
  222. self.dps[UNKNOWN109_DPS] = 109
  223. self.dps[UNKNOWN110_DPS] = 110
  224. self.assertDictEqual(
  225. self.subject.extra_state_attributes,
  226. {
  227. "unknown_8": True,
  228. "unknown_12": False,
  229. "unknown_102": True,
  230. "unknown_103": False,
  231. "unknown_108": 108,
  232. "unknown_109": 109,
  233. "unknown_110": 110,
  234. },
  235. )
  236. def test_light_icon(self):
  237. self.dps[LIGHT_DPS] = True
  238. self.assertEqual(self.basicLight.icon, "mdi:led-on")
  239. self.dps[LIGHT_DPS] = False
  240. self.assertEqual(self.basicLight.icon, "mdi:led-off")
  241. def test_switch_icon(self):
  242. self.assertEqual(self.basicSwitch.icon, "mdi:power-sleep")