test_fersk_vind_2_climate.py 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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.0,
  35. max=32.0,
  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. | ClimateEntityFeature.TURN_OFF
  45. | ClimateEntityFeature.TURN_ON
  46. ),
  47. )
  48. def test_temperature_unit(self):
  49. self.dps[UNIT_DPS] = "C"
  50. self.assertEqual(self.subject.temperature_unit, UnitOfTemperature.CELSIUS)
  51. self.dps[UNIT_DPS] = "F"
  52. self.assertEqual(self.subject.temperature_unit, UnitOfTemperature.FAHRENHEIT)
  53. def test_minimum_target_temperature_f(self):
  54. self.dps[UNIT_DPS] = "F"
  55. self.assertEqual(self.subject.min_temp, 60)
  56. def test_maximum_target_temperature_f(self):
  57. self.dps[UNIT_DPS] = "F"
  58. self.assertEqual(self.subject.max_temp, 90)
  59. def test_current_temperature(self):
  60. self.dps[CURRENTTEMP_DPS] = 25
  61. self.assertEqual(self.subject.current_temperature, 25)
  62. def test_hvac_mode(self):
  63. self.dps[POWER_DPS] = True
  64. self.dps[HVACMODE_DPS] = "COOL"
  65. self.assertEqual(self.subject.hvac_mode, HVACMode.COOL)
  66. self.dps[HVACMODE_DPS] = "FAN"
  67. self.assertEqual(self.subject.hvac_mode, HVACMode.FAN_ONLY)
  68. self.dps[HVACMODE_DPS] = "DRY"
  69. self.assertEqual(self.subject.hvac_mode, HVACMode.DRY)
  70. self.dps[HVACMODE_DPS] = "HEAT"
  71. self.assertEqual(self.subject.hvac_mode, HVACMode.HEAT)
  72. self.dps[POWER_DPS] = False
  73. self.assertEqual(self.subject.hvac_mode, HVACMode.OFF)
  74. def test_hvac_modes(self):
  75. self.assertCountEqual(
  76. self.subject.hvac_modes,
  77. [
  78. HVACMode.COOL,
  79. HVACMode.DRY,
  80. HVACMode.FAN_ONLY,
  81. HVACMode.HEAT,
  82. HVACMode.OFF,
  83. ],
  84. )
  85. async def test_set_hvac_mode_off(self):
  86. async with assert_device_properties_set(
  87. self.subject._device, {POWER_DPS: False}
  88. ):
  89. await self.subject.async_set_hvac_mode(HVACMode.OFF)
  90. async def test_set_hvac_mode_cool(self):
  91. async with assert_device_properties_set(
  92. self.subject._device, {POWER_DPS: True, HVACMODE_DPS: "COOL"}
  93. ):
  94. await self.subject.async_set_hvac_mode(HVACMode.COOL)
  95. async def test_set_hvac_mode_dry(self):
  96. async with assert_device_properties_set(
  97. self.subject._device, {POWER_DPS: True, HVACMODE_DPS: "DRY"}
  98. ):
  99. await self.subject.async_set_hvac_mode(HVACMode.DRY)
  100. async def test_set_hvac_mode_fan(self):
  101. async with assert_device_properties_set(
  102. self.subject._device, {POWER_DPS: True, HVACMODE_DPS: "FAN"}
  103. ):
  104. await self.subject.async_set_hvac_mode(HVACMode.FAN_ONLY)
  105. async def test_set_hvac_mode_heat(self):
  106. async with assert_device_properties_set(
  107. self.subject._device, {POWER_DPS: True, HVACMODE_DPS: "HEAT"}
  108. ):
  109. await self.subject.async_set_hvac_mode(HVACMode.HEAT)
  110. def test_fan_mode(self):
  111. self.dps[FAN_DPS] = 1
  112. self.assertEqual(self.subject.fan_mode, "low")
  113. self.dps[FAN_DPS] = 2
  114. self.assertEqual(self.subject.fan_mode, "medium")
  115. self.dps[FAN_DPS] = 3
  116. self.assertEqual(self.subject.fan_mode, "high")
  117. def test_fan_modes(self):
  118. self.assertCountEqual(
  119. self.subject.fan_modes,
  120. ["low", "medium", "high"],
  121. )
  122. async def test_set_fan_mode_to_low(self):
  123. async with assert_device_properties_set(
  124. self.subject._device,
  125. {FAN_DPS: 1},
  126. ):
  127. await self.subject.async_set_fan_mode("low")
  128. async def test_set_fan_mode_to_medium(self):
  129. async with assert_device_properties_set(
  130. self.subject._device,
  131. {FAN_DPS: 2},
  132. ):
  133. await self.subject.async_set_fan_mode("medium")
  134. async def test_set_fan_mode_to_high(self):
  135. async with assert_device_properties_set(
  136. self.subject._device,
  137. {FAN_DPS: 3},
  138. ):
  139. await self.subject.async_set_fan_mode("high")
  140. def test_swing_modes(self):
  141. self.assertCountEqual(
  142. self.subject.swing_modes,
  143. [SWING_OFF, SWING_VERTICAL],
  144. )
  145. def test_swing_mode(self):
  146. self.dps[SWING_DPS] = False
  147. self.assertEqual(self.subject.swing_mode, SWING_OFF)
  148. self.dps[SWING_DPS] = True
  149. self.assertEqual(self.subject.swing_mode, SWING_VERTICAL)
  150. async def test_set_swing_mode_to_vertical(self):
  151. async with assert_device_properties_set(
  152. self.subject._device,
  153. {SWING_DPS: True},
  154. ):
  155. await self.subject.async_set_swing_mode(SWING_VERTICAL)
  156. async def test_set_swing_mode_to_off(self):
  157. async with assert_device_properties_set(
  158. self.subject._device,
  159. {SWING_DPS: False},
  160. ):
  161. await self.subject.async_set_swing_mode(SWING_OFF)
  162. def test_extra_state_attributes(self):
  163. self.dps[UNKNOWN101_DPS] = True
  164. self.dps[UNKNOWN102_DPS] = False
  165. self.dps[TIMER_DPS] = 103
  166. self.dps[COUNTDOWN_DPS] = 105
  167. self.dps[UNKNOWN106_DPS] = 106
  168. self.dps[UNKNOWN109_DPS] = True
  169. self.dps[UNKNOWN110_DPS] = 110
  170. self.assertDictEqual(
  171. self.subject.extra_state_attributes,
  172. {
  173. "unknown_101": True,
  174. "unknown_102": False,
  175. "timer": 103,
  176. "countdown": 105,
  177. "unknown_106": 106,
  178. "unknown_109": True,
  179. "unknown_110": 110,
  180. },
  181. )