test_wetair_wch750_heater.py 7.2 KB

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