test_wetair_wch750_heater.py 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. from homeassistant.components.climate.const import (
  2. ClimateEntityFeature,
  3. HVACMode,
  4. PRESET_AWAY,
  5. PRESET_COMFORT,
  6. PRESET_BOOST,
  7. )
  8. from homeassistant.const import TIME_MINUTES
  9. from ..const import WETAIR_WCH750_HEATER_PAYLOAD
  10. from ..helpers import assert_device_properties_set
  11. from ..mixins.climate import TargetTemperatureTests
  12. from ..mixins.light import DimmableLightTests
  13. from ..mixins.select import BasicSelectTests
  14. from ..mixins.sensor import BasicSensorTests
  15. from .base_device_tests import TuyaDeviceTestCase
  16. HVACMODE_DPS = "1"
  17. TEMPERATURE_DPS = "2"
  18. PRESET_DPS = "4"
  19. HVACACTION_DPS = "11"
  20. TIMER_DPS = "19"
  21. COUNTDOWN_DPS = "20"
  22. UNKNOWN21_DPS = "21"
  23. BRIGHTNESS_DPS = "101"
  24. class TestWetairWCH750Heater(
  25. BasicSelectTests,
  26. BasicSensorTests,
  27. DimmableLightTests,
  28. TargetTemperatureTests,
  29. TuyaDeviceTestCase,
  30. ):
  31. __test__ = True
  32. def setUp(self):
  33. self.setUpForConfig("wetair_wch750_heater.yaml", WETAIR_WCH750_HEATER_PAYLOAD)
  34. self.subject = self.entities.get("climate")
  35. self.setUpTargetTemperature(
  36. TEMPERATURE_DPS,
  37. self.subject,
  38. min=10,
  39. max=35,
  40. )
  41. self.setUpDimmableLight(
  42. BRIGHTNESS_DPS,
  43. self.entities.get("light_display"),
  44. offval="level0",
  45. tests=[
  46. ("level1", 85),
  47. ("level2", 170),
  48. ("level3", 255),
  49. ],
  50. )
  51. self.setUpBasicSelect(
  52. TIMER_DPS,
  53. self.entities.get("select_timer"),
  54. {
  55. "0h": "Off",
  56. "1h": "1 hour",
  57. "2h": "2 hours",
  58. "3h": "3 hours",
  59. "4h": "4 hours",
  60. "5h": "5 hours",
  61. "6h": "6 hours",
  62. "7h": "7 hours",
  63. "8h": "8 hours",
  64. "9h": "9 hours",
  65. "10h": "10 hours",
  66. "11h": "11 hours",
  67. "12h": "12 hours",
  68. "13h": "13 hours",
  69. "14h": "14 hours",
  70. "15h": "15 hours",
  71. "16h": "16 hours",
  72. "17h": "17 hours",
  73. "18h": "18 hours",
  74. "19h": "19 hours",
  75. "20h": "20 hours",
  76. "21h": "21 hours",
  77. "22h": "22 hours",
  78. "23h": "23 hours",
  79. "24h": "24 hours",
  80. },
  81. )
  82. self.setUpBasicSensor(
  83. COUNTDOWN_DPS, self.entities.get("sensor_timer"), unit=TIME_MINUTES
  84. )
  85. self.mark_secondary(
  86. [
  87. "light_display",
  88. "select_timer",
  89. "sensor_timer",
  90. ]
  91. )
  92. def test_supported_features(self):
  93. self.assertEqual(
  94. self.subject.supported_features,
  95. (
  96. ClimateEntityFeature.TARGET_TEMPERATURE
  97. | ClimateEntityFeature.PRESET_MODE
  98. ),
  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, HVACMode.HEAT)
  137. self.dps[HVACMODE_DPS] = False
  138. self.assertEqual(self.subject.hvac_mode, HVACMode.OFF)
  139. def test_hvac_modes(self):
  140. self.assertCountEqual(self.subject.hvac_modes, [HVACMode.OFF, HVACMode.HEAT])
  141. async def test_turn_on(self):
  142. async with assert_device_properties_set(
  143. self.subject._device,
  144. {HVACMODE_DPS: True},
  145. ):
  146. await self.subject.async_set_hvac_mode(HVACMode.HEAT)
  147. async def test_turn_off(self):
  148. async with assert_device_properties_set(
  149. self.subject._device,
  150. {HVACMODE_DPS: False},
  151. ):
  152. await self.subject.async_set_hvac_mode(HVACMode.OFF)
  153. def test_preset_mode(self):
  154. self.dps[PRESET_DPS] = "mod_free"
  155. self.assertEqual(self.subject.preset_mode, PRESET_COMFORT)
  156. self.dps[PRESET_DPS] = "mod_max12h"
  157. self.assertEqual(self.subject.preset_mode, PRESET_BOOST)
  158. self.dps[PRESET_DPS] = "mod_antiforst"
  159. self.assertEqual(self.subject.preset_mode, PRESET_AWAY)
  160. def test_preset_modes(self):
  161. self.assertCountEqual(self.subject.preset_modes, ["comfort", "boost", "away"])
  162. async def test_set_preset_mode_to_comfort(self):
  163. async with assert_device_properties_set(
  164. self.subject._device,
  165. {PRESET_DPS: "mod_free"},
  166. ):
  167. await self.subject.async_set_preset_mode(PRESET_COMFORT)
  168. async def test_set_preset_mode_to_boost(self):
  169. async with assert_device_properties_set(
  170. self.subject._device,
  171. {PRESET_DPS: "mod_max12h"},
  172. ):
  173. await self.subject.async_set_preset_mode(PRESET_BOOST)
  174. async def test_set_preset_mode_to_away(self):
  175. async with assert_device_properties_set(
  176. self.subject._device,
  177. {PRESET_DPS: "mod_antiforst"},
  178. ):
  179. await self.subject.async_set_preset_mode(PRESET_AWAY)
  180. def test_extra_state_attributes(self):
  181. self.dps[TIMER_DPS] = "1h"
  182. self.dps[COUNTDOWN_DPS] = 20
  183. self.dps[UNKNOWN21_DPS] = 21
  184. self.assertDictEqual(
  185. self.subject.extra_state_attributes,
  186. {
  187. "timer": "1h",
  188. "countdown": 20,
  189. "unknown_21": 21,
  190. },
  191. )
  192. def test_light_icon(self):
  193. self.assertEqual(self.dimmableLight.icon, None)
  194. async def test_light_brightness_snaps(self):
  195. async with assert_device_properties_set(
  196. self.dimmableLight._device,
  197. {BRIGHTNESS_DPS: "level1"},
  198. ):
  199. await self.dimmableLight.async_turn_on(brightness=100)