test_awow_th213_thermostat.py 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  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. def test_supported_features(self):
  89. self.assertEqual(
  90. self.subject.supported_features,
  91. SUPPORT_TARGET_TEMPERATURE | SUPPORT_PRESET_MODE,
  92. )
  93. def test_icon(self):
  94. self.dps[HVACACTION_DPS] = True
  95. self.assertEqual(self.subject.icon, "mdi:thermometer")
  96. self.dps[HVACACTION_DPS] = False
  97. self.assertEqual(self.subject.icon, "mdi:thermometer-off")
  98. self.dps[LOCK_DPS] = True
  99. self.assertEqual(self.basicLock.icon, "mdi:hand-back-right-off")
  100. self.dps[LOCK_DPS] = False
  101. self.assertEqual(self.basicLock.icon, "mdi:hand-back-right")
  102. def test_temperature_unit_returns_device_temperature_unit(self):
  103. self.assertEqual(
  104. self.subject.temperature_unit, self.subject._device.temperature_unit
  105. )
  106. async def test_legacy_set_temperature_with_preset_mode(self):
  107. async with assert_device_properties_set(self.subject._device, {PRESET_DPS: 2}):
  108. await self.subject.async_set_temperature(preset_mode="Away")
  109. async def test_legacy_set_temperature_with_both_properties(self):
  110. async with assert_device_properties_set(
  111. self.subject._device,
  112. {
  113. TEMPERATURE_DPS: 25,
  114. PRESET_DPS: 3,
  115. },
  116. ):
  117. await self.subject.async_set_temperature(
  118. temperature=25, preset_mode="Smart"
  119. )
  120. def test_current_temperature(self):
  121. self.dps[CURRENTTEMP_DPS] = 25
  122. self.assertEqual(self.subject.current_temperature, 25)
  123. def test_hvac_mode(self):
  124. self.dps[HVACMODE_DPS] = True
  125. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_HEAT)
  126. self.dps[HVACMODE_DPS] = False
  127. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_OFF)
  128. self.dps[HVACMODE_DPS] = None
  129. self.assertEqual(self.subject.hvac_mode, STATE_UNAVAILABLE)
  130. def test_hvac_modes(self):
  131. self.assertCountEqual(self.subject.hvac_modes, [HVAC_MODE_OFF, HVAC_MODE_HEAT])
  132. async def test_turn_on(self):
  133. async with assert_device_properties_set(
  134. self.subject._device, {HVACMODE_DPS: True}
  135. ):
  136. await self.subject.async_set_hvac_mode(HVAC_MODE_HEAT)
  137. async def test_turn_off(self):
  138. async with assert_device_properties_set(
  139. self.subject._device, {HVACMODE_DPS: False}
  140. ):
  141. await self.subject.async_set_hvac_mode(HVAC_MODE_OFF)
  142. def test_preset_mode(self):
  143. self.dps[PRESET_DPS] = "1"
  144. self.assertEqual(self.subject.preset_mode, "Home")
  145. self.dps[PRESET_DPS] = "2"
  146. self.assertEqual(self.subject.preset_mode, "Away")
  147. self.dps[PRESET_DPS] = "3"
  148. self.assertEqual(self.subject.preset_mode, "Smart")
  149. self.dps[PRESET_DPS] = "4"
  150. self.assertEqual(self.subject.preset_mode, "Sleep")
  151. self.dps[PRESET_DPS] = None
  152. self.assertEqual(self.subject.preset_mode, None)
  153. def test_preset_modes(self):
  154. self.assertCountEqual(
  155. self.subject.preset_modes,
  156. ["Home", "Away", "Smart", "Sleep"],
  157. )
  158. async def test_set_preset_mode_to_home(self):
  159. async with assert_device_properties_set(
  160. self.subject._device,
  161. {PRESET_DPS: 1},
  162. ):
  163. await self.subject.async_set_preset_mode("Home")
  164. async def test_set_preset_mode_to_away(self):
  165. async with assert_device_properties_set(
  166. self.subject._device,
  167. {PRESET_DPS: 2},
  168. ):
  169. await self.subject.async_set_preset_mode("Away")
  170. async def test_set_preset_mode_to_smart(self):
  171. async with assert_device_properties_set(
  172. self.subject._device,
  173. {PRESET_DPS: 3},
  174. ):
  175. await self.subject.async_set_preset_mode("Smart")
  176. async def test_set_preset_mode_to_sleep(self):
  177. async with assert_device_properties_set(
  178. self.subject._device,
  179. {PRESET_DPS: 4},
  180. ):
  181. await self.subject.async_set_preset_mode("Sleep")
  182. def test_hvac_action(self):
  183. self.dps[HVACMODE_DPS] = True
  184. self.dps[HVACACTION_DPS] = True
  185. self.assertEqual(self.subject.hvac_action, CURRENT_HVAC_HEAT)
  186. self.dps[HVACACTION_DPS] = False
  187. self.assertEqual(self.subject.hvac_action, CURRENT_HVAC_IDLE)
  188. self.dps[HVACMODE_DPS] = False
  189. self.assertEqual(self.subject.hvac_action, CURRENT_HVAC_OFF)
  190. def test_device_state_attributes(self):
  191. self.dps[ERROR_DPS] = 8
  192. self.dps[EXTERNTEMP_DPS] = 27
  193. self.dps[SENSOR_DPS] = 1
  194. self.dps[CALIBRATE_DPS] = 2
  195. self.dps[CALIBSWING_DPS] = 3
  196. self.dps[UNKNOWN107_DPS] = True
  197. self.dps[UNKNOWN108_DPS] = False
  198. self.dps[UNKNOWN110_DPS] = 110
  199. self.assertDictEqual(
  200. self.subject.device_state_attributes,
  201. {
  202. "error": 8,
  203. "external_temperature": 27,
  204. "sensor": "External",
  205. "temperature_calibration_offset": 2,
  206. "temperature_calibration_swing": 3,
  207. "unknown_107": True,
  208. "unknown_108": False,
  209. "unknown_110": 110,
  210. },
  211. )