test_jiahong_et72w_thermostat.py 7.8 KB

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