test_jiahong_et72w_thermostat.py 7.8 KB

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