test_awow_th213_thermostat.py 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  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_celsius(self):
  109. self.assertEqual(self.subject.temperature_unit, UnitOfTemperature.CELSIUS)
  110. async def test_legacy_set_temperature_with_preset_mode(self):
  111. async with assert_device_properties_set(self.subject._device, {PRESET_DPS: 2}):
  112. await self.subject.async_set_temperature(preset_mode="Away")
  113. async def test_legacy_set_temperature_with_both_properties(self):
  114. async with assert_device_properties_set(
  115. self.subject._device,
  116. {
  117. TEMPERATURE_DPS: 25,
  118. PRESET_DPS: 3,
  119. },
  120. ):
  121. await self.subject.async_set_temperature(
  122. temperature=25, preset_mode="Smart"
  123. )
  124. def test_current_temperature(self):
  125. self.dps[CURRENTTEMP_DPS] = 25
  126. self.assertEqual(self.subject.current_temperature, 25)
  127. def test_hvac_mode(self):
  128. self.dps[HVACMODE_DPS] = True
  129. self.assertEqual(self.subject.hvac_mode, HVACMode.HEAT)
  130. self.dps[HVACMODE_DPS] = False
  131. self.assertEqual(self.subject.hvac_mode, HVACMode.OFF)
  132. def test_hvac_modes(self):
  133. self.assertCountEqual(self.subject.hvac_modes, [HVACMode.OFF, HVACMode.HEAT])
  134. async def test_turn_on(self):
  135. async with assert_device_properties_set(
  136. self.subject._device, {HVACMODE_DPS: True}
  137. ):
  138. await self.subject.async_set_hvac_mode(HVACMode.HEAT)
  139. async def test_turn_off(self):
  140. async with assert_device_properties_set(
  141. self.subject._device, {HVACMODE_DPS: False}
  142. ):
  143. await self.subject.async_set_hvac_mode(HVACMode.OFF)
  144. def test_preset_mode(self):
  145. self.dps[PRESET_DPS] = "1"
  146. self.assertEqual(self.subject.preset_mode, "Home")
  147. self.dps[PRESET_DPS] = "2"
  148. self.assertEqual(self.subject.preset_mode, "Away")
  149. self.dps[PRESET_DPS] = "3"
  150. self.assertEqual(self.subject.preset_mode, "Smart")
  151. self.dps[PRESET_DPS] = "4"
  152. self.assertEqual(self.subject.preset_mode, "Sleep")
  153. self.dps[PRESET_DPS] = None
  154. self.assertEqual(self.subject.preset_mode, None)
  155. def test_preset_modes(self):
  156. self.assertCountEqual(
  157. self.subject.preset_modes,
  158. ["Home", "Away", "Smart", "Sleep"],
  159. )
  160. async def test_set_preset_mode_to_home(self):
  161. async with assert_device_properties_set(
  162. self.subject._device,
  163. {PRESET_DPS: 1},
  164. ):
  165. await self.subject.async_set_preset_mode("Home")
  166. async def test_set_preset_mode_to_away(self):
  167. async with assert_device_properties_set(
  168. self.subject._device,
  169. {PRESET_DPS: 2},
  170. ):
  171. await self.subject.async_set_preset_mode("Away")
  172. async def test_set_preset_mode_to_smart(self):
  173. async with assert_device_properties_set(
  174. self.subject._device,
  175. {PRESET_DPS: 3},
  176. ):
  177. await self.subject.async_set_preset_mode("Smart")
  178. async def test_set_preset_mode_to_sleep(self):
  179. async with assert_device_properties_set(
  180. self.subject._device,
  181. {PRESET_DPS: 4},
  182. ):
  183. await self.subject.async_set_preset_mode("Sleep")
  184. def test_hvac_action(self):
  185. self.dps[HVACMODE_DPS] = True
  186. self.dps[HVACACTION_DPS] = True
  187. self.assertEqual(self.subject.hvac_action, HVACAction.HEATING)
  188. self.dps[HVACACTION_DPS] = False
  189. self.assertEqual(self.subject.hvac_action, HVACAction.IDLE)
  190. self.dps[HVACMODE_DPS] = False
  191. self.assertEqual(self.subject.hvac_action, HVACAction.OFF)
  192. def test_extra_state_attributes(self):
  193. self.dps[ERROR_DPS] = 8
  194. self.dps[EXTERNTEMP_DPS] = 27
  195. self.dps[SENSOR_DPS] = 1
  196. self.dps[CALIBRATE_DPS] = 2
  197. self.dps[CALIBSWING_DPS] = 3
  198. self.dps[UNKNOWN107_DPS] = True
  199. self.dps[UNKNOWN108_DPS] = False
  200. self.dps[UNKNOWN110_DPS] = 110
  201. self.assertDictEqual(
  202. self.subject.extra_state_attributes,
  203. {
  204. "error": 8,
  205. "external_temperature": 27,
  206. "sensor": "External",
  207. "temperature_calibration_offset": 2,
  208. "temperature_calibration_swing": 3,
  209. "unknown_107": True,
  210. "unknown_108": False,
  211. "unknown_110": 110,
  212. },
  213. )