test_electriq_12wminv_heatpump.py 9.0 KB

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