test_fersk_vind_2_climate.py 7.4 KB

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