test_carson_cb.py 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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 ..mixins.climate import TargetTemperatureTests
  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(TargetTemperatureTests, 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.setUpTargetTemperature(
  34. TEMPERATURE_DPS,
  35. self.subject,
  36. min=16,
  37. max=30,
  38. )
  39. def test_supported_features(self):
  40. self.assertEqual(
  41. self.subject.supported_features,
  42. SUPPORT_TARGET_TEMPERATURE | SUPPORT_FAN_MODE | SUPPORT_SWING_MODE,
  43. )
  44. def test_icon(self):
  45. self.dps[POWER_DPS] = True
  46. self.dps[HVACMODE_DPS] = "COOL"
  47. self.assertEqual(self.subject.icon, "mdi:snowflake")
  48. self.dps[HVACMODE_DPS] = "HEAT"
  49. self.assertEqual(self.subject.icon, "mdi:fire")
  50. self.dps[HVACMODE_DPS] = "DRY"
  51. self.assertEqual(self.subject.icon, "mdi:water")
  52. self.dps[HVACMODE_DPS] = "FAN"
  53. self.assertEqual(self.subject.icon, "mdi:fan")
  54. self.dps[POWER_DPS] = False
  55. self.assertEqual(self.subject.icon, "mdi:hvac-off")
  56. def test_temperature_unit(self):
  57. self.dps[UNIT_DPS] = "C"
  58. self.assertEqual(self.subject.temperature_unit, TEMP_CELSIUS)
  59. self.dps[UNIT_DPS] = "F"
  60. self.assertEqual(self.subject.temperature_unit, TEMP_FAHRENHEIT)
  61. def test_current_temperature(self):
  62. self.dps[CURRENTTEMP_DPS] = 25
  63. self.assertEqual(self.subject.current_temperature, 25)
  64. def test_hvac_mode(self):
  65. self.dps[POWER_DPS] = True
  66. self.dps[HVACMODE_DPS] = "HEAT"
  67. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_HEAT)
  68. self.dps[HVACMODE_DPS] = "COOL"
  69. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_COOL)
  70. self.dps[HVACMODE_DPS] = "DRY"
  71. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_DRY)
  72. self.dps[HVACMODE_DPS] = "FAN"
  73. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_FAN_ONLY)
  74. self.dps[HVACMODE_DPS] = None
  75. self.assertEqual(self.subject.hvac_mode, STATE_UNAVAILABLE)
  76. self.dps[HVACMODE_DPS] = "DRY"
  77. self.dps[POWER_DPS] = False
  78. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_OFF)
  79. def test_hvac_modes(self):
  80. self.assertCountEqual(
  81. self.subject.hvac_modes,
  82. [
  83. HVAC_MODE_OFF,
  84. HVAC_MODE_HEAT,
  85. HVAC_MODE_COOL,
  86. HVAC_MODE_DRY,
  87. HVAC_MODE_FAN_ONLY,
  88. ],
  89. )
  90. async def test_turn_on(self):
  91. async with assert_device_properties_set(
  92. self.subject._device, {POWER_DPS: True, HVACMODE_DPS: "HEAT"}
  93. ):
  94. await self.subject.async_set_hvac_mode(HVAC_MODE_HEAT)
  95. async def test_turn_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(HVAC_MODE_OFF)
  100. def test_fan_mode(self):
  101. self.dps[FAN_DPS] = 1
  102. self.assertEqual(self.subject.fan_mode, "low")
  103. self.dps[FAN_DPS] = 2
  104. self.assertEqual(self.subject.fan_mode, "medium")
  105. self.dps[FAN_DPS] = 3
  106. self.assertEqual(self.subject.fan_mode, "high")
  107. def test_fan_modes(self):
  108. self.assertCountEqual(
  109. self.subject.fan_modes,
  110. [
  111. "low",
  112. "medium",
  113. "high",
  114. ],
  115. )
  116. async def test_set_fan_mode_to_low(self):
  117. async with assert_device_properties_set(
  118. self.subject._device,
  119. {FAN_DPS: 1},
  120. ):
  121. await self.subject.async_set_fan_mode("low")
  122. async def test_set_fan_mode_to_medium(self):
  123. async with assert_device_properties_set(
  124. self.subject._device,
  125. {FAN_DPS: 2},
  126. ):
  127. await self.subject.async_set_fan_mode("medium")
  128. async def test_set_fan_mode_to_high(self):
  129. async with assert_device_properties_set(
  130. self.subject._device,
  131. {FAN_DPS: 3},
  132. ):
  133. await self.subject.async_set_fan_mode("high")
  134. def test_swing_modes(self):
  135. self.assertCountEqual(
  136. self.subject.swing_modes,
  137. ["off", "vertical"],
  138. )
  139. def test_swing_mode(self):
  140. self.dps[SWING_DPS] = False
  141. self.assertEqual(self.subject.swing_mode, "off")
  142. self.dps[SWING_DPS] = True
  143. self.assertEqual(self.subject.swing_mode, "vertical")
  144. async def test_set_swing_mode_to_off(self):
  145. async with assert_device_properties_set(
  146. self.subject._device,
  147. {SWING_DPS: False},
  148. ):
  149. await self.subject.async_set_swing_mode("off")
  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("vertical")
  156. def test_extra_state_attribures(self):
  157. self.dps[UNKNOWN102_DPS] = True
  158. self.dps[TIMER_DPS] = 103
  159. self.dps[COUNTDOWN_DPS] = 105
  160. self.dps[UNKNOWN106_DPS] = 106
  161. self.dps[UNKNOWN110_DPS] = 110
  162. self.assertDictEqual(
  163. self.subject.extra_state_attributes,
  164. {
  165. "unknown_102": True,
  166. "timer": 103,
  167. "countdown": 105,
  168. "unknown_106": 106,
  169. "unknown_110": 110,
  170. },
  171. )