test_saswell_t29utk_thermostat.py 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. from homeassistant.components.climate.const import (
  2. CURRENT_HVAC_COOL,
  3. CURRENT_HVAC_HEAT,
  4. CURRENT_HVAC_IDLE,
  5. CURRENT_HVAC_OFF,
  6. FAN_AUTO,
  7. FAN_ON,
  8. HVAC_MODE_COOL,
  9. HVAC_MODE_HEAT,
  10. HVAC_MODE_OFF,
  11. PRESET_AWAY,
  12. PRESET_HOME,
  13. SUPPORT_FAN_MODE,
  14. SUPPORT_PRESET_MODE,
  15. SUPPORT_TARGET_TEMPERATURE,
  16. )
  17. from homeassistant.const import STATE_UNAVAILABLE, TEMP_CELSIUS, TEMP_FAHRENHEIT
  18. from unittest.mock import ANY
  19. from ..const import SASWELL_T29UTK_THERMOSTAT_PAYLOAD
  20. from ..helpers import assert_device_properties_set
  21. from .base_device_tests import TuyaDeviceTestCase
  22. POWER_DPS = "1"
  23. TEMPERATURE_DPS = "2"
  24. CURRENTTEMP_DPS = "3"
  25. HVACACTION_DPS = "4"
  26. FAN_DPS = "5"
  27. UNITS_DPS = "19"
  28. AWAY_DPS = "101"
  29. PROGRAM_DPS = "102"
  30. HVACMODE_DPS = "103"
  31. UNKNOWN112_DPS = "112"
  32. UNKNOWN113_DPS = "113"
  33. TEMPC_DPS = "114"
  34. CURTEMPC_DPS = "115"
  35. TEMPF_DPS = "116"
  36. CURTEMPF_DPS = "117"
  37. class TestSaswellT29UTKThermostat(TuyaDeviceTestCase):
  38. __test__ = True
  39. def setUp(self):
  40. self.setUpForConfig(
  41. "saswell_t29utk_thermostat.yaml", SASWELL_T29UTK_THERMOSTAT_PAYLOAD
  42. )
  43. self.subject = self.entities.get("climate")
  44. def test_supported_features(self):
  45. self.assertEqual(
  46. self.subject.supported_features,
  47. SUPPORT_TARGET_TEMPERATURE | SUPPORT_FAN_MODE | SUPPORT_PRESET_MODE,
  48. )
  49. def test_icon(self):
  50. self.dps[POWER_DPS] = True
  51. self.dps[HVACACTION_DPS] = "cold"
  52. self.assertEqual(self.subject.icon, "mdi:thermometer-minus")
  53. self.dps[HVACACTION_DPS] = "heat"
  54. self.assertEqual(self.subject.icon, "mdi:thermometer-plus")
  55. self.dps[HVACACTION_DPS] = "off"
  56. self.assertEqual(self.subject.icon, "mdi:thermometer")
  57. self.dps[POWER_DPS] = False
  58. self.assertEqual(self.subject.icon, "mdi:thermometer-off")
  59. def test_temperature_unit(self):
  60. self.dps[UNITS_DPS] = "c"
  61. self.assertEqual(self.subject.temperature_unit, TEMP_CELSIUS)
  62. self.dps[UNITS_DPS] = "f"
  63. self.assertEqual(self.subject.temperature_unit, TEMP_FAHRENHEIT)
  64. def test_target_temperature(self):
  65. self.dps[TEMPERATURE_DPS] = 250
  66. self.assertEqual(self.subject.target_temperature, 25.0)
  67. def test_target_temperature_step(self):
  68. self.dps[UNITS_DPS] = "c"
  69. self.assertEqual(self.subject.target_temperature_step, 0.5)
  70. self.dps[UNITS_DPS] = "f"
  71. self.assertEqual(self.subject.target_temperature_step, 1)
  72. def test_minimum_target_temperature(self):
  73. self.assertEqual(self.subject.min_temp, 5)
  74. def test_maximum_target_temperature(self):
  75. self.assertEqual(self.subject.max_temp, 35)
  76. async def test_set_target_temperature(self):
  77. async with assert_device_properties_set(
  78. self.subject._device,
  79. {TEMPERATURE_DPS: 245},
  80. ):
  81. await self.subject.async_set_target_temperature(24.5)
  82. async def test_set_target_temperature_rounds_value_to_half_degrees(self):
  83. async with assert_device_properties_set(
  84. self.subject._device,
  85. {TEMPERATURE_DPS: 245},
  86. ):
  87. await self.subject.async_set_target_temperature(24.6)
  88. async def test_set_target_temperature_fails_outside_valid_range(self):
  89. with self.assertRaisesRegex(
  90. ValueError, "temperature \\(4\\) must be between 5.0 and 35.0"
  91. ):
  92. await self.subject.async_set_target_temperature(4)
  93. def test_current_temperature(self):
  94. self.dps[CURRENTTEMP_DPS] = 250
  95. self.assertEqual(self.subject.current_temperature, 25.0)
  96. def test_hvac_mode(self):
  97. self.dps[POWER_DPS] = False
  98. self.dps[HVACMODE_DPS] = "cold"
  99. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_OFF)
  100. self.dps[POWER_DPS] = True
  101. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_COOL)
  102. self.dps[HVACMODE_DPS] = "heat"
  103. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_HEAT)
  104. def test_hvac_modes(self):
  105. self.assertCountEqual(
  106. self.subject.hvac_modes,
  107. [HVAC_MODE_COOL, HVAC_MODE_HEAT, HVAC_MODE_OFF],
  108. )
  109. async def test_turn_off(self):
  110. async with assert_device_properties_set(
  111. self.subject._device, {POWER_DPS: False, HVACMODE_DPS: ANY}
  112. ):
  113. await self.subject.async_set_hvac_mode(HVAC_MODE_OFF)
  114. async def test_set_hvac_mode_cool(self):
  115. async with assert_device_properties_set(
  116. self.subject._device, {POWER_DPS: True, HVACMODE_DPS: "cold"}
  117. ):
  118. await self.subject.async_set_hvac_mode(HVAC_MODE_COOL)
  119. async def test_set_hvac_mode_heat(self):
  120. async with assert_device_properties_set(
  121. self.subject._device, {POWER_DPS: True, HVACMODE_DPS: "heat"}
  122. ):
  123. await self.subject.async_set_hvac_mode(HVAC_MODE_HEAT)
  124. def test_hvac_action(self):
  125. self.dps[POWER_DPS] = True
  126. self.dps[HVACACTION_DPS] = "cold"
  127. self.assertEqual(self.subject.hvac_action, CURRENT_HVAC_COOL)
  128. self.dps[HVACACTION_DPS] = "heat"
  129. self.assertEqual(self.subject.hvac_action, CURRENT_HVAC_HEAT)
  130. self.dps[HVACACTION_DPS] = "off"
  131. self.assertEqual(self.subject.hvac_action, CURRENT_HVAC_IDLE)
  132. self.dps[POWER_DPS] = False
  133. self.assertEqual(self.subject.hvac_action, CURRENT_HVAC_OFF)
  134. def test_fan_mode(self):
  135. self.dps[FAN_DPS] = "auto"
  136. self.assertEqual(self.subject.fan_mode, FAN_AUTO)
  137. self.dps[FAN_DPS] = "on"
  138. self.assertEqual(self.subject.fan_mode, FAN_ON)
  139. def test_fan_modes(self):
  140. self.assertCountEqual(self.subject.fan_modes, [FAN_AUTO, FAN_ON])
  141. async def test_set_fan_on(self):
  142. async with assert_device_properties_set(
  143. self.subject._device,
  144. {FAN_DPS: "on"},
  145. ):
  146. await self.subject.async_set_fan_mode(FAN_ON)
  147. async def test_set_fan_auto(self):
  148. async with assert_device_properties_set(
  149. self.subject._device,
  150. {FAN_DPS: "auto"},
  151. ):
  152. await self.subject.async_set_fan_mode(FAN_AUTO)
  153. def test_preset_mode(self):
  154. self.dps[AWAY_DPS] = False
  155. self.dps[PROGRAM_DPS] = False
  156. self.assertEqual(self.subject.preset_mode, PRESET_HOME)
  157. self.dps[PROGRAM_DPS] = True
  158. self.assertEqual(self.subject.preset_mode, "Program")
  159. self.dps[AWAY_DPS] = True
  160. self.assertEqual(self.subject.preset_mode, PRESET_AWAY)
  161. self.dps[PROGRAM_DPS] = False
  162. self.assertEqual(self.subject.preset_mode, PRESET_AWAY)
  163. def test_preset_modes(self):
  164. self.assertCountEqual(
  165. self.subject.preset_modes,
  166. [PRESET_HOME, PRESET_AWAY, "Program"],
  167. )
  168. async def test_set_preset_to_away(self):
  169. async with assert_device_properties_set(
  170. self.subject._device,
  171. {AWAY_DPS: True},
  172. ):
  173. await self.subject.async_set_preset_mode(PRESET_AWAY)
  174. async def test_set_preset_to_home(self):
  175. async with assert_device_properties_set(
  176. self.subject._device,
  177. {AWAY_DPS: False, PROGRAM_DPS: False},
  178. ):
  179. await self.subject.async_set_preset_mode(PRESET_HOME)
  180. async def test_set_preset_to_program(self):
  181. async with assert_device_properties_set(
  182. self.subject._device,
  183. {AWAY_DPS: False, PROGRAM_DPS: True},
  184. ):
  185. await self.subject.async_set_preset_mode("Program")
  186. def test_device_state_attributes(self):
  187. self.dps[UNKNOWN112_DPS] = "unknown112"
  188. self.dps[UNKNOWN113_DPS] = 113
  189. self.dps[TEMPC_DPS] = 114
  190. self.dps[CURTEMPC_DPS] = 115
  191. self.dps[TEMPF_DPS] = 116
  192. self.dps[CURTEMPF_DPS] = 117
  193. self.assertCountEqual(
  194. self.subject.device_state_attributes,
  195. {
  196. "unknown_112": "unknown112",
  197. "unknown_113": 113,
  198. "temperature_c": 114,
  199. "current_temperature_c": 115,
  200. "temperature_f": 116,
  201. "current_temperature_f": 117,
  202. },
  203. )