test_awow_th213v2_thermostat.py 8.0 KB

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