test_jiahong_et72w_thermostat.py 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. from homeassistant.components.climate.const import (
  2. HVAC_MODE_AUTO,
  3. HVAC_MODE_COOL,
  4. HVAC_MODE_HEAT,
  5. HVAC_MODE_OFF,
  6. SUPPORT_TARGET_TEMPERATURE,
  7. )
  8. from homeassistant.components.sensor import (
  9. STATE_CLASS_MEASUREMENT,
  10. STATE_CLASS_TOTAL_INCREASING,
  11. )
  12. from homeassistant.const import (
  13. DEVICE_CLASS_ENERGY,
  14. DEVICE_CLASS_TEMPERATURE,
  15. ENERGY_KILO_WATT_HOUR,
  16. STATE_UNAVAILABLE,
  17. TEMP_CELSIUS,
  18. TEMP_FAHRENHEIT,
  19. )
  20. from ..const import JIAHONG_ET72W_PAYLOAD
  21. from ..helpers import assert_device_properties_set
  22. from ..mixins.climate import TargetTemperatureTests
  23. from ..mixins.lock import BasicLockTests
  24. from ..mixins.number import BasicNumberTests
  25. from ..mixins.select import MultiSelectTests
  26. from ..mixins.sensor import MultiSensorTests
  27. from .base_device_tests import TuyaDeviceTestCase
  28. POWER_DPS = "101"
  29. TEMPERATURE_DPS = "102"
  30. HVACMODE_DPS = "103"
  31. UNKNOWN104_DPS = "104"
  32. CURRENTTEMP_DPS = "105"
  33. FLOORTEMP_DPS = "106"
  34. UNIT_DPS = "107"
  35. LOCK_DPS = "108"
  36. UNKNOWN109_DPS = "109"
  37. SCHED_DPS = "110"
  38. SENSOR_DPS = "111"
  39. UNKNOWN112_DPS = "112"
  40. UNKNOWN113_DPS = "113"
  41. CALIB_DPS = "116"
  42. ENERGY_DPS = "117"
  43. HVACACTION_DPS = "118"
  44. TEMPLIMIT_DPS = "121"
  45. class TestJiahongEt72wThermostat(
  46. BasicLockTests,
  47. BasicNumberTests,
  48. MultiSelectTests,
  49. MultiSensorTests,
  50. TargetTemperatureTests,
  51. TuyaDeviceTestCase,
  52. ):
  53. __test__ = True
  54. def setUp(self):
  55. self.setUpForConfig(
  56. "jiahong_et72w_thermostat.yaml",
  57. JIAHONG_ET72W_PAYLOAD,
  58. )
  59. self.subject = self.entities.get("climate")
  60. self.setUpTargetTemperature(
  61. TEMPERATURE_DPS,
  62. self.subject,
  63. min=5.0,
  64. max=40.0,
  65. scale=10,
  66. step=5,
  67. )
  68. self.setUpBasicLock(LOCK_DPS, self.entities.get("lock_screen_lock"))
  69. self.setUpMultiSelect(
  70. [
  71. {
  72. "dps": SCHED_DPS,
  73. "name": "select_auto_schedule",
  74. "options": {
  75. 0: "7",
  76. 1: "5+1+1",
  77. 2: "7 (Adaptive)",
  78. 3: "5+1+1 (Adaptive)",
  79. },
  80. },
  81. {
  82. "dps": UNIT_DPS,
  83. "name": "select_temperature_unit",
  84. "options": {
  85. False: "Celsius",
  86. True: "Fahrenheit",
  87. },
  88. },
  89. {
  90. "dps": SENSOR_DPS,
  91. "name": "select_temperature_sensor",
  92. "options": {
  93. "0": "Room",
  94. "1": "Floor",
  95. "2": "Both",
  96. },
  97. },
  98. ],
  99. )
  100. self.setUpBasicNumber(
  101. TEMPLIMIT_DPS,
  102. self.entities.get("number_room_temperature_limit"),
  103. min=10.0,
  104. max=40.0,
  105. step=0.5,
  106. scale=10,
  107. unit=TEMP_CELSIUS,
  108. )
  109. self.setUpMultiSensors(
  110. [
  111. {
  112. "dps": CURRENTTEMP_DPS,
  113. "name": "sensor_room_temperature",
  114. "device_class": DEVICE_CLASS_TEMPERATURE,
  115. "state_class": STATE_CLASS_MEASUREMENT,
  116. "unit": TEMP_CELSIUS,
  117. "testdata": (195, 19.5),
  118. },
  119. {
  120. "dps": FLOORTEMP_DPS,
  121. "name": "sensor_floor_temperature",
  122. "device_class": DEVICE_CLASS_TEMPERATURE,
  123. "state_class": STATE_CLASS_MEASUREMENT,
  124. "unit": TEMP_CELSIUS,
  125. "testdata": (214, 21.4),
  126. },
  127. {
  128. "dps": ENERGY_DPS,
  129. "name": "sensor_energy",
  130. "device_class": DEVICE_CLASS_ENERGY,
  131. "state_class": STATE_CLASS_TOTAL_INCREASING,
  132. "unit": ENERGY_KILO_WATT_HOUR,
  133. "testdata": (1234, 123.4),
  134. },
  135. ]
  136. )
  137. self.mark_secondary(
  138. [
  139. "lock_screen_lock",
  140. "number_room_temperature_limit",
  141. "select_auto_schedule",
  142. "select_temperature_sensor",
  143. "select_temperature_unit",
  144. ],
  145. )
  146. def test_supported_features(self):
  147. self.assertEqual(
  148. self.subject.supported_features,
  149. SUPPORT_TARGET_TEMPERATURE,
  150. )
  151. def test_temperature_unit(self):
  152. self.dps[UNIT_DPS] = False
  153. self.assertEqual(
  154. self.subject.temperature_unit,
  155. TEMP_CELSIUS,
  156. )
  157. self.assertEqual(self.subject.target_temperature_step, 0.5)
  158. self.dps[UNIT_DPS] = True
  159. self.assertEqual(
  160. self.subject.temperature_unit,
  161. TEMP_FAHRENHEIT,
  162. )
  163. self.assertEqual(self.subject.target_temperature_step, 3.0)
  164. def test_current_temperature(self):
  165. self.dps[CURRENTTEMP_DPS] = 385
  166. self.assertEqual(self.subject.current_temperature, 38.5)
  167. def test_hvac_mode(self):
  168. self.dps[POWER_DPS] = False
  169. self.dps[HVACMODE_DPS] = "Smart"
  170. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_OFF)
  171. self.dps[POWER_DPS] = True
  172. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_AUTO)
  173. self.dps[HVACMODE_DPS] = "Manual"
  174. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_HEAT)
  175. self.dps[HVACMODE_DPS] = "Anti_frozen"
  176. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_COOL)
  177. self.dps[HVACMODE_DPS] = None
  178. self.assertEqual(self.subject.hvac_mode, STATE_UNAVAILABLE)
  179. def test_hvac_modes(self):
  180. self.assertCountEqual(
  181. self.subject.hvac_modes,
  182. [
  183. HVAC_MODE_AUTO,
  184. HVAC_MODE_COOL,
  185. HVAC_MODE_HEAT,
  186. HVAC_MODE_OFF,
  187. ],
  188. )
  189. # Override - since min and max are set by attributes, the range
  190. # allowed when setting is wider than normal. The thermostat seems
  191. # to be configurable as at least a water heater (to 212F), as tuya
  192. # doc says max 1000.0 (after scaling)
  193. async def test_set_target_temperature_fails_outside_valid_range(self):
  194. with self.assertRaisesRegex(
  195. ValueError,
  196. f"temperature \\(4.5\\) must be between 5.0 and 40.0",
  197. ):
  198. await self.subject.async_set_target_temperature(4.5)
  199. with self.assertRaisesRegex(
  200. ValueError,
  201. f"temperature \\(41\\) must be between 5.0 and 40.0",
  202. ):
  203. await self.subject.async_set_target_temperature(41)
  204. def test_extra_state_attributes(self):
  205. self.dps[UNKNOWN104_DPS] = 104
  206. self.dps[UNKNOWN109_DPS] = True
  207. self.dps[UNKNOWN112_DPS] = 112
  208. self.dps[UNKNOWN113_DPS] = 113
  209. self.assertDictEqual(
  210. self.subject.extra_state_attributes,
  211. {
  212. "unknown_104": 104,
  213. "unknown_109": True,
  214. "unknown_112": 112,
  215. "unknown_113": 113,
  216. },
  217. )
  218. def test_multi_sensor_extra_state_attributes(self):
  219. self.dps[CALIB_DPS] = 321
  220. self.assertEqual(
  221. self.multiSensor["sensor_energy"].extra_state_attributes,
  222. {"energy_calibration": 321},
  223. )
  224. def test_icons(self):
  225. self.dps[LOCK_DPS] = True
  226. self.assertEqual(self.basicLock.icon, "mdi:hand-back-right-off")
  227. self.dps[LOCK_DPS] = False
  228. self.assertEqual(self.basicLock.icon, "mdi:hand-back-right")