test_purline_m100_heater.py 7.1 KB

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