test_awow_th213_thermostat.py 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. from homeassistant.components.climate.const import (
  2. CURRENT_HVAC_HEAT,
  3. CURRENT_HVAC_IDLE,
  4. CURRENT_HVAC_OFF,
  5. HVAC_MODE_HEAT,
  6. HVAC_MODE_OFF,
  7. SUPPORT_PRESET_MODE,
  8. SUPPORT_TARGET_TEMPERATURE,
  9. )
  10. from homeassistant.const import (
  11. DEVICE_CLASS_TEMPERATURE,
  12. STATE_UNAVAILABLE,
  13. TEMP_CELSIUS,
  14. )
  15. from ..const import TH213_THERMOSTAT_PAYLOAD
  16. from ..helpers import assert_device_properties_set
  17. from ..mixins.climate import TargetTemperatureTests
  18. from ..mixins.lock import BasicLockTests
  19. from ..mixins.number import MultiNumberTests
  20. from ..mixins.select import BasicSelectTests
  21. from ..mixins.sensor import BasicSensorTests
  22. from .base_device_tests import TuyaDeviceTestCase
  23. HVACMODE_DPS = "1"
  24. TEMPERATURE_DPS = "2"
  25. CURRENTTEMP_DPS = "3"
  26. PRESET_DPS = "4"
  27. LOCK_DPS = "6"
  28. ERROR_DPS = "12"
  29. EXTERNTEMP_DPS = "101"
  30. SENSOR_DPS = "102"
  31. CALIBRATE_DPS = "103"
  32. CALIBSWING_DPS = "104"
  33. HVACACTION_DPS = "105"
  34. UNKNOWN107_DPS = "107"
  35. UNKNOWN108_DPS = "108"
  36. UNKNOWN110_DPS = "110"
  37. class TestAwowTH213Thermostat(
  38. BasicLockTests,
  39. BasicSelectTests,
  40. BasicSensorTests,
  41. MultiNumberTests,
  42. TargetTemperatureTests,
  43. TuyaDeviceTestCase,
  44. ):
  45. __test__ = True
  46. def setUp(self):
  47. self.setUpForConfig("awow_th213_thermostat.yaml", TH213_THERMOSTAT_PAYLOAD)
  48. self.subject = self.entities.get("climate")
  49. self.setUpTargetTemperature(
  50. TEMPERATURE_DPS,
  51. self.subject,
  52. min=5,
  53. max=30,
  54. )
  55. self.setUpBasicLock(LOCK_DPS, self.entities.get("lock_child_lock"))
  56. self.setUpBasicSensor(
  57. EXTERNTEMP_DPS,
  58. self.entities.get("sensor_external_temperature"),
  59. unit=TEMP_CELSIUS,
  60. device_class=DEVICE_CLASS_TEMPERATURE,
  61. state_class="measurement",
  62. )
  63. self.setUpBasicSelect(
  64. SENSOR_DPS,
  65. self.entities.get("select_temperature_sensor"),
  66. {
  67. 0: "Internal",
  68. 1: "External",
  69. 2: "Both",
  70. },
  71. )
  72. self.setUpMultiNumber(
  73. [
  74. {
  75. "name": "number_calibration_offset",
  76. "dps": CALIBRATE_DPS,
  77. "min": -9,
  78. "max": 9,
  79. },
  80. {
  81. "name": "number_calibration_swing",
  82. "dps": CALIBSWING_DPS,
  83. "min": 1,
  84. "max": 9,
  85. },
  86. ]
  87. )
  88. self.mark_secondary(
  89. [
  90. "lock_child_lock",
  91. "select_temperature_sensor",
  92. "number_calibration_offset",
  93. "number_calibration_swing",
  94. ]
  95. )
  96. def test_supported_features(self):
  97. self.assertEqual(
  98. self.subject.supported_features,
  99. SUPPORT_TARGET_TEMPERATURE | SUPPORT_PRESET_MODE,
  100. )
  101. def test_icon(self):
  102. self.dps[HVACACTION_DPS] = True
  103. self.assertEqual(self.subject.icon, "mdi:thermometer")
  104. self.dps[HVACACTION_DPS] = False
  105. self.assertEqual(self.subject.icon, "mdi:thermometer-off")
  106. self.dps[LOCK_DPS] = True
  107. self.assertEqual(self.basicLock.icon, "mdi:hand-back-right-off")
  108. self.dps[LOCK_DPS] = False
  109. self.assertEqual(self.basicLock.icon, "mdi:hand-back-right")
  110. def test_temperature_unit_returns_device_temperature_unit(self):
  111. self.assertEqual(
  112. self.subject.temperature_unit, self.subject._device.temperature_unit
  113. )
  114. async def test_legacy_set_temperature_with_preset_mode(self):
  115. async with assert_device_properties_set(self.subject._device, {PRESET_DPS: 2}):
  116. await self.subject.async_set_temperature(preset_mode="Away")
  117. async def test_legacy_set_temperature_with_both_properties(self):
  118. async with assert_device_properties_set(
  119. self.subject._device,
  120. {
  121. TEMPERATURE_DPS: 25,
  122. PRESET_DPS: 3,
  123. },
  124. ):
  125. await self.subject.async_set_temperature(
  126. temperature=25, preset_mode="Smart"
  127. )
  128. def test_current_temperature(self):
  129. self.dps[CURRENTTEMP_DPS] = 25
  130. self.assertEqual(self.subject.current_temperature, 25)
  131. def test_hvac_mode(self):
  132. self.dps[HVACMODE_DPS] = True
  133. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_HEAT)
  134. self.dps[HVACMODE_DPS] = False
  135. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_OFF)
  136. self.dps[HVACMODE_DPS] = None
  137. self.assertEqual(self.subject.hvac_mode, STATE_UNAVAILABLE)
  138. def test_hvac_modes(self):
  139. self.assertCountEqual(self.subject.hvac_modes, [HVAC_MODE_OFF, HVAC_MODE_HEAT])
  140. async def test_turn_on(self):
  141. async with assert_device_properties_set(
  142. self.subject._device, {HVACMODE_DPS: True}
  143. ):
  144. await self.subject.async_set_hvac_mode(HVAC_MODE_HEAT)
  145. async def test_turn_off(self):
  146. async with assert_device_properties_set(
  147. self.subject._device, {HVACMODE_DPS: False}
  148. ):
  149. await self.subject.async_set_hvac_mode(HVAC_MODE_OFF)
  150. def test_preset_mode(self):
  151. self.dps[PRESET_DPS] = "1"
  152. self.assertEqual(self.subject.preset_mode, "Home")
  153. self.dps[PRESET_DPS] = "2"
  154. self.assertEqual(self.subject.preset_mode, "Away")
  155. self.dps[PRESET_DPS] = "3"
  156. self.assertEqual(self.subject.preset_mode, "Smart")
  157. self.dps[PRESET_DPS] = "4"
  158. self.assertEqual(self.subject.preset_mode, "Sleep")
  159. self.dps[PRESET_DPS] = None
  160. self.assertEqual(self.subject.preset_mode, None)
  161. def test_preset_modes(self):
  162. self.assertCountEqual(
  163. self.subject.preset_modes,
  164. ["Home", "Away", "Smart", "Sleep"],
  165. )
  166. async def test_set_preset_mode_to_home(self):
  167. async with assert_device_properties_set(
  168. self.subject._device,
  169. {PRESET_DPS: 1},
  170. ):
  171. await self.subject.async_set_preset_mode("Home")
  172. async def test_set_preset_mode_to_away(self):
  173. async with assert_device_properties_set(
  174. self.subject._device,
  175. {PRESET_DPS: 2},
  176. ):
  177. await self.subject.async_set_preset_mode("Away")
  178. async def test_set_preset_mode_to_smart(self):
  179. async with assert_device_properties_set(
  180. self.subject._device,
  181. {PRESET_DPS: 3},
  182. ):
  183. await self.subject.async_set_preset_mode("Smart")
  184. async def test_set_preset_mode_to_sleep(self):
  185. async with assert_device_properties_set(
  186. self.subject._device,
  187. {PRESET_DPS: 4},
  188. ):
  189. await self.subject.async_set_preset_mode("Sleep")
  190. def test_hvac_action(self):
  191. self.dps[HVACMODE_DPS] = True
  192. self.dps[HVACACTION_DPS] = True
  193. self.assertEqual(self.subject.hvac_action, CURRENT_HVAC_HEAT)
  194. self.dps[HVACACTION_DPS] = False
  195. self.assertEqual(self.subject.hvac_action, CURRENT_HVAC_IDLE)
  196. self.dps[HVACMODE_DPS] = False
  197. self.assertEqual(self.subject.hvac_action, CURRENT_HVAC_OFF)
  198. def test_device_state_attributes(self):
  199. self.dps[ERROR_DPS] = 8
  200. self.dps[EXTERNTEMP_DPS] = 27
  201. self.dps[SENSOR_DPS] = 1
  202. self.dps[CALIBRATE_DPS] = 2
  203. self.dps[CALIBSWING_DPS] = 3
  204. self.dps[UNKNOWN107_DPS] = True
  205. self.dps[UNKNOWN108_DPS] = False
  206. self.dps[UNKNOWN110_DPS] = 110
  207. self.assertDictEqual(
  208. self.subject.device_state_attributes,
  209. {
  210. "error": 8,
  211. "external_temperature": 27,
  212. "sensor": "External",
  213. "temperature_calibration_offset": 2,
  214. "temperature_calibration_swing": 3,
  215. "unknown_107": True,
  216. "unknown_108": False,
  217. "unknown_110": 110,
  218. },
  219. )