test_saswell_t29utk_thermostat.py 8.9 KB

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