test_electriq_12wminv_heatpump.py 11 KB

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