test_saswell_t29utk_thermostat.py 8.8 KB

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