test_jiahong_et72w_thermostat.py 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  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. "unit": UnitOfEnergy.KILO_WATT_HOUR,
  125. "testdata": (1234, 123.4),
  126. },
  127. ]
  128. )
  129. self.mark_secondary(
  130. [
  131. "lock_screen_lock",
  132. "number_room_temperature_limit",
  133. "select_auto_schedule",
  134. "select_temperature_sensor",
  135. "select_temperature_unit",
  136. ],
  137. )
  138. def test_supported_features(self):
  139. self.assertEqual(
  140. self.subject.supported_features,
  141. ClimateEntityFeature.TARGET_TEMPERATURE,
  142. )
  143. def test_temperature_unit(self):
  144. self.dps[UNIT_DPS] = False
  145. self.assertEqual(
  146. self.subject.temperature_unit,
  147. UnitOfTemperature.CELSIUS,
  148. )
  149. self.assertEqual(self.subject.target_temperature_step, 0.5)
  150. self.dps[UNIT_DPS] = True
  151. self.assertEqual(
  152. self.subject.temperature_unit,
  153. UnitOfTemperature.FAHRENHEIT,
  154. )
  155. self.assertEqual(self.subject.target_temperature_step, 3.0)
  156. def test_current_temperature(self):
  157. self.dps[CURRENTTEMP_DPS] = 385
  158. self.assertEqual(self.subject.current_temperature, 38.5)
  159. def test_farenheit(self):
  160. self.dps[UNIT_DPS] = True
  161. # these seem suspicious, but are the values provided by the device
  162. # owner in the config. Basically in C they translate to:
  163. # Setting C F
  164. # min temp 5 12F = -11C
  165. # max temp 40 75F = 24C
  166. # temp step 0.5 3F = 2C
  167. # It seems more likely that it should be 40 - 100 with step 1
  168. # (or in the config, 400 - 1000, step 10, scale 10)
  169. self.assertEqual(self.subject.min_temp, 12.0)
  170. self.assertEqual(self.subject.max_temp, 75.0)
  171. self.assertEqual(self.subject.target_temperature_step, 3.0)
  172. def test_hvac_mode(self):
  173. self.dps[POWER_DPS] = False
  174. self.dps[HVACMODE_DPS] = "Smart"
  175. self.assertEqual(self.subject.hvac_mode, HVACMode.OFF)
  176. self.dps[POWER_DPS] = True
  177. self.assertEqual(self.subject.hvac_mode, HVACMode.AUTO)
  178. self.dps[HVACMODE_DPS] = "Manual"
  179. self.assertEqual(self.subject.hvac_mode, HVACMode.HEAT)
  180. self.dps[HVACMODE_DPS] = "Anti_frozen"
  181. self.assertEqual(self.subject.hvac_mode, HVACMode.COOL)
  182. def test_hvac_modes(self):
  183. self.assertCountEqual(
  184. self.subject.hvac_modes,
  185. [
  186. HVACMode.AUTO,
  187. HVACMode.COOL,
  188. HVACMode.HEAT,
  189. HVACMode.OFF,
  190. ],
  191. )
  192. async def test_set_target_temperature_fails_outside_valid_range(self):
  193. with self.assertRaisesRegex(
  194. ValueError,
  195. f"temperature \\(4.5\\) must be between 5.0 and 40.0",
  196. ):
  197. await self.subject.async_set_target_temperature(4.5)
  198. with self.assertRaisesRegex(
  199. ValueError,
  200. f"temperature \\(41\\) must be between 5.0 and 40.0",
  201. ):
  202. await self.subject.async_set_target_temperature(41)
  203. def test_extra_state_attributes(self):
  204. self.dps[UNKNOWN104_DPS] = 104
  205. self.dps[UNKNOWN109_DPS] = True
  206. self.dps[UNKNOWN112_DPS] = 112
  207. self.dps[UNKNOWN113_DPS] = 113
  208. self.assertDictEqual(
  209. self.subject.extra_state_attributes,
  210. {
  211. "unknown_104": 104,
  212. "unknown_109": True,
  213. "unknown_112": 112,
  214. "unknown_113": 113,
  215. },
  216. )
  217. def test_multi_sensor_extra_state_attributes(self):
  218. self.dps[CALIB_DPS] = 321
  219. self.assertEqual(
  220. self.multiSensor["sensor_energy"].extra_state_attributes,
  221. {"energy_calibration": 321},
  222. )
  223. def test_icons(self):
  224. self.dps[LOCK_DPS] = True
  225. self.assertEqual(self.basicLock.icon, "mdi:hand-back-right-off")
  226. self.dps[LOCK_DPS] = False
  227. self.assertEqual(self.basicLock.icon, "mdi:hand-back-right")