test_saswell_t29utk_thermostat.py 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  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. self.mark_secondary(["select_configuration", "select_temperature_unit"])
  77. def test_supported_features(self):
  78. self.assertEqual(
  79. self.subject.supported_features,
  80. SUPPORT_TARGET_TEMPERATURE | SUPPORT_FAN_MODE | SUPPORT_PRESET_MODE,
  81. )
  82. def test_icon(self):
  83. self.dps[HVACMODE_DPS] = "cold"
  84. self.assertEqual(self.subject.icon, "mdi:thermometer-minus")
  85. self.dps[HVACMODE_DPS] = "hot"
  86. self.assertEqual(self.subject.icon, "mdi:thermometer-plus")
  87. self.dps[HVACMODE_DPS] = "off"
  88. self.assertEqual(self.subject.icon, "mdi:thermometer-off")
  89. def test_temperature_unit(self):
  90. self.dps[UNITS_DPS] = "C"
  91. self.assertEqual(self.subject.temperature_unit, TEMP_CELSIUS)
  92. self.dps[UNITS_DPS] = "F"
  93. self.assertEqual(self.subject.temperature_unit, TEMP_FAHRENHEIT)
  94. def test_target_temperature_step_f(self):
  95. self.dps[UNITS_DPS] = "F"
  96. self.assertEqual(self.subject.target_temperature_step, 1)
  97. def test_minimum_target_temperature_f(self):
  98. self.dps[UNITS_DPS] = "F"
  99. self.assertEqual(self.subject.min_temp, 41)
  100. def test_maximum_target_temperature_f(self):
  101. self.dps[UNITS_DPS] = "F"
  102. self.assertEqual(self.subject.max_temp, 95)
  103. async def test_set_target_temperature_f(self):
  104. self.dps[UNITS_DPS] = "F"
  105. async with assert_device_properties_set(
  106. self.subject._device,
  107. {TEMPERATURE_DPS: 740},
  108. ):
  109. await self.subject.async_set_target_temperature(74)
  110. def test_current_temperature(self):
  111. self.dps[CURRENTTEMP_DPS] = 250
  112. self.assertEqual(self.subject.current_temperature, 25.0)
  113. def test_hvac_mode(self):
  114. self.dps[HVACMODE_DPS] = "off"
  115. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_OFF)
  116. self.dps[HVACMODE_DPS] = "cold"
  117. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_COOL)
  118. self.dps[HVACMODE_DPS] = "hot"
  119. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_HEAT)
  120. def test_hvac_modes(self):
  121. self.assertCountEqual(
  122. self.subject.hvac_modes,
  123. [HVAC_MODE_COOL, HVAC_MODE_HEAT, HVAC_MODE_OFF],
  124. )
  125. async def test_turn_off(self):
  126. async with assert_device_properties_set(
  127. self.subject._device, {HVACMODE_DPS: "off"}
  128. ):
  129. await self.subject.async_set_hvac_mode(HVAC_MODE_OFF)
  130. async def test_set_hvac_mode_cool(self):
  131. async with assert_device_properties_set(
  132. self.subject._device, {HVACMODE_DPS: "cold"}
  133. ):
  134. await self.subject.async_set_hvac_mode(HVAC_MODE_COOL)
  135. async def test_set_hvac_mode_heat(self):
  136. async with assert_device_properties_set(
  137. self.subject._device, {HVACMODE_DPS: "hot"}
  138. ):
  139. await self.subject.async_set_hvac_mode(HVAC_MODE_HEAT)
  140. async def test_set_hvac_mode_heat_fails_in_cooling_config(self):
  141. self.dps[CONFIG_DPS] = "1"
  142. with self.assertRaisesRegex(
  143. AttributeError, "hvac_mode cannot be set at this time"
  144. ):
  145. await self.subject.async_set_hvac_mode(HVAC_MODE_HEAT)
  146. async def test_set_hvac_mode_cool_fails_in_heating_config(self):
  147. self.dps[CONFIG_DPS] = "2"
  148. with self.assertRaisesRegex(
  149. AttributeError, "hvac_mode cannot be set at this time"
  150. ):
  151. await self.subject.async_set_hvac_mode(HVAC_MODE_COOL)
  152. def test_hvac_action(self):
  153. self.dps[POWER_DPS] = True
  154. self.dps[HVACACTION_DPS] = "cold"
  155. self.assertEqual(self.subject.hvac_action, CURRENT_HVAC_COOL)
  156. self.dps[HVACACTION_DPS] = "hot"
  157. self.assertEqual(self.subject.hvac_action, CURRENT_HVAC_HEAT)
  158. self.dps[POWER_DPS] = False
  159. self.assertEqual(self.subject.hvac_action, CURRENT_HVAC_OFF)
  160. def test_fan_mode(self):
  161. self.dps[FAN_DPS] = "auto"
  162. self.assertEqual(self.subject.fan_mode, FAN_AUTO)
  163. self.dps[FAN_DPS] = "on"
  164. self.assertEqual(self.subject.fan_mode, FAN_ON)
  165. def test_fan_modes(self):
  166. self.assertCountEqual(self.subject.fan_modes, [FAN_AUTO, FAN_ON])
  167. async def test_set_fan_on(self):
  168. async with assert_device_properties_set(
  169. self.subject._device,
  170. {FAN_DPS: "on"},
  171. ):
  172. await self.subject.async_set_fan_mode(FAN_ON)
  173. async def test_set_fan_auto(self):
  174. async with assert_device_properties_set(
  175. self.subject._device,
  176. {FAN_DPS: "auto"},
  177. ):
  178. await self.subject.async_set_fan_mode(FAN_AUTO)
  179. def test_preset_mode(self):
  180. self.dps[AWAY_DPS] = False
  181. self.dps[PROGRAM_DPS] = False
  182. self.assertEqual(self.subject.preset_mode, PRESET_HOME)
  183. self.dps[PROGRAM_DPS] = True
  184. self.assertEqual(self.subject.preset_mode, "Program")
  185. self.dps[AWAY_DPS] = True
  186. self.assertEqual(self.subject.preset_mode, PRESET_AWAY)
  187. self.dps[PROGRAM_DPS] = False
  188. self.assertEqual(self.subject.preset_mode, PRESET_AWAY)
  189. def test_preset_modes(self):
  190. self.assertCountEqual(
  191. self.subject.preset_modes,
  192. [PRESET_HOME, PRESET_AWAY, "Program"],
  193. )
  194. async def test_set_preset_to_away(self):
  195. async with assert_device_properties_set(
  196. self.subject._device,
  197. {AWAY_DPS: True},
  198. ):
  199. await self.subject.async_set_preset_mode(PRESET_AWAY)
  200. async def test_set_preset_to_home(self):
  201. async with assert_device_properties_set(
  202. self.subject._device,
  203. {AWAY_DPS: False, PROGRAM_DPS: False},
  204. ):
  205. await self.subject.async_set_preset_mode(PRESET_HOME)
  206. async def test_set_preset_to_program(self):
  207. async with assert_device_properties_set(
  208. self.subject._device,
  209. {AWAY_DPS: False, PROGRAM_DPS: True},
  210. ):
  211. await self.subject.async_set_preset_mode("Program")
  212. def test_extra_state_attributes(self):
  213. self.dps[POWER_DPS] = True
  214. self.dps[CONFIG_DPS] = "2"
  215. self.dps[UNKNOWN113_DPS] = 113
  216. self.dps[TEMPC_DPS] = 114
  217. self.dps[CURTEMPC_DPS] = 115
  218. self.dps[TEMPF_DPS] = 116
  219. self.dps[CURTEMPF_DPS] = 117
  220. self.assertDictEqual(
  221. self.subject.extra_state_attributes,
  222. {
  223. "power": True,
  224. "configuration": "heating",
  225. "unknown_113": 113,
  226. "temperature_c": 114,
  227. "current_temperature_c": 115,
  228. "temperature_f": 116,
  229. "current_temperature_f": 117,
  230. },
  231. )