test_fersk_vind_2_climate.py 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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 ..mixins.climate import TargetTemperatureTests
  17. from .base_device_tests import TuyaDeviceTestCase
  18. POWER_DPS = "1"
  19. TEMPERATURE_DPS = "2"
  20. CURRENTTEMP_DPS = "3"
  21. HVACMODE_DPS = "4"
  22. FAN_DPS = "5"
  23. UNIT_DPS = "19"
  24. UNKNOWN101_DPS = "101"
  25. UNKNOWN102_DPS = "102"
  26. TIMER_DPS = "103"
  27. SWING_DPS = "104"
  28. COUNTDOWN_DPS = "105"
  29. UNKNOWN106_DPS = "106"
  30. UNKNOWN109_DPS = "109"
  31. UNKNOWN110_DPS = "110"
  32. class TestFerskVind2Climate(TargetTemperatureTests, TuyaDeviceTestCase):
  33. __test__ = True
  34. def setUp(self):
  35. self.setUpForConfig("fersk_vind_2_climate.yaml", FERSK_VIND2_PAYLOAD)
  36. self.subject = self.entities.get("climate")
  37. self.setUpTargetTemperature(
  38. TEMPERATURE_DPS,
  39. self.subject,
  40. min=16,
  41. max=32,
  42. )
  43. def test_supported_features(self):
  44. self.assertEqual(
  45. self.subject.supported_features,
  46. SUPPORT_TARGET_TEMPERATURE | SUPPORT_FAN_MODE | SUPPORT_SWING_MODE,
  47. )
  48. def test_icon(self):
  49. self.dps[POWER_DPS] = True
  50. self.dps[HVACMODE_DPS] = "COOL"
  51. self.assertEqual(self.subject.icon, "mdi:snowflake")
  52. self.dps[HVACMODE_DPS] = "FAN"
  53. self.assertEqual(self.subject.icon, "mdi:fan")
  54. self.dps[HVACMODE_DPS] = "DRY"
  55. self.assertEqual(self.subject.icon, "mdi:water")
  56. self.dps[HVACMODE_DPS] = "HEAT"
  57. self.assertEqual(self.subject.icon, "mdi:fire")
  58. self.dps[POWER_DPS] = False
  59. self.assertEqual(self.subject.icon, "mdi:hvac-off")
  60. def test_temperature_unit(self):
  61. self.dps[UNIT_DPS] = "C"
  62. self.assertEqual(self.subject.temperature_unit, TEMP_CELSIUS)
  63. self.dps[UNIT_DPS] = "F"
  64. self.assertEqual(self.subject.temperature_unit, TEMP_FAHRENHEIT)
  65. def test_minimum_target_temperature_f(self):
  66. self.dps[UNIT_DPS] = "F"
  67. self.assertEqual(self.subject.min_temp, 60)
  68. def test_maximum_target_temperature_f(self):
  69. self.dps[UNIT_DPS] = "F"
  70. self.assertEqual(self.subject.max_temp, 90)
  71. def test_current_temperature(self):
  72. self.dps[CURRENTTEMP_DPS] = 25
  73. self.assertEqual(self.subject.current_temperature, 25)
  74. def test_hvac_mode(self):
  75. self.dps[POWER_DPS] = True
  76. self.dps[HVACMODE_DPS] = "COOL"
  77. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_COOL)
  78. self.dps[HVACMODE_DPS] = "FAN"
  79. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_FAN_ONLY)
  80. self.dps[HVACMODE_DPS] = "DRY"
  81. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_DRY)
  82. self.dps[HVACMODE_DPS] = "HEAT"
  83. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_HEAT)
  84. self.dps[POWER_DPS] = False
  85. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_OFF)
  86. def test_hvac_modes(self):
  87. self.assertCountEqual(
  88. self.subject.hvac_modes,
  89. [
  90. HVAC_MODE_COOL,
  91. HVAC_MODE_DRY,
  92. HVAC_MODE_FAN_ONLY,
  93. HVAC_MODE_HEAT,
  94. HVAC_MODE_OFF,
  95. ],
  96. )
  97. async def test_set_hvac_mode_off(self):
  98. async with assert_device_properties_set(
  99. self.subject._device, {POWER_DPS: False}
  100. ):
  101. await self.subject.async_set_hvac_mode(HVAC_MODE_OFF)
  102. async def test_set_hvac_mode_cool(self):
  103. async with assert_device_properties_set(
  104. self.subject._device, {POWER_DPS: True, HVACMODE_DPS: "COOL"}
  105. ):
  106. await self.subject.async_set_hvac_mode(HVAC_MODE_COOL)
  107. async def test_set_hvac_mode_dry(self):
  108. async with assert_device_properties_set(
  109. self.subject._device, {POWER_DPS: True, HVACMODE_DPS: "DRY"}
  110. ):
  111. await self.subject.async_set_hvac_mode(HVAC_MODE_DRY)
  112. async def test_set_hvac_mode_fan(self):
  113. async with assert_device_properties_set(
  114. self.subject._device, {POWER_DPS: True, HVACMODE_DPS: "FAN"}
  115. ):
  116. await self.subject.async_set_hvac_mode(HVAC_MODE_FAN_ONLY)
  117. async def test_set_hvac_mode_heat(self):
  118. async with assert_device_properties_set(
  119. self.subject._device, {POWER_DPS: True, HVACMODE_DPS: "HEAT"}
  120. ):
  121. await self.subject.async_set_hvac_mode(HVAC_MODE_HEAT)
  122. def test_fan_mode(self):
  123. self.dps[FAN_DPS] = 1
  124. self.assertEqual(self.subject.fan_mode, "low")
  125. self.dps[FAN_DPS] = 2
  126. self.assertEqual(self.subject.fan_mode, "medium")
  127. self.dps[FAN_DPS] = 3
  128. self.assertEqual(self.subject.fan_mode, "high")
  129. def test_fan_modes(self):
  130. self.assertCountEqual(
  131. self.subject.fan_modes,
  132. ["low", "medium", "high"],
  133. )
  134. async def test_set_fan_mode_to_low(self):
  135. async with assert_device_properties_set(
  136. self.subject._device,
  137. {FAN_DPS: 1},
  138. ):
  139. await self.subject.async_set_fan_mode("low")
  140. async def test_set_fan_mode_to_medium(self):
  141. async with assert_device_properties_set(
  142. self.subject._device,
  143. {FAN_DPS: 2},
  144. ):
  145. await self.subject.async_set_fan_mode("medium")
  146. async def test_set_fan_mode_to_high(self):
  147. async with assert_device_properties_set(
  148. self.subject._device,
  149. {FAN_DPS: 3},
  150. ):
  151. await self.subject.async_set_fan_mode("high")
  152. def test_swing_modes(self):
  153. self.assertCountEqual(
  154. self.subject.swing_modes,
  155. [SWING_OFF, SWING_VERTICAL],
  156. )
  157. def test_swing_mode(self):
  158. self.dps[SWING_DPS] = False
  159. self.assertEqual(self.subject.swing_mode, SWING_OFF)
  160. self.dps[SWING_DPS] = True
  161. self.assertEqual(self.subject.swing_mode, SWING_VERTICAL)
  162. async def test_set_swing_mode_to_vertical(self):
  163. async with assert_device_properties_set(
  164. self.subject._device,
  165. {SWING_DPS: True},
  166. ):
  167. await self.subject.async_set_swing_mode(SWING_VERTICAL)
  168. async def test_set_swing_mode_to_off(self):
  169. async with assert_device_properties_set(
  170. self.subject._device,
  171. {SWING_DPS: False},
  172. ):
  173. await self.subject.async_set_swing_mode(SWING_OFF)
  174. def test_extra_state_attributes(self):
  175. self.dps[UNKNOWN101_DPS] = True
  176. self.dps[UNKNOWN102_DPS] = False
  177. self.dps[TIMER_DPS] = 103
  178. self.dps[COUNTDOWN_DPS] = 105
  179. self.dps[UNKNOWN106_DPS] = 106
  180. self.dps[UNKNOWN109_DPS] = True
  181. self.dps[UNKNOWN110_DPS] = 110
  182. self.assertDictEqual(
  183. self.subject.extra_state_attributes,
  184. {
  185. "unknown_101": True,
  186. "unknown_102": False,
  187. "timer": 103,
  188. "countdown": 105,
  189. "unknown_106": 106,
  190. "unknown_109": True,
  191. "unknown_110": 110,
  192. },
  193. )