test_purline_m100_heater.py 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  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. def test_supported_features(self):
  51. self.assertEqual(
  52. self.subject.supported_features,
  53. SUPPORT_TARGET_TEMPERATURE | SUPPORT_PRESET_MODE | SUPPORT_SWING_MODE,
  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, HVAC_MODE_HEAT)
  75. self.dps[PRESET_DPS] = "off"
  76. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_FAN_ONLY)
  77. self.dps[HVACMODE_DPS] = False
  78. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_OFF)
  79. self.dps[HVACMODE_DPS] = None
  80. self.assertEqual(self.subject.hvac_mode, STATE_UNAVAILABLE)
  81. def test_hvac_modes(self):
  82. self.assertCountEqual(
  83. self.subject.hvac_modes,
  84. [HVAC_MODE_OFF, HVAC_MODE_HEAT, HVAC_MODE_FAN_ONLY],
  85. )
  86. async def test_turn_on(self):
  87. async with assert_device_properties_set_optional(
  88. self.subject._device,
  89. {HVACMODE_DPS: True},
  90. {PRESET_DPS: "auto"},
  91. ):
  92. await self.subject.async_set_hvac_mode(HVAC_MODE_HEAT)
  93. async def test_turn_off(self):
  94. async with assert_device_properties_set(
  95. self.subject._device,
  96. {HVACMODE_DPS: False},
  97. ):
  98. await self.subject.async_set_hvac_mode(HVAC_MODE_OFF)
  99. async def test_turn_on_fan(self):
  100. async with assert_device_properties_set_optional(
  101. self.subject._device,
  102. {HVACMODE_DPS: True},
  103. {PRESET_DPS: "off"},
  104. ):
  105. await self.subject.async_set_hvac_mode(HVAC_MODE_FAN_ONLY)
  106. def test_preset_mode(self):
  107. self.dps[PRESET_DPS] = "auto"
  108. self.assertEqual(self.subject.preset_mode, "Auto")
  109. self.dps[PRESET_DPS] = "off"
  110. self.assertEqual(self.subject.preset_mode, "Fan")
  111. self.dps[PRESET_DPS] = "4"
  112. self.assertEqual(self.subject.preset_mode, "4")
  113. self.dps[PRESET_DPS] = None
  114. self.assertIs(self.subject.preset_mode, None)
  115. def test_preset_modes(self):
  116. self.assertCountEqual(
  117. self.subject.preset_modes,
  118. ["Fan", "1", "2", "3", "4", "5", "Auto"],
  119. )
  120. async def test_set_preset_mode_numeric(self):
  121. async with assert_device_properties_set(
  122. self.subject._device,
  123. {PRESET_DPS: "3"},
  124. ):
  125. await self.subject.async_set_preset_mode("3")
  126. def test_swing_mode(self):
  127. self.dps[SWING_DPS] = True
  128. self.assertEqual(self.subject.swing_mode, SWING_VERTICAL)
  129. self.dps[SWING_DPS] = False
  130. self.assertEqual(self.subject.swing_mode, SWING_OFF)
  131. def test_swing_modes(self):
  132. self.assertCountEqual(
  133. self.subject.swing_modes,
  134. [SWING_OFF, SWING_VERTICAL],
  135. )
  136. async def test_set_swing_mode_on(self):
  137. async with assert_device_properties_set(
  138. self.subject._device, {SWING_DPS: True}
  139. ):
  140. await self.subject.async_set_swing_mode(SWING_VERTICAL)
  141. async def test_set_swing_mode_off(self):
  142. async with assert_device_properties_set(
  143. self.subject._device, {SWING_DPS: False}
  144. ):
  145. await self.subject.async_set_swing_mode(SWING_OFF)
  146. def test_light_supported_color_modes(self):
  147. self.assertCountEqual(
  148. self.light.supported_color_modes,
  149. [COLOR_MODE_ONOFF],
  150. )
  151. def test_light_color_mode(self):
  152. self.assertEqual(self.light.color_mode, COLOR_MODE_ONOFF)
  153. def test_light_icon(self):
  154. self.dps[LIGHTOFF_DPS] = False
  155. self.assertEqual(self.light.icon, "mdi:led-on")
  156. self.dps[LIGHTOFF_DPS] = True
  157. self.assertEqual(self.light.icon, "mdi:led-off")
  158. def test_light_is_on(self):
  159. self.dps[LIGHTOFF_DPS] = False
  160. self.assertTrue(self.light.is_on)
  161. self.dps[LIGHTOFF_DPS] = True
  162. self.assertFalse(self.light.is_on)
  163. def test_light_state_attributes(self):
  164. self.assertEqual(self.light.device_state_attributes, {})
  165. async def test_light_turn_on(self):
  166. async with assert_device_properties_set(
  167. self.light._device, {LIGHTOFF_DPS: False}
  168. ):
  169. await self.light.async_turn_on()
  170. async def test_light_turn_off(self):
  171. async with assert_device_properties_set(
  172. self.light._device, {LIGHTOFF_DPS: True}
  173. ):
  174. await self.light.async_turn_off()
  175. async def test_toggle_turns_the_light_on_when_it_was_off(self):
  176. self.dps[LIGHTOFF_DPS] = True
  177. async with assert_device_properties_set(
  178. self.light._device, {LIGHTOFF_DPS: False}
  179. ):
  180. await self.light.async_toggle()
  181. async def test_toggle_turns_the_light_off_when_it_was_on(self):
  182. self.dps[LIGHTOFF_DPS] = False
  183. async with assert_device_properties_set(
  184. self.light._device, {LIGHTOFF_DPS: True}
  185. ):
  186. await self.light.async_toggle()