test_jiahong_et72w_thermostat.py 7.7 KB

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