test_awow_th213_thermostat.py 8.2 KB

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