test_jiahong_et72w_thermostat.py 7.8 KB

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