test_carson_cb.py 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  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. )
  11. from homeassistant.const import STATE_UNAVAILABLE, TEMP_CELSIUS, TEMP_FAHRENHEIT
  12. from ..const import CARSON_CB_PAYLOAD
  13. from ..helpers import assert_device_properties_set
  14. from .base_device_tests import TuyaDeviceTestCase
  15. POWER_DPS = "1"
  16. TEMPERATURE_DPS = "2"
  17. CURRENTTEMP_DPS = "3"
  18. HVACMODE_DPS = "4"
  19. FAN_DPS = "5"
  20. UNIT_DPS = "19"
  21. UNKNOWN102_DPS = "102"
  22. TIMER_DPS = "103"
  23. SWING_DPS = "104"
  24. COUNTDOWN_DPS = "105"
  25. UNKNOWN106_DPS = "106"
  26. UNKNOWN110_DPS = "110"
  27. class TestCarsonCBHeatpump(TuyaDeviceTestCase):
  28. __test__ = True
  29. def setUp(self):
  30. self.setUpForConfig("carson_cb.yaml", CARSON_CB_PAYLOAD)
  31. self.subject = self.entities.get("climate")
  32. def test_supported_features(self):
  33. self.assertEqual(
  34. self.subject.supported_features,
  35. SUPPORT_TARGET_TEMPERATURE | SUPPORT_FAN_MODE | SUPPORT_SWING_MODE,
  36. )
  37. def test_icon(self):
  38. self.dps[POWER_DPS] = True
  39. self.dps[HVACMODE_DPS] = "COOL"
  40. self.assertEqual(self.subject.icon, "mdi:snowflake")
  41. self.dps[HVACMODE_DPS] = "HEAT"
  42. self.assertEqual(self.subject.icon, "mdi:fire")
  43. self.dps[HVACMODE_DPS] = "DRY"
  44. self.assertEqual(self.subject.icon, "mdi:water")
  45. self.dps[HVACMODE_DPS] = "FAN"
  46. self.assertEqual(self.subject.icon, "mdi:fan")
  47. self.dps[POWER_DPS] = False
  48. self.assertEqual(self.subject.icon, "mdi:hvac-off")
  49. def test_temperature_unit(self):
  50. self.dps[UNIT_DPS] = "C"
  51. self.assertEqual(self.subject.temperature_unit, TEMP_CELSIUS)
  52. self.dps[UNIT_DPS] = "F"
  53. self.assertEqual(self.subject.temperature_unit, TEMP_FAHRENHEIT)
  54. def test_target_temperature(self):
  55. self.dps[TEMPERATURE_DPS] = 25
  56. self.assertEqual(self.subject.target_temperature, 25)
  57. def test_target_temperature_step(self):
  58. self.assertEqual(self.subject.target_temperature_step, 1)
  59. def test_minimum_target_temperature(self):
  60. self.assertEqual(self.subject.min_temp, 16)
  61. def test_maximum_target_temperature(self):
  62. self.assertEqual(self.subject.max_temp, 30)
  63. async def test_legacy_set_temperature_with_temperature(self):
  64. async with assert_device_properties_set(
  65. self.subject._device, {TEMPERATURE_DPS: 24}
  66. ):
  67. await self.subject.async_set_temperature(temperature=24)
  68. async def test_legacy_set_temperature_with_no_valid_properties(self):
  69. await self.subject.async_set_temperature(something="else")
  70. self.subject._device.async_set_property.assert_not_called()
  71. async def test_set_target_temperature_succeeds_within_valid_range(self):
  72. async with assert_device_properties_set(
  73. self.subject._device,
  74. {TEMPERATURE_DPS: 25},
  75. ):
  76. await self.subject.async_set_target_temperature(25)
  77. async def test_set_target_temperature_rounds_value_to_closest_integer(self):
  78. async with assert_device_properties_set(
  79. self.subject._device, {TEMPERATURE_DPS: 23}
  80. ):
  81. await self.subject.async_set_target_temperature(22.6)
  82. async def test_set_target_temperature_fails_outside_valid_range(self):
  83. with self.assertRaisesRegex(
  84. ValueError, "temperature \\(15\\) must be between 16 and 30"
  85. ):
  86. await self.subject.async_set_target_temperature(15)
  87. with self.assertRaisesRegex(
  88. ValueError, "temperature \\(31\\) must be between 16 and 30"
  89. ):
  90. await self.subject.async_set_target_temperature(31)
  91. def test_current_temperature(self):
  92. self.dps[CURRENTTEMP_DPS] = 25
  93. self.assertEqual(self.subject.current_temperature, 25)
  94. def test_hvac_mode(self):
  95. self.dps[POWER_DPS] = True
  96. self.dps[HVACMODE_DPS] = "HEAT"
  97. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_HEAT)
  98. self.dps[HVACMODE_DPS] = "COOL"
  99. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_COOL)
  100. self.dps[HVACMODE_DPS] = "DRY"
  101. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_DRY)
  102. self.dps[HVACMODE_DPS] = "FAN"
  103. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_FAN_ONLY)
  104. self.dps[HVACMODE_DPS] = None
  105. self.assertEqual(self.subject.hvac_mode, STATE_UNAVAILABLE)
  106. self.dps[HVACMODE_DPS] = "DRY"
  107. self.dps[POWER_DPS] = False
  108. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_OFF)
  109. def test_hvac_modes(self):
  110. self.assertCountEqual(
  111. self.subject.hvac_modes,
  112. [
  113. HVAC_MODE_OFF,
  114. HVAC_MODE_HEAT,
  115. HVAC_MODE_COOL,
  116. HVAC_MODE_DRY,
  117. HVAC_MODE_FAN_ONLY,
  118. ],
  119. )
  120. async def test_turn_on(self):
  121. async with assert_device_properties_set(
  122. self.subject._device, {POWER_DPS: True, HVACMODE_DPS: "HEAT"}
  123. ):
  124. await self.subject.async_set_hvac_mode(HVAC_MODE_HEAT)
  125. async def test_turn_off(self):
  126. async with assert_device_properties_set(
  127. self.subject._device, {POWER_DPS: False}
  128. ):
  129. await self.subject.async_set_hvac_mode(HVAC_MODE_OFF)
  130. def test_fan_mode(self):
  131. self.dps[FAN_DPS] = 1
  132. self.assertEqual(self.subject.fan_mode, "low")
  133. self.dps[FAN_DPS] = 2
  134. self.assertEqual(self.subject.fan_mode, "medium")
  135. self.dps[FAN_DPS] = 3
  136. self.assertEqual(self.subject.fan_mode, "high")
  137. def test_fan_modes(self):
  138. self.assertCountEqual(
  139. self.subject.fan_modes,
  140. [
  141. "low",
  142. "medium",
  143. "high",
  144. ],
  145. )
  146. async def test_set_fan_mode_to_low(self):
  147. async with assert_device_properties_set(
  148. self.subject._device,
  149. {FAN_DPS: 1},
  150. ):
  151. await self.subject.async_set_fan_mode("low")
  152. async def test_set_fan_mode_to_medium(self):
  153. async with assert_device_properties_set(
  154. self.subject._device,
  155. {FAN_DPS: 2},
  156. ):
  157. await self.subject.async_set_fan_mode("medium")
  158. async def test_set_fan_mode_to_high(self):
  159. async with assert_device_properties_set(
  160. self.subject._device,
  161. {FAN_DPS: 3},
  162. ):
  163. await self.subject.async_set_fan_mode("high")
  164. def test_swing_modes(self):
  165. self.assertCountEqual(
  166. self.subject.swing_modes,
  167. ["off", "vertical"],
  168. )
  169. def test_swing_mode(self):
  170. self.dps[SWING_DPS] = False
  171. self.assertEqual(self.subject.swing_mode, "off")
  172. self.dps[SWING_DPS] = True
  173. self.assertEqual(self.subject.swing_mode, "vertical")
  174. async def test_set_swing_mode_to_off(self):
  175. async with assert_device_properties_set(
  176. self.subject._device,
  177. {SWING_DPS: False},
  178. ):
  179. await self.subject.async_set_swing_mode("off")
  180. async def test_set_swing_mode_to_vertical(self):
  181. async with assert_device_properties_set(
  182. self.subject._device,
  183. {SWING_DPS: True},
  184. ):
  185. await self.subject.async_set_swing_mode("vertical")
  186. def test_device_state_attribures(self):
  187. self.dps[UNKNOWN102_DPS] = True
  188. self.dps[TIMER_DPS] = 103
  189. self.dps[COUNTDOWN_DPS] = 105
  190. self.dps[UNKNOWN106_DPS] = 106
  191. self.dps[UNKNOWN110_DPS] = 110
  192. self.assertDictEqual(
  193. self.subject.device_state_attributes,
  194. {
  195. "unknown_102": True,
  196. "timer": 103,
  197. "countdown": 105,
  198. "unknown_106": 106,
  199. "unknown_110": 110,
  200. },
  201. )