test_saswell_t29utk_thermostat.py 8.9 KB

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