test_awow_th213v2_thermostat.py 8.1 KB

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