test_hysen_hy08we2_thermostat.py 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. from homeassistant.components.climate.const import (
  2. ClimateEntityFeature,
  3. HVACAction,
  4. HVACMode,
  5. )
  6. from homeassistant.components.sensor import SensorDeviceClass
  7. from homeassistant.const import TEMP_CELSIUS, TIME_DAYS
  8. from ..const import HYSEN_HY08WE2_THERMOSTAT_PAYLOAD
  9. from ..helpers import assert_device_properties_set
  10. from ..mixins.climate import TargetTemperatureTests
  11. from ..mixins.lock import BasicLockTests
  12. from ..mixins.number import MultiNumberTests
  13. from ..mixins.select import MultiSelectTests
  14. from ..mixins.sensor import BasicSensorTests
  15. from .base_device_tests import TuyaDeviceTestCase
  16. HVACMODE_DPS = "1"
  17. TEMPERATURE_DPS = "2"
  18. CURRENTTEMP_DPS = "3"
  19. PRESET_DPS = "4"
  20. LOCK_DPS = "6"
  21. UNKNOWN12_DPS = "12"
  22. UNKNOWN101_DPS = "101"
  23. HVACACTION_DPS = "102"
  24. EXTTEMP_DPS = "103"
  25. HOLIDAYS_DPS = "104"
  26. HOLIDAYTEMP_DPS = "105"
  27. UNKNOWN106_DPS = "106"
  28. UNKNOWN107_DPS = "107"
  29. UNKNOWN108_DPS = "108"
  30. CALIBOFFSET_DPS = "109"
  31. CALIBSWINGINT_DPS = "110"
  32. CALIBSWINGEXT_DPS = "111"
  33. HIGHTEMP_DPS = "112"
  34. LOWTEMP_DPS = "113"
  35. MAXTEMP_DPS = "114"
  36. MINTEMP_DPS = "115"
  37. SENSOR_DPS = "116"
  38. INITIAL_DPS = "117"
  39. SCHED_DPS = "118"
  40. class TestHysenHY08WE2Thermostat(
  41. BasicLockTests,
  42. MultiNumberTests,
  43. MultiSelectTests,
  44. BasicSensorTests,
  45. TargetTemperatureTests,
  46. TuyaDeviceTestCase,
  47. ):
  48. __test__ = True
  49. def setUp(self):
  50. self.setUpForConfig(
  51. "hysen_hy08we2_thermostat.yaml",
  52. HYSEN_HY08WE2_THERMOSTAT_PAYLOAD,
  53. )
  54. self.subject = self.entities.get("climate")
  55. self.setUpTargetTemperature(
  56. TEMPERATURE_DPS,
  57. self.subject,
  58. min=5.0,
  59. max=30.0,
  60. scale=10,
  61. step=5,
  62. )
  63. self.setUpBasicLock(LOCK_DPS, self.entities.get("lock_child_lock"))
  64. self.setUpMultiSelect(
  65. [
  66. {
  67. "dps": SCHED_DPS,
  68. "name": "select_schedule",
  69. "options": {
  70. "2days": "5 + 2 day",
  71. "1days": "6 + 1 day",
  72. "0days": "7 day",
  73. },
  74. },
  75. {
  76. "dps": INITIAL_DPS,
  77. "name": "select_initial_state",
  78. "options": {
  79. "keep": "Previous",
  80. "on": "On",
  81. "off": "Off",
  82. },
  83. },
  84. {
  85. "dps": SENSOR_DPS,
  86. "name": "select_temperature_sensor",
  87. "options": {
  88. "in": "Internal",
  89. "ext": "External",
  90. "all": "Both",
  91. },
  92. },
  93. ],
  94. )
  95. self.setUpBasicSensor(
  96. EXTTEMP_DPS,
  97. self.entities.get("sensor_external_temperature"),
  98. device_class=SensorDeviceClass.TEMPERATURE,
  99. testdata=(205, 20.5),
  100. unit=TEMP_CELSIUS,
  101. state_class="measurement",
  102. )
  103. self.setUpMultiNumber(
  104. [
  105. {
  106. "dps": HOLIDAYS_DPS,
  107. "name": "number_holiday_days",
  108. "min": 1,
  109. "max": 30,
  110. "unit": TIME_DAYS,
  111. },
  112. {
  113. "dps": HOLIDAYTEMP_DPS,
  114. "name": "number_holiday_temperature",
  115. "min": 5,
  116. "max": 30,
  117. "unit": TEMP_CELSIUS,
  118. },
  119. {
  120. "dps": CALIBOFFSET_DPS,
  121. "name": "number_calibration_offset",
  122. "min": -9,
  123. "max": 9,
  124. "unit": TEMP_CELSIUS,
  125. },
  126. {
  127. "dps": CALIBSWINGINT_DPS,
  128. "name": "number_calibration_swing_internal",
  129. "min": 0.5,
  130. "max": 2.5,
  131. "scale": 10,
  132. "step": 0.1,
  133. "unit": TEMP_CELSIUS,
  134. },
  135. {
  136. "dps": CALIBSWINGEXT_DPS,
  137. "name": "number_calibration_swing_external",
  138. "min": 0.1,
  139. "max": 1.0,
  140. "scale": 10,
  141. "step": 0.1,
  142. "unit": TEMP_CELSIUS,
  143. },
  144. {
  145. "dps": HIGHTEMP_DPS,
  146. "name": "number_high_temperature_protection",
  147. "min": 35,
  148. "max": 70,
  149. "unit": TEMP_CELSIUS,
  150. },
  151. {
  152. "dps": LOWTEMP_DPS,
  153. "name": "number_low_temperature_protection",
  154. "min": 1,
  155. "max": 10,
  156. "unit": TEMP_CELSIUS,
  157. },
  158. {
  159. "dps": MINTEMP_DPS,
  160. "name": "number_low_temperature_limit",
  161. "min": 1,
  162. "max": 10,
  163. "unit": TEMP_CELSIUS,
  164. },
  165. {
  166. "dps": MAXTEMP_DPS,
  167. "name": "number_high_temperature_limit",
  168. "min": 2,
  169. "max": 70,
  170. "unit": TEMP_CELSIUS,
  171. },
  172. ],
  173. )
  174. self.mark_secondary(
  175. [
  176. "lock_child_lock",
  177. "number_holiday_days",
  178. "number_holiday_temperature",
  179. "number_calibration_offset",
  180. "number_calibration_swing_internal",
  181. "number_calibration_swing_external",
  182. "number_high_temperature_protection",
  183. "number_low_temperature_protection",
  184. "number_low_temperature_limit",
  185. "number_high_temperature_limit",
  186. "select_temperature_sensor",
  187. "select_initial_state",
  188. "select_schedule",
  189. ],
  190. )
  191. def test_supported_features(self):
  192. self.assertEqual(
  193. self.subject.supported_features,
  194. (
  195. ClimateEntityFeature.PRESET_MODE
  196. | ClimateEntityFeature.TARGET_TEMPERATURE
  197. ),
  198. )
  199. def test_current_temperature(self):
  200. self.dps[CURRENTTEMP_DPS] = 685
  201. self.assertEqual(self.subject.current_temperature, 68.5)
  202. def test_hvac_mode(self):
  203. self.dps[HVACMODE_DPS] = False
  204. self.assertEqual(self.subject.hvac_mode, HVACMode.OFF)
  205. self.dps[HVACMODE_DPS] = True
  206. self.assertEqual(self.subject.hvac_mode, HVACMode.HEAT)
  207. def test_hvac_modes(self):
  208. self.assertCountEqual(
  209. self.subject.hvac_modes,
  210. [
  211. HVACMode.HEAT,
  212. HVACMode.OFF,
  213. ],
  214. )
  215. async def test_set_hvac_mode_heat(self):
  216. async with assert_device_properties_set(
  217. self.subject._device,
  218. {HVACMODE_DPS: True},
  219. ):
  220. await self.subject.async_set_hvac_mode(HVACMode.HEAT)
  221. async def test_set_hvac_mode_off(self):
  222. async with assert_device_properties_set(
  223. self.subject._device,
  224. {HVACMODE_DPS: False},
  225. ):
  226. await self.subject.async_set_hvac_mode(HVACMode.OFF)
  227. def test_hvac_action(self):
  228. self.dps[HVACMODE_DPS] = True
  229. self.dps[HVACACTION_DPS] = True
  230. self.assertEqual(self.subject.hvac_action, HVACAction.HEATING)
  231. self.dps[HVACACTION_DPS] = False
  232. self.assertEqual(self.subject.hvac_action, HVACAction.IDLE)
  233. self.dps[HVACMODE_DPS] = False
  234. self.assertEqual(self.subject.hvac_action, HVACAction.OFF)
  235. def test_preset_modes(self):
  236. self.assertCountEqual(
  237. self.subject.preset_modes,
  238. ["Manual", "Program", "Program Override", "Holiday"],
  239. )
  240. def test_preset_mode(self):
  241. self.dps[PRESET_DPS] = "Manual"
  242. self.assertEqual(self.subject.preset_mode, "Manual")
  243. self.dps[PRESET_DPS] = "Program"
  244. self.assertEqual(self.subject.preset_mode, "Program")
  245. self.dps[PRESET_DPS] = "TempProg"
  246. self.assertEqual(self.subject.preset_mode, "Program Override")
  247. self.dps[PRESET_DPS] = "Holiday"
  248. self.assertEqual(self.subject.preset_mode, "Holiday")
  249. # Override - since min and max are set by attributes, the range
  250. # allowed when setting is wider than normal. The thermostat seems
  251. # to be configurable as at least a water heater (to 212F), as tuya
  252. # doc says max 1000.0 (after scaling)
  253. async def test_set_target_temperature_fails_outside_valid_range(self):
  254. with self.assertRaisesRegex(
  255. ValueError,
  256. f"temperature \\(0\\) must be between 0.5 and 122.0",
  257. ):
  258. await self.subject.async_set_target_temperature(0)
  259. with self.assertRaisesRegex(
  260. ValueError,
  261. f"temperature \\(122.5\\) must be between 0.5 and 122.0",
  262. ):
  263. await self.subject.async_set_target_temperature(122.5)
  264. def test_extra_state_attributes(self):
  265. self.dps[UNKNOWN12_DPS] = 12
  266. self.dps[UNKNOWN101_DPS] = True
  267. self.dps[UNKNOWN106_DPS] = False
  268. self.dps[UNKNOWN107_DPS] = True
  269. self.dps[UNKNOWN108_DPS] = False
  270. self.assertDictEqual(
  271. self.subject.extra_state_attributes,
  272. {
  273. "unknown_12": 12,
  274. "unknown_101": True,
  275. "unknown_106": False,
  276. "unknown_107": True,
  277. "unknown_108": False,
  278. },
  279. )
  280. def test_icons(self):
  281. self.dps[LOCK_DPS] = True
  282. self.assertEqual(self.basicLock.icon, "mdi:hand-back-right-off")
  283. self.dps[LOCK_DPS] = False
  284. self.assertEqual(self.basicLock.icon, "mdi:hand-back-right")