test_awow_th213_thermostat.py 8.1 KB

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