test_purline_m100_heater.py 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. from homeassistant.components.climate.const import (
  2. ClimateEntityFeature,
  3. HVACMode,
  4. SWING_OFF,
  5. SWING_VERTICAL,
  6. )
  7. from homeassistant.components.light import ColorMode
  8. from ..const import PURLINE_M100_HEATER_PAYLOAD
  9. from ..helpers import (
  10. assert_device_properties_set,
  11. assert_device_properties_set_optional,
  12. )
  13. from ..mixins.climate import TargetTemperatureTests
  14. from ..mixins.switch import BasicSwitchTests
  15. from .base_device_tests import TuyaDeviceTestCase
  16. HVACMODE_DPS = "1"
  17. TEMPERATURE_DPS = "2"
  18. CURRENTTEMP_DPS = "3"
  19. PRESET_DPS = "5"
  20. LIGHTOFF_DPS = "10"
  21. TIMERHR_DPS = "11"
  22. TIMER_DPS = "12"
  23. SWITCH_DPS = "101"
  24. SWING_DPS = "102"
  25. class TestPulineM100Heater(
  26. BasicSwitchTests,
  27. TargetTemperatureTests,
  28. TuyaDeviceTestCase,
  29. ):
  30. __test__ = True
  31. def setUp(self):
  32. self.setUpForConfig("purline_m100_heater.yaml", PURLINE_M100_HEATER_PAYLOAD)
  33. self.subject = self.entities.get("climate")
  34. self.setUpTargetTemperature(
  35. TEMPERATURE_DPS,
  36. self.subject,
  37. min=15,
  38. max=35,
  39. )
  40. # BasicLightTests mixin not used due to inverted switch
  41. self.light = self.entities.get("light_display")
  42. self.setUpBasicSwitch(
  43. SWITCH_DPS, self.entities.get("switch_open_window_detector")
  44. )
  45. self.mark_secondary(["light_display", "switch_open_window_detector"])
  46. def test_supported_features(self):
  47. self.assertEqual(
  48. self.subject.supported_features,
  49. (
  50. ClimateEntityFeature.TARGET_TEMPERATURE
  51. | ClimateEntityFeature.PRESET_MODE
  52. | ClimateEntityFeature.SWING_MODE
  53. ),
  54. )
  55. def test_icon(self):
  56. self.dps[HVACMODE_DPS] = True
  57. self.dps[PRESET_DPS] = "auto"
  58. self.assertEqual(self.subject.icon, "mdi:radiator")
  59. self.dps[HVACMODE_DPS] = False
  60. self.assertEqual(self.subject.icon, "mdi:radiator-disabled")
  61. self.dps[HVACMODE_DPS] = True
  62. self.dps[PRESET_DPS] = "off"
  63. self.assertEqual(self.subject.icon, "mdi:fan")
  64. def test_temperature_unit_returns_device_temperature_unit(self):
  65. self.assertEqual(
  66. self.subject.temperature_unit, self.subject._device.temperature_unit
  67. )
  68. def test_current_temperature(self):
  69. self.dps[CURRENTTEMP_DPS] = 25
  70. self.assertEqual(self.subject.current_temperature, 25)
  71. def test_hvac_mode(self):
  72. self.dps[HVACMODE_DPS] = True
  73. self.dps[PRESET_DPS] = "auto"
  74. self.assertEqual(self.subject.hvac_mode, HVACMode.HEAT)
  75. self.dps[PRESET_DPS] = "off"
  76. self.assertEqual(self.subject.hvac_mode, HVACMode.FAN_ONLY)
  77. self.dps[HVACMODE_DPS] = False
  78. self.assertEqual(self.subject.hvac_mode, HVACMode.OFF)
  79. def test_hvac_modes(self):
  80. self.assertCountEqual(
  81. self.subject.hvac_modes,
  82. [HVACMode.OFF, HVACMode.HEAT, HVACMode.FAN_ONLY],
  83. )
  84. async def test_turn_on(self):
  85. async with assert_device_properties_set_optional(
  86. self.subject._device,
  87. {HVACMODE_DPS: True},
  88. {PRESET_DPS: "auto"},
  89. ):
  90. await self.subject.async_set_hvac_mode(HVACMode.HEAT)
  91. async def test_turn_off(self):
  92. async with assert_device_properties_set(
  93. self.subject._device,
  94. {HVACMODE_DPS: False},
  95. ):
  96. await self.subject.async_set_hvac_mode(HVACMode.OFF)
  97. async def test_turn_on_fan(self):
  98. async with assert_device_properties_set_optional(
  99. self.subject._device,
  100. {HVACMODE_DPS: True},
  101. {PRESET_DPS: "off"},
  102. ):
  103. await self.subject.async_set_hvac_mode(HVACMode.FAN_ONLY)
  104. def test_preset_mode(self):
  105. self.dps[PRESET_DPS] = "auto"
  106. self.assertEqual(self.subject.preset_mode, "Auto")
  107. self.dps[PRESET_DPS] = "off"
  108. self.assertEqual(self.subject.preset_mode, "Fan")
  109. self.dps[PRESET_DPS] = "4"
  110. self.assertEqual(self.subject.preset_mode, "4")
  111. self.dps[PRESET_DPS] = None
  112. self.assertIs(self.subject.preset_mode, None)
  113. def test_preset_modes(self):
  114. self.assertCountEqual(
  115. self.subject.preset_modes,
  116. ["Fan", "1", "2", "3", "4", "5", "Auto"],
  117. )
  118. async def test_set_preset_mode_numeric(self):
  119. async with assert_device_properties_set(
  120. self.subject._device,
  121. {PRESET_DPS: "3"},
  122. ):
  123. await self.subject.async_set_preset_mode("3")
  124. def test_swing_mode(self):
  125. self.dps[SWING_DPS] = True
  126. self.assertEqual(self.subject.swing_mode, SWING_VERTICAL)
  127. self.dps[SWING_DPS] = False
  128. self.assertEqual(self.subject.swing_mode, SWING_OFF)
  129. def test_swing_modes(self):
  130. self.assertCountEqual(
  131. self.subject.swing_modes,
  132. [SWING_OFF, SWING_VERTICAL],
  133. )
  134. async def test_set_swing_mode_on(self):
  135. async with assert_device_properties_set(
  136. self.subject._device, {SWING_DPS: True}
  137. ):
  138. await self.subject.async_set_swing_mode(SWING_VERTICAL)
  139. async def test_set_swing_mode_off(self):
  140. async with assert_device_properties_set(
  141. self.subject._device, {SWING_DPS: False}
  142. ):
  143. await self.subject.async_set_swing_mode(SWING_OFF)
  144. def test_light_supported_color_modes(self):
  145. self.assertCountEqual(
  146. self.light.supported_color_modes,
  147. [ColorMode.ONOFF],
  148. )
  149. def test_light_color_mode(self):
  150. self.assertEqual(self.light.color_mode, ColorMode.ONOFF)
  151. def test_light_icon(self):
  152. self.dps[LIGHTOFF_DPS] = False
  153. self.assertEqual(self.light.icon, "mdi:led-on")
  154. self.dps[LIGHTOFF_DPS] = True
  155. self.assertEqual(self.light.icon, "mdi:led-off")
  156. def test_light_is_on(self):
  157. self.dps[LIGHTOFF_DPS] = False
  158. self.assertTrue(self.light.is_on)
  159. self.dps[LIGHTOFF_DPS] = True
  160. self.assertFalse(self.light.is_on)
  161. def test_light_state_attributes(self):
  162. self.assertEqual(self.light.extra_state_attributes, {})
  163. async def test_light_turn_on(self):
  164. async with assert_device_properties_set(
  165. self.light._device, {LIGHTOFF_DPS: False}
  166. ):
  167. await self.light.async_turn_on()
  168. async def test_light_turn_off(self):
  169. async with assert_device_properties_set(
  170. self.light._device, {LIGHTOFF_DPS: True}
  171. ):
  172. await self.light.async_turn_off()
  173. async def test_toggle_turns_the_light_on_when_it_was_off(self):
  174. self.dps[LIGHTOFF_DPS] = True
  175. async with assert_device_properties_set(
  176. self.light._device, {LIGHTOFF_DPS: False}
  177. ):
  178. await self.light.async_toggle()
  179. async def test_toggle_turns_the_light_off_when_it_was_on(self):
  180. self.dps[LIGHTOFF_DPS] = False
  181. async with assert_device_properties_set(
  182. self.light._device, {LIGHTOFF_DPS: True}
  183. ):
  184. await self.light.async_toggle()