test_wetair_wch750_heater.py 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. from homeassistant.components.climate.const import (
  2. PRESET_AWAY,
  3. PRESET_BOOST,
  4. PRESET_COMFORT,
  5. ClimateEntityFeature,
  6. HVACMode,
  7. )
  8. from homeassistant.components.sensor import SensorDeviceClass
  9. from homeassistant.const import UnitOfTemperature, UnitOfTime
  10. from ..const import WETAIR_WCH750_HEATER_PAYLOAD
  11. from ..helpers import assert_device_properties_set
  12. from ..mixins.climate import TargetTemperatureTests
  13. from ..mixins.light import DimmableLightTests
  14. from ..mixins.select import BasicSelectTests
  15. from ..mixins.sensor import BasicSensorTests
  16. from .base_device_tests import TuyaDeviceTestCase
  17. HVACMODE_DPS = "1"
  18. TEMPERATURE_DPS = "2"
  19. PRESET_DPS = "4"
  20. HVACACTION_DPS = "11"
  21. TIMER_DPS = "19"
  22. COUNTDOWN_DPS = "20"
  23. UNKNOWN21_DPS = "21"
  24. BRIGHTNESS_DPS = "101"
  25. class TestWetairWCH750Heater(
  26. BasicSelectTests,
  27. BasicSensorTests,
  28. DimmableLightTests,
  29. TargetTemperatureTests,
  30. TuyaDeviceTestCase,
  31. ):
  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.0,
  39. max=35.0,
  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": "cancel",
  56. "1h": "1h",
  57. "2h": "2h",
  58. "3h": "3h",
  59. "4h": "4h",
  60. "5h": "5h",
  61. "6h": "6h",
  62. "7h": "7h",
  63. "8h": "8h",
  64. "9h": "9h",
  65. "10h": "10h",
  66. "11h": "11h",
  67. "12h": "12h",
  68. "13h": "13h",
  69. "14h": "14h",
  70. "15h": "15h",
  71. "16h": "16h",
  72. "17h": "17h",
  73. "18h": "18h",
  74. "19h": "19h",
  75. "20h": "20h",
  76. "21h": "21h",
  77. "22h": "22h",
  78. "23h": "23h",
  79. "24h": "24h",
  80. },
  81. )
  82. self.setUpBasicSensor(
  83. COUNTDOWN_DPS,
  84. self.entities.get("sensor_time_remaining"),
  85. unit=UnitOfTime.MINUTES,
  86. device_class=SensorDeviceClass.DURATION,
  87. )
  88. self.mark_secondary(
  89. [
  90. "light_display",
  91. "select_timer",
  92. "sensor_time_remaining",
  93. ]
  94. )
  95. def test_supported_features(self):
  96. self.assertEqual(
  97. self.subject.supported_features,
  98. (
  99. ClimateEntityFeature.TARGET_TEMPERATURE
  100. | ClimateEntityFeature.PRESET_MODE
  101. | ClimateEntityFeature.TURN_OFF
  102. | ClimateEntityFeature.TURN_ON
  103. ),
  104. )
  105. def test_temperatre_unit_retrns_device_temperatre_unit(self):
  106. self.assertEqual(self.subject.temperature_unit, UnitOfTemperature.CELSIUS)
  107. def test_target_temperature_in_af_mode(self):
  108. self.dps[TEMPERATURE_DPS] = 25
  109. self.dps[PRESET_DPS] = "mod_antiforst"
  110. self.assertEqual(self.subject.target_temperature, None)
  111. async def test_legacy_set_temperature_with_preset_mode(self):
  112. async with assert_device_properties_set(
  113. self.subject._device, {PRESET_DPS: "mod_antiforst"}
  114. ):
  115. await self.subject.async_set_temperature(preset_mode=PRESET_AWAY)
  116. async def test_legacy_set_temperature_with_both_properties(self):
  117. async with assert_device_properties_set(
  118. self.subject._device,
  119. {TEMPERATURE_DPS: 25, PRESET_DPS: "mod_max12h"},
  120. ):
  121. await self.subject.async_set_temperature(
  122. preset_mode=PRESET_BOOST, temperature=25
  123. )
  124. async def test_set_target_temperature_fails_in_anti_frost(self):
  125. self.dps[PRESET_DPS] = "mod_antiforst"
  126. with self.assertRaisesRegex(
  127. AttributeError, "temperature cannot be set at this time"
  128. ):
  129. await self.subject.async_set_target_temperature(25)
  130. def test_current_temperature_not_supported(self):
  131. self.assertIsNone(self.subject.current_temperature)
  132. def test_hvac_mode(self):
  133. self.dps[HVACMODE_DPS] = True
  134. self.assertEqual(self.subject.hvac_mode, HVACMode.HEAT)
  135. self.dps[HVACMODE_DPS] = False
  136. self.assertEqual(self.subject.hvac_mode, HVACMode.OFF)
  137. def test_hvac_modes(self):
  138. self.assertCountEqual(self.subject.hvac_modes, [HVACMode.OFF, HVACMode.HEAT])
  139. async def test_turn_on(self):
  140. async with assert_device_properties_set(
  141. self.subject._device,
  142. {HVACMODE_DPS: True},
  143. ):
  144. await self.subject.async_set_hvac_mode(HVACMode.HEAT)
  145. async def test_turn_off(self):
  146. async with assert_device_properties_set(
  147. self.subject._device,
  148. {HVACMODE_DPS: False},
  149. ):
  150. await self.subject.async_set_hvac_mode(HVACMode.OFF)
  151. def test_preset_mode(self):
  152. self.dps[PRESET_DPS] = "mod_free"
  153. self.assertEqual(self.subject.preset_mode, PRESET_COMFORT)
  154. self.dps[PRESET_DPS] = "mod_max12h"
  155. self.assertEqual(self.subject.preset_mode, PRESET_BOOST)
  156. self.dps[PRESET_DPS] = "mod_antiforst"
  157. self.assertEqual(self.subject.preset_mode, PRESET_AWAY)
  158. def test_preset_modes(self):
  159. self.assertCountEqual(self.subject.preset_modes, ["comfort", "boost", "away"])
  160. async def test_set_preset_mode_to_comfort(self):
  161. async with assert_device_properties_set(
  162. self.subject._device,
  163. {PRESET_DPS: "mod_free"},
  164. ):
  165. await self.subject.async_set_preset_mode(PRESET_COMFORT)
  166. async def test_set_preset_mode_to_boost(self):
  167. async with assert_device_properties_set(
  168. self.subject._device,
  169. {PRESET_DPS: "mod_max12h"},
  170. ):
  171. await self.subject.async_set_preset_mode(PRESET_BOOST)
  172. async def test_set_preset_mode_to_away(self):
  173. async with assert_device_properties_set(
  174. self.subject._device,
  175. {PRESET_DPS: "mod_antiforst"},
  176. ):
  177. await self.subject.async_set_preset_mode(PRESET_AWAY)
  178. def test_extra_state_attributes(self):
  179. self.dps[UNKNOWN21_DPS] = 21
  180. self.assertDictEqual(
  181. self.subject.extra_state_attributes,
  182. {
  183. "unknown_21": 21,
  184. },
  185. )
  186. def test_light_icon(self):
  187. self.assertEqual(self.dimmableLight.icon, None)
  188. async def test_light_brightness_snaps(self):
  189. async with assert_device_properties_set(
  190. self.dimmableLight._device,
  191. {BRIGHTNESS_DPS: "level1"},
  192. ):
  193. await self.dimmableLight.async_turn_on(brightness=100)