test_carson_cb.py 8.2 KB

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