test_jiahong_et72w_thermostat.py 7.8 KB

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