test_jiahong_et72w_thermostat.py 7.8 KB

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