test_purline_m100_heater.py 7.0 KB

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