test_wetair_wch750_heater.py 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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.setUpBasicSelect(
  55. TIMER_DPS,
  56. self.entities.get("select_timer"),
  57. {
  58. "0h": "Off",
  59. "1h": "1 hour",
  60. "2h": "2 hours",
  61. "3h": "3 hours",
  62. "4h": "4 hours",
  63. "5h": "5 hours",
  64. "6h": "6 hours",
  65. "7h": "7 hours",
  66. "8h": "8 hours",
  67. "9h": "9 hours",
  68. "10h": "10 hours",
  69. "11h": "11 hours",
  70. "12h": "12 hours",
  71. "13h": "13 hours",
  72. "14h": "14 hours",
  73. "15h": "15 hours",
  74. "16h": "16 hours",
  75. "17h": "17 hours",
  76. "18h": "18 hours",
  77. "19h": "19 hours",
  78. "20h": "20 hours",
  79. "21h": "21 hours",
  80. "22h": "22 hours",
  81. "23h": "23 hours",
  82. "24h": "24 hours",
  83. },
  84. )
  85. self.setUpBasicSensor(
  86. COUNTDOWN_DPS, self.entities.get("sensor_timer"), unit=TIME_MINUTES
  87. )
  88. self.mark_secondary(
  89. [
  90. "light_display",
  91. "select_timer",
  92. "sensor_timer",
  93. ]
  94. )
  95. def test_supported_features(self):
  96. self.assertEqual(
  97. self.subject.supported_features,
  98. SUPPORT_TARGET_TEMPERATURE | SUPPORT_PRESET_MODE,
  99. )
  100. def test_icon(self):
  101. self.dps[HVACMODE_DPS] = True
  102. self.assertEqual(self.subject.icon, "mdi:radiator")
  103. self.dps[HVACMODE_DPS] = False
  104. self.assertEqual(self.subject.icon, "mdi:radiator-disabled")
  105. def test_temperatre_unit_retrns_device_temperatre_unit(self):
  106. self.assertEqual(
  107. self.subject.temperature_unit, self.subject._device.temperature_unit
  108. )
  109. def test_target_temperature_in_af_mode(self):
  110. self.dps[TEMPERATURE_DPS] = 25
  111. self.dps[PRESET_DPS] = "mod_antiforst"
  112. self.assertEqual(self.subject.target_temperature, None)
  113. async def test_legacy_set_temperature_with_preset_mode(self):
  114. async with assert_device_properties_set(
  115. self.subject._device, {PRESET_DPS: "mod_antiforst"}
  116. ):
  117. await self.subject.async_set_temperature(preset_mode=PRESET_AWAY)
  118. async def test_legacy_set_temperature_with_both_properties(self):
  119. async with assert_device_properties_set(
  120. self.subject._device,
  121. {TEMPERATURE_DPS: 25, PRESET_DPS: "mod_max12h"},
  122. ):
  123. await self.subject.async_set_temperature(
  124. preset_mode=PRESET_BOOST, temperature=25
  125. )
  126. async def test_set_target_temperature_fails_in_anti_frost(self):
  127. self.dps[PRESET_DPS] = "mod_antiforst"
  128. with self.assertRaisesRegex(
  129. AttributeError, "temperature cannot be set at this time"
  130. ):
  131. await self.subject.async_set_target_temperature(25)
  132. def test_current_temperature_not_supported(self):
  133. self.assertIsNone(self.subject.current_temperature)
  134. def test_hvac_mode(self):
  135. self.dps[HVACMODE_DPS] = True
  136. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_HEAT)
  137. self.dps[HVACMODE_DPS] = False
  138. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_OFF)
  139. self.dps[HVACMODE_DPS] = None
  140. self.assertEqual(self.subject.hvac_mode, STATE_UNAVAILABLE)
  141. def test_hvac_modes(self):
  142. self.assertCountEqual(self.subject.hvac_modes, [HVAC_MODE_OFF, HVAC_MODE_HEAT])
  143. async def test_turn_on(self):
  144. async with assert_device_properties_set(
  145. self.subject._device,
  146. {HVACMODE_DPS: True},
  147. ):
  148. await self.subject.async_set_hvac_mode(HVAC_MODE_HEAT)
  149. async def test_turn_off(self):
  150. async with assert_device_properties_set(
  151. self.subject._device,
  152. {HVACMODE_DPS: False},
  153. ):
  154. await self.subject.async_set_hvac_mode(HVAC_MODE_OFF)
  155. def test_preset_mode(self):
  156. self.dps[PRESET_DPS] = "mod_free"
  157. self.assertEqual(self.subject.preset_mode, PRESET_COMFORT)
  158. self.dps[PRESET_DPS] = "mod_max12h"
  159. self.assertEqual(self.subject.preset_mode, PRESET_BOOST)
  160. self.dps[PRESET_DPS] = "mod_antiforst"
  161. self.assertEqual(self.subject.preset_mode, PRESET_AWAY)
  162. def test_preset_modes(self):
  163. self.assertCountEqual(self.subject.preset_modes, ["comfort", "boost", "away"])
  164. async def test_set_preset_mode_to_comfort(self):
  165. async with assert_device_properties_set(
  166. self.subject._device,
  167. {PRESET_DPS: "mod_free"},
  168. ):
  169. await self.subject.async_set_preset_mode(PRESET_COMFORT)
  170. async def test_set_preset_mode_to_boost(self):
  171. async with assert_device_properties_set(
  172. self.subject._device,
  173. {PRESET_DPS: "mod_max12h"},
  174. ):
  175. await self.subject.async_set_preset_mode(PRESET_BOOST)
  176. async def test_set_preset_mode_to_away(self):
  177. async with assert_device_properties_set(
  178. self.subject._device,
  179. {PRESET_DPS: "mod_antiforst"},
  180. ):
  181. await self.subject.async_set_preset_mode(PRESET_AWAY)
  182. def test_extra_state_attributes(self):
  183. self.dps[TIMER_DPS] = "1h"
  184. self.dps[COUNTDOWN_DPS] = 20
  185. self.dps[UNKNOWN21_DPS] = 21
  186. self.assertDictEqual(
  187. self.subject.extra_state_attributes,
  188. {
  189. "timer": "1h",
  190. "countdown": 20,
  191. "unknown_21": 21,
  192. },
  193. )
  194. def test_light_icon(self):
  195. self.assertEqual(self.dimmableLight.icon, None)
  196. async def test_light_brightness_snaps(self):
  197. async with assert_device_properties_set(
  198. self.dimmableLight._device,
  199. {BRIGHTNESS_DPS: "level1"},
  200. ):
  201. await self.dimmableLight.async_turn_on(brightness=100)