test_electriq_12wminv_heatpump.py 13 KB

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