test_wetair_wch750_heater.py 7.7 KB

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