test_fersk_vind_2_climate.py 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. from homeassistant.components.climate.const import (
  2. HVAC_MODE_COOL,
  3. HVAC_MODE_DRY,
  4. HVAC_MODE_FAN_ONLY,
  5. HVAC_MODE_HEAT,
  6. HVAC_MODE_OFF,
  7. SUPPORT_FAN_MODE,
  8. SUPPORT_SWING_MODE,
  9. SUPPORT_TARGET_TEMPERATURE,
  10. SWING_OFF,
  11. SWING_VERTICAL,
  12. )
  13. from homeassistant.const import STATE_UNAVAILABLE, TEMP_CELSIUS, TEMP_FAHRENHEIT
  14. from ..const import FERSK_VIND2_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. UNIT_DPS = "19"
  23. UNKNOWN101_DPS = "101"
  24. UNKNOWN102_DPS = "102"
  25. TIMER_DPS = "103"
  26. SWING_DPS = "104"
  27. COUNTDOWN_DPS = "105"
  28. UNKNOWN106_DPS = "106"
  29. UNKNOWN109_DPS = "109"
  30. UNKNOWN110_DPS = "110"
  31. class TestFerskVind2Climate(TuyaDeviceTestCase):
  32. __test__ = True
  33. def setUp(self):
  34. self.setUpForConfig("fersk_vind_2_climate.yaml", FERSK_VIND2_PAYLOAD)
  35. self.subject = self.entities.get("climate")
  36. def test_supported_features(self):
  37. self.assertEqual(
  38. self.subject.supported_features,
  39. SUPPORT_TARGET_TEMPERATURE | SUPPORT_FAN_MODE | SUPPORT_SWING_MODE,
  40. )
  41. def test_icon(self):
  42. self.dps[POWER_DPS] = True
  43. self.dps[HVACMODE_DPS] = "COOL"
  44. self.assertEqual(self.subject.icon, "mdi:snowflake")
  45. self.dps[HVACMODE_DPS] = "FAN"
  46. self.assertEqual(self.subject.icon, "mdi:fan")
  47. self.dps[HVACMODE_DPS] = "DRY"
  48. self.assertEqual(self.subject.icon, "mdi:water")
  49. self.dps[HVACMODE_DPS] = "HEAT"
  50. self.assertEqual(self.subject.icon, "mdi:fire")
  51. self.dps[POWER_DPS] = False
  52. self.assertEqual(self.subject.icon, "mdi:hvac-off")
  53. def test_temperature_unit(self):
  54. self.dps[UNIT_DPS] = "C"
  55. self.assertEqual(self.subject.temperature_unit, TEMP_CELSIUS)
  56. self.dps[UNIT_DPS] = "F"
  57. self.assertEqual(self.subject.temperature_unit, TEMP_FAHRENHEIT)
  58. def test_target_temperature(self):
  59. self.dps[TEMPERATURE_DPS] = 25
  60. self.assertEqual(self.subject.target_temperature, 25)
  61. def test_target_temperature_step(self):
  62. self.assertEqual(self.subject.target_temperature_step, 1)
  63. def test_minimum_target_temperature(self):
  64. self.dps[UNIT_DPS] = "C"
  65. self.assertEqual(self.subject.min_temp, 16)
  66. self.dps[UNIT_DPS] = "F"
  67. self.assertEqual(self.subject.min_temp, 60)
  68. def test_maximum_target_temperature(self):
  69. self.dps[UNIT_DPS] = "C"
  70. self.assertEqual(self.subject.max_temp, 32)
  71. self.dps[UNIT_DPS] = "F"
  72. self.assertEqual(self.subject.max_temp, 90)
  73. async def test_legacy_set_temperature_with_temperature(self):
  74. self.dps[UNIT_DPS] = "C"
  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_set_target_temperature_succeeds_within_valid_range(self):
  80. self.dps[UNIT_DPS] = "C"
  81. async with assert_device_properties_set(
  82. self.subject._device, {TEMPERATURE_DPS: 24}
  83. ):
  84. await self.subject.async_set_target_temperature(24)
  85. self.dps[UNIT_DPS] = "F"
  86. async with assert_device_properties_set(
  87. self.subject._device, {TEMPERATURE_DPS: 80}
  88. ):
  89. await self.subject.async_set_target_temperature(80)
  90. async def test_set_target_temperature_fails_outside_valid_range(self):
  91. self.dps[UNIT_DPS] = "C"
  92. with self.assertRaisesRegex(
  93. ValueError, "temperature \\(15\\) must be between 16 and 32"
  94. ):
  95. await self.subject.async_set_target_temperature(15)
  96. with self.assertRaisesRegex(
  97. ValueError, "temperature \\(33\\) must be between 16 and 32"
  98. ):
  99. await self.subject.async_set_target_temperature(33)
  100. self.dps[UNIT_DPS] = "F"
  101. with self.assertRaisesRegex(
  102. ValueError, "temperature \\(59\\) must be between 60 and 90"
  103. ):
  104. await self.subject.async_set_target_temperature(59)
  105. with self.assertRaisesRegex(
  106. ValueError, "temperature \\(91\\) must be between 60 and 90"
  107. ):
  108. await self.subject.async_set_target_temperature(91)
  109. def test_current_temperature(self):
  110. self.dps[CURRENTTEMP_DPS] = 25
  111. self.assertEqual(self.subject.current_temperature, 25)
  112. def test_hvac_mode(self):
  113. self.dps[POWER_DPS] = True
  114. self.dps[HVACMODE_DPS] = "COOL"
  115. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_COOL)
  116. self.dps[HVACMODE_DPS] = "FAN"
  117. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_FAN_ONLY)
  118. self.dps[HVACMODE_DPS] = "DRY"
  119. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_DRY)
  120. self.dps[HVACMODE_DPS] = "HEAT"
  121. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_HEAT)
  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_COOL,
  129. HVAC_MODE_DRY,
  130. HVAC_MODE_FAN_ONLY,
  131. HVAC_MODE_HEAT,
  132. HVAC_MODE_OFF,
  133. ],
  134. )
  135. async def test_set_hvac_mode_off(self):
  136. async with assert_device_properties_set(
  137. self.subject._device, {POWER_DPS: False}
  138. ):
  139. await self.subject.async_set_hvac_mode(HVAC_MODE_OFF)
  140. async def test_set_hvac_mode_cool(self):
  141. async with assert_device_properties_set(
  142. self.subject._device, {POWER_DPS: True, HVACMODE_DPS: "COOL"}
  143. ):
  144. await self.subject.async_set_hvac_mode(HVAC_MODE_COOL)
  145. async def test_set_hvac_mode_dry(self):
  146. async with assert_device_properties_set(
  147. self.subject._device, {POWER_DPS: True, HVACMODE_DPS: "DRY"}
  148. ):
  149. await self.subject.async_set_hvac_mode(HVAC_MODE_DRY)
  150. async def test_set_hvac_mode_fan(self):
  151. async with assert_device_properties_set(
  152. self.subject._device, {POWER_DPS: True, HVACMODE_DPS: "FAN"}
  153. ):
  154. await self.subject.async_set_hvac_mode(HVAC_MODE_FAN_ONLY)
  155. async def test_set_hvac_mode_heat(self):
  156. async with assert_device_properties_set(
  157. self.subject._device, {POWER_DPS: True, HVACMODE_DPS: "HEAT"}
  158. ):
  159. await self.subject.async_set_hvac_mode(HVAC_MODE_HEAT)
  160. def test_fan_mode(self):
  161. self.dps[FAN_DPS] = 1
  162. self.assertEqual(self.subject.fan_mode, "low")
  163. self.dps[FAN_DPS] = 2
  164. self.assertEqual(self.subject.fan_mode, "medium")
  165. self.dps[FAN_DPS] = 3
  166. self.assertEqual(self.subject.fan_mode, "high")
  167. def test_fan_modes(self):
  168. self.assertCountEqual(
  169. self.subject.fan_modes,
  170. ["low", "medium", "high"],
  171. )
  172. async def test_set_fan_mode_to_low(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("low")
  178. async def test_set_fan_mode_to_medium(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("medium")
  184. async def test_set_fan_mode_to_high(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("high")
  190. def test_swing_modes(self):
  191. self.assertCountEqual(
  192. self.subject.swing_modes,
  193. [SWING_OFF, SWING_VERTICAL],
  194. )
  195. def test_swing_mode(self):
  196. self.dps[SWING_DPS] = False
  197. self.assertEqual(self.subject.swing_mode, SWING_OFF)
  198. self.dps[SWING_DPS] = True
  199. self.assertEqual(self.subject.swing_mode, SWING_VERTICAL)
  200. async def test_set_swing_mode_to_vertical(self):
  201. async with assert_device_properties_set(
  202. self.subject._device,
  203. {SWING_DPS: True},
  204. ):
  205. await self.subject.async_set_swing_mode(SWING_VERTICAL)
  206. async def test_set_swing_mode_to_off(self):
  207. async with assert_device_properties_set(
  208. self.subject._device,
  209. {SWING_DPS: False},
  210. ):
  211. await self.subject.async_set_swing_mode(SWING_OFF)
  212. def test_device_state_attribures(self):
  213. self.dps[UNKNOWN101_DPS] = True
  214. self.dps[UNKNOWN102_DPS] = False
  215. self.dps[TIMER_DPS] = 103
  216. self.dps[COUNTDOWN_DPS] = 105
  217. self.dps[UNKNOWN106_DPS] = 106
  218. self.dps[UNKNOWN109_DPS] = True
  219. self.dps[UNKNOWN110_DPS] = 110
  220. self.assertDictEqual(
  221. self.subject.device_state_attributes,
  222. {
  223. "unknown_101": True,
  224. "unknown_102": False,
  225. "timer": 103,
  226. "countdown": 105,
  227. "unknown_106": 106,
  228. "unknown_109": True,
  229. "unknown_110": 110,
  230. },
  231. )