test_electriq_12wminv_heatpump.py 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  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. def test_supported_features(self):
  56. self.assertEqual(
  57. self.subject.supported_features,
  58. SUPPORT_TARGET_TEMPERATURE | SUPPORT_FAN_MODE | SUPPORT_SWING_MODE,
  59. )
  60. def test_icon(self):
  61. self.dps[POWER_DPS] = True
  62. self.dps[HVACMODE_DPS] = "auto"
  63. self.assertEqual(self.subject.icon, "mdi:hvac")
  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] = "wet"
  69. self.assertEqual(self.subject.icon, "mdi:water")
  70. self.dps[HVACMODE_DPS] = "wind"
  71. self.assertEqual(self.subject.icon, "mdi:fan")
  72. self.dps[POWER_DPS] = False
  73. self.assertEqual(self.subject.icon, "mdi:hvac-off")
  74. def test_temperature_unit_returns_device_temperature_unit(self):
  75. self.assertEqual(
  76. self.subject.temperature_unit, self.subject._device.temperature_unit
  77. )
  78. def test_current_temperature(self):
  79. self.dps[CURRENTTEMP_DPS] = 25
  80. self.assertEqual(self.subject.current_temperature, 25)
  81. def test_hvac_mode(self):
  82. self.dps[POWER_DPS] = True
  83. self.dps[HVACMODE_DPS] = "hot"
  84. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_HEAT)
  85. self.dps[HVACMODE_DPS] = "cold"
  86. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_COOL)
  87. self.dps[HVACMODE_DPS] = "wet"
  88. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_DRY)
  89. self.dps[HVACMODE_DPS] = "wind"
  90. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_FAN_ONLY)
  91. self.dps[HVACMODE_DPS] = "auto"
  92. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_HEAT_COOL)
  93. self.dps[HVACMODE_DPS] = None
  94. self.assertEqual(self.subject.hvac_mode, STATE_UNAVAILABLE)
  95. self.dps[HVACMODE_DPS] = "auto"
  96. self.dps[POWER_DPS] = False
  97. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_OFF)
  98. def test_hvac_modes(self):
  99. self.assertCountEqual(
  100. self.subject.hvac_modes,
  101. [
  102. HVAC_MODE_OFF,
  103. HVAC_MODE_HEAT,
  104. HVAC_MODE_HEAT_COOL,
  105. HVAC_MODE_COOL,
  106. HVAC_MODE_DRY,
  107. HVAC_MODE_FAN_ONLY,
  108. ],
  109. )
  110. async def test_turn_on(self):
  111. async with assert_device_properties_set(
  112. self.subject._device, {POWER_DPS: True, HVACMODE_DPS: "hot"}
  113. ):
  114. await self.subject.async_set_hvac_mode(HVAC_MODE_HEAT)
  115. async def test_turn_off(self):
  116. async with assert_device_properties_set(
  117. self.subject._device, {POWER_DPS: False}
  118. ):
  119. await self.subject.async_set_hvac_mode(HVAC_MODE_OFF)
  120. def test_fan_mode(self):
  121. self.dps[FAN_DPS] = 1
  122. self.assertEqual(self.subject.fan_mode, "auto")
  123. self.dps[FAN_DPS] = 2
  124. self.assertEqual(self.subject.fan_mode, "Turbo")
  125. self.dps[FAN_DPS] = 3
  126. self.assertEqual(self.subject.fan_mode, "low")
  127. self.dps[FAN_DPS] = 4
  128. self.assertEqual(self.subject.fan_mode, "medium")
  129. self.dps[FAN_DPS] = 5
  130. self.assertEqual(self.subject.fan_mode, "high")
  131. def test_fan_mode_invalid_in_dry_hvac_mode(self):
  132. self.dps[HVACMODE_DPS] = "wet"
  133. self.dps[FAN_DPS] = 1
  134. self.assertIs(self.subject.fan_mode, None)
  135. def test_fan_modes(self):
  136. self.assertCountEqual(
  137. self.subject.fan_modes,
  138. [
  139. "auto",
  140. "Turbo",
  141. "low",
  142. "medium",
  143. "high",
  144. ],
  145. )
  146. async def test_set_fan_mode_to_auto(self):
  147. async with assert_device_properties_set(
  148. self.subject._device,
  149. {FAN_DPS: 1},
  150. ):
  151. await self.subject.async_set_fan_mode("auto")
  152. async def test_set_fan_mode_to_turbo(self):
  153. async with assert_device_properties_set(
  154. self.subject._device,
  155. {FAN_DPS: 2},
  156. ):
  157. await self.subject.async_set_fan_mode("Turbo")
  158. async def test_set_fan_mode_to_low(self):
  159. async with assert_device_properties_set(
  160. self.subject._device,
  161. {FAN_DPS: 3},
  162. ):
  163. await self.subject.async_set_fan_mode("low")
  164. async def test_set_fan_mode_to_medium(self):
  165. async with assert_device_properties_set(
  166. self.subject._device,
  167. {FAN_DPS: 4},
  168. ):
  169. await self.subject.async_set_fan_mode("medium")
  170. async def test_set_fan_mode_to_high(self):
  171. async with assert_device_properties_set(
  172. self.subject._device,
  173. {FAN_DPS: 5},
  174. ):
  175. await self.subject.async_set_fan_mode("high")
  176. def test_swing_modes(self):
  177. self.assertCountEqual(
  178. self.subject.swing_modes,
  179. ["off", "horizontal", "vertical", "both"],
  180. )
  181. def test_swing_mode(self):
  182. self.dps[VSWING_DPS] = False
  183. self.dps[HSWING_DPS] = False
  184. self.assertEqual(self.subject.swing_mode, "off")
  185. self.dps[VSWING_DPS] = True
  186. self.assertEqual(self.subject.swing_mode, "vertical")
  187. self.dps[HSWING_DPS] = True
  188. self.assertEqual(self.subject.swing_mode, "both")
  189. self.dps[VSWING_DPS] = False
  190. self.assertEqual(self.subject.swing_mode, "horizontal")
  191. async def test_set_swing_mode_to_both(self):
  192. async with assert_device_properties_set(
  193. self.subject._device,
  194. {HSWING_DPS: True, VSWING_DPS: True},
  195. ):
  196. await self.subject.async_set_swing_mode("both")
  197. async def test_set_swing_mode_to_horizontal(self):
  198. async with assert_device_properties_set(
  199. self.subject._device,
  200. {HSWING_DPS: True, VSWING_DPS: False},
  201. ):
  202. await self.subject.async_set_swing_mode("horizontal")
  203. async def test_set_swing_mode_to_off(self):
  204. async with assert_device_properties_set(
  205. self.subject._device,
  206. {HSWING_DPS: False, VSWING_DPS: False},
  207. ):
  208. await self.subject.async_set_swing_mode("off")
  209. async def test_set_swing_mode_to_vertical(self):
  210. async with assert_device_properties_set(
  211. self.subject._device,
  212. {HSWING_DPS: False, VSWING_DPS: True},
  213. ):
  214. await self.subject.async_set_swing_mode("vertical")
  215. def test_device_state_attribures(self):
  216. self.dps[UNKNOWN8_DPS] = True
  217. self.dps[UNKNOWN12_DPS] = False
  218. self.dps[UNKNOWN102_DPS] = True
  219. self.dps[UNKNOWN103_DPS] = False
  220. self.dps[UNKNOWN108_DPS] = 108
  221. self.dps[UNKNOWN109_DPS] = 109
  222. self.dps[UNKNOWN110_DPS] = 110
  223. self.assertDictEqual(
  224. self.subject.device_state_attributes,
  225. {
  226. "unknown_8": True,
  227. "unknown_12": False,
  228. "unknown_102": True,
  229. "unknown_103": False,
  230. "unknown_108": 108,
  231. "unknown_109": 109,
  232. "unknown_110": 110,
  233. },
  234. )
  235. def test_light_icon(self):
  236. self.dps[LIGHT_DPS] = True
  237. self.assertEqual(self.basicLight.icon, "mdi:led-on")
  238. self.dps[LIGHT_DPS] = False
  239. self.assertEqual(self.basicLight.icon, "mdi:led-off")
  240. def test_switch_icon(self):
  241. self.assertEqual(self.basicSwitch.icon, "mdi:power-sleep")