test_electriq_12wminv_heatpump.py 13 KB

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