4
0

test_electriq_12wminv_heatpump.py 9.0 KB

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