test_wetair_wch750_heater.py 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. from homeassistant.components.climate.const import (
  2. HVAC_MODE_HEAT,
  3. HVAC_MODE_OFF,
  4. PRESET_AWAY,
  5. PRESET_COMFORT,
  6. PRESET_BOOST,
  7. SUPPORT_PRESET_MODE,
  8. SUPPORT_TARGET_TEMPERATURE,
  9. )
  10. from homeassistant.components.light import COLOR_MODE_BRIGHTNESS
  11. from homeassistant.const import STATE_UNAVAILABLE, TIME_MINUTES
  12. from ..const import WETAIR_WCH750_HEATER_PAYLOAD
  13. from ..helpers import assert_device_properties_set
  14. from ..mixins.climate import TargetTemperatureTests
  15. from ..mixins.light import DimmableLightTests
  16. from ..mixins.select import BasicSelectTests
  17. from ..mixins.sensor import BasicSensorTests
  18. from .base_device_tests import TuyaDeviceTestCase
  19. HVACMODE_DPS = "1"
  20. TEMPERATURE_DPS = "2"
  21. PRESET_DPS = "4"
  22. HVACACTION_DPS = "11"
  23. TIMER_DPS = "19"
  24. COUNTDOWN_DPS = "20"
  25. UNKNOWN21_DPS = "21"
  26. BRIGHTNESS_DPS = "101"
  27. class TestWetairWCH750Heater(
  28. BasicSelectTests,
  29. BasicSensorTests,
  30. DimmableLightTests,
  31. TargetTemperatureTests,
  32. TuyaDeviceTestCase,
  33. ):
  34. __test__ = True
  35. def setUp(self):
  36. self.setUpForConfig("wetair_wch750_heater.yaml", WETAIR_WCH750_HEATER_PAYLOAD)
  37. self.subject = self.entities.get("climate")
  38. self.setUpTargetTemperature(
  39. TEMPERATURE_DPS,
  40. self.subject,
  41. min=10,
  42. max=35,
  43. )
  44. self.setUpDimmableLight(
  45. BRIGHTNESS_DPS,
  46. self.entities.get("light_display"),
  47. offval="level0",
  48. tests=[
  49. ("level1", 85),
  50. ("level2", 170),
  51. ("level3", 255),
  52. ],
  53. )
  54. self.light = self.entities.get("light_display")
  55. self.setUpBasicSelect(
  56. TIMER_DPS,
  57. self.entities.get("select_timer"),
  58. {
  59. "0h": "Off",
  60. "1h": "1 hour",
  61. "2h": "2 hours",
  62. "3h": "3 hours",
  63. "4h": "4 hours",
  64. "5h": "5 hours",
  65. "6h": "6 hours",
  66. "7h": "7 hours",
  67. "8h": "8 hours",
  68. "9h": "9 hours",
  69. "10h": "10 hours",
  70. "11h": "11 hours",
  71. "12h": "12 hours",
  72. "13h": "13 hours",
  73. "14h": "14 hours",
  74. "15h": "15 hours",
  75. "16h": "16 hours",
  76. "17h": "17 hours",
  77. "18h": "18 hours",
  78. "19h": "19 hours",
  79. "20h": "20 hours",
  80. "21h": "21 hours",
  81. "22h": "22 hours",
  82. "23h": "23 hours",
  83. "24h": "24 hours",
  84. },
  85. )
  86. self.setUpBasicSensor(
  87. COUNTDOWN_DPS, self.entities.get("sensor_timer"), unit=TIME_MINUTES
  88. )
  89. def test_supported_features(self):
  90. self.assertEqual(
  91. self.subject.supported_features,
  92. SUPPORT_TARGET_TEMPERATURE | SUPPORT_PRESET_MODE,
  93. )
  94. def test_icon(self):
  95. self.dps[HVACMODE_DPS] = True
  96. self.assertEqual(self.subject.icon, "mdi:radiator")
  97. self.dps[HVACMODE_DPS] = False
  98. self.assertEqual(self.subject.icon, "mdi:radiator-disabled")
  99. def test_temperatre_unit_retrns_device_temperatre_unit(self):
  100. self.assertEqual(
  101. self.subject.temperature_unit, self.subject._device.temperature_unit
  102. )
  103. def test_target_temperature_in_af_mode(self):
  104. self.dps[TEMPERATURE_DPS] = 25
  105. self.dps[PRESET_DPS] = "mod_antiforst"
  106. self.assertEqual(self.subject.target_temperature, None)
  107. async def test_legacy_set_temperature_with_preset_mode(self):
  108. async with assert_device_properties_set(
  109. self.subject._device, {PRESET_DPS: "mod_antiforst"}
  110. ):
  111. await self.subject.async_set_temperature(preset_mode=PRESET_AWAY)
  112. async def test_legacy_set_temperature_with_both_properties(self):
  113. async with assert_device_properties_set(
  114. self.subject._device,
  115. {TEMPERATURE_DPS: 25, PRESET_DPS: "mod_max12h"},
  116. ):
  117. await self.subject.async_set_temperature(
  118. preset_mode=PRESET_BOOST, temperature=25
  119. )
  120. async def test_set_target_temperature_fails_in_anti_frost(self):
  121. self.dps[PRESET_DPS] = "mod_antiforst"
  122. with self.assertRaisesRegex(
  123. AttributeError, "temperature cannot be set at this time"
  124. ):
  125. await self.subject.async_set_target_temperature(25)
  126. def test_current_temperature_not_supported(self):
  127. self.assertIsNone(self.subject.current_temperature)
  128. def test_hvac_mode(self):
  129. self.dps[HVACMODE_DPS] = True
  130. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_HEAT)
  131. self.dps[HVACMODE_DPS] = False
  132. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_OFF)
  133. self.dps[HVACMODE_DPS] = None
  134. self.assertEqual(self.subject.hvac_mode, STATE_UNAVAILABLE)
  135. def test_hvac_modes(self):
  136. self.assertCountEqual(self.subject.hvac_modes, [HVAC_MODE_OFF, HVAC_MODE_HEAT])
  137. async def test_turn_on(self):
  138. async with assert_device_properties_set(
  139. self.subject._device,
  140. {HVACMODE_DPS: True},
  141. ):
  142. await self.subject.async_set_hvac_mode(HVAC_MODE_HEAT)
  143. async def test_turn_off(self):
  144. async with assert_device_properties_set(
  145. self.subject._device,
  146. {HVACMODE_DPS: False},
  147. ):
  148. await self.subject.async_set_hvac_mode(HVAC_MODE_OFF)
  149. def test_preset_mode(self):
  150. self.dps[PRESET_DPS] = "mod_free"
  151. self.assertEqual(self.subject.preset_mode, PRESET_COMFORT)
  152. self.dps[PRESET_DPS] = "mod_max12h"
  153. self.assertEqual(self.subject.preset_mode, PRESET_BOOST)
  154. self.dps[PRESET_DPS] = "mod_antiforst"
  155. self.assertEqual(self.subject.preset_mode, PRESET_AWAY)
  156. def test_preset_modes(self):
  157. self.assertCountEqual(self.subject.preset_modes, ["comfort", "boost", "away"])
  158. async def test_set_preset_mode_to_comfort(self):
  159. async with assert_device_properties_set(
  160. self.subject._device,
  161. {PRESET_DPS: "mod_free"},
  162. ):
  163. await self.subject.async_set_preset_mode(PRESET_COMFORT)
  164. async def test_set_preset_mode_to_boost(self):
  165. async with assert_device_properties_set(
  166. self.subject._device,
  167. {PRESET_DPS: "mod_max12h"},
  168. ):
  169. await self.subject.async_set_preset_mode(PRESET_BOOST)
  170. async def test_set_preset_mode_to_away(self):
  171. async with assert_device_properties_set(
  172. self.subject._device,
  173. {PRESET_DPS: "mod_antiforst"},
  174. ):
  175. await self.subject.async_set_preset_mode(PRESET_AWAY)
  176. def test_device_state_attributes(self):
  177. self.dps[TIMER_DPS] = "1h"
  178. self.dps[COUNTDOWN_DPS] = 20
  179. self.dps[UNKNOWN21_DPS] = 21
  180. self.assertDictEqual(
  181. self.subject.device_state_attributes,
  182. {
  183. "timer": "1h",
  184. "countdown": 20,
  185. "unknown_21": 21,
  186. },
  187. )
  188. def test_light_icon(self):
  189. self.assertEqual(self.dimmableLight.icon, None)
  190. async def test_light_brightness_snaps(self):
  191. async with assert_device_properties_set(
  192. self.dimmableLight._device,
  193. {BRIGHTNESS_DPS: "level1"},
  194. ):
  195. await self.dimmableLight.async_turn_on(brightness=100)