test_purline_m100_heater.py 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  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.components.switch import DEVICE_CLASS_SWITCH
  13. from homeassistant.const import STATE_UNAVAILABLE
  14. from ..const import PURLINE_M100_HEATER_PAYLOAD
  15. from ..helpers import (
  16. assert_device_properties_set,
  17. assert_device_properties_set_optional,
  18. )
  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(BasicSwitchTests, TuyaDeviceTestCase):
  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. # BasicLightTests mixin not used due to inverted switch
  36. self.light = self.entities.get("light_display")
  37. self.setUpBasicSwitch(
  38. SWITCH_DPS, self.entities.get("switch_open_window_detector")
  39. )
  40. def test_supported_features(self):
  41. self.assertEqual(
  42. self.subject.supported_features,
  43. SUPPORT_TARGET_TEMPERATURE | SUPPORT_PRESET_MODE | SUPPORT_SWING_MODE,
  44. )
  45. def test_icon(self):
  46. self.dps[HVACMODE_DPS] = True
  47. self.dps[PRESET_DPS] = "auto"
  48. self.assertEqual(self.subject.icon, "mdi:radiator")
  49. self.dps[HVACMODE_DPS] = False
  50. self.assertEqual(self.subject.icon, "mdi:radiator-disabled")
  51. self.dps[HVACMODE_DPS] = True
  52. self.dps[PRESET_DPS] = "off"
  53. self.assertEqual(self.subject.icon, "mdi:fan")
  54. def test_temperature_unit_returns_device_temperature_unit(self):
  55. self.assertEqual(
  56. self.subject.temperature_unit, self.subject._device.temperature_unit
  57. )
  58. def test_target_temperature(self):
  59. self.dps[TEMPERATURE_DPS] = 25
  60. self.assertEqual(self.subject.target_temperature, 25)
  61. def test_target_temperature_step(self):
  62. self.assertEqual(self.subject.target_temperature_step, 1)
  63. def test_minimum_target_temperature(self):
  64. self.assertEqual(self.subject.min_temp, 15)
  65. def test_maximum_target_temperature(self):
  66. self.assertEqual(self.subject.max_temp, 35)
  67. async def test_legacy_set_temperature_with_temperature(self):
  68. async with assert_device_properties_set(
  69. self.subject._device, {TEMPERATURE_DPS: 25}
  70. ):
  71. await self.subject.async_set_temperature(temperature=25)
  72. async def test_legacy_set_temperature_with_no_valid_properties(self):
  73. await self.subject.async_set_temperature(something="else")
  74. self.subject._device.async_set_property.assert_not_called()
  75. async def test_set_target_temperature(self):
  76. async with assert_device_properties_set(
  77. self.subject._device, {TEMPERATURE_DPS: 25}
  78. ):
  79. await self.subject.async_set_target_temperature(25)
  80. async def test_set_target_temperature_rounds_value_to_closest_integer(self):
  81. async with assert_device_properties_set(
  82. self.subject._device,
  83. {TEMPERATURE_DPS: 25},
  84. ):
  85. await self.subject.async_set_target_temperature(24.6)
  86. async def test_set_target_temperature_fails_outside_valid_range(self):
  87. with self.assertRaisesRegex(
  88. ValueError, "temperature \\(4\\) must be between 15 and 35"
  89. ):
  90. await self.subject.async_set_target_temperature(4)
  91. with self.assertRaisesRegex(
  92. ValueError, "temperature \\(36\\) must be between 15 and 35"
  93. ):
  94. await self.subject.async_set_target_temperature(36)
  95. def test_current_temperature(self):
  96. self.dps[CURRENTTEMP_DPS] = 25
  97. self.assertEqual(self.subject.current_temperature, 25)
  98. def test_hvac_mode(self):
  99. self.dps[HVACMODE_DPS] = True
  100. self.dps[PRESET_DPS] = "auto"
  101. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_HEAT)
  102. self.dps[PRESET_DPS] = "off"
  103. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_FAN_ONLY)
  104. self.dps[HVACMODE_DPS] = False
  105. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_OFF)
  106. self.dps[HVACMODE_DPS] = None
  107. self.assertEqual(self.subject.hvac_mode, STATE_UNAVAILABLE)
  108. def test_hvac_modes(self):
  109. self.assertCountEqual(
  110. self.subject.hvac_modes,
  111. [HVAC_MODE_OFF, HVAC_MODE_HEAT, HVAC_MODE_FAN_ONLY],
  112. )
  113. async def test_turn_on(self):
  114. async with assert_device_properties_set_optional(
  115. self.subject._device,
  116. {HVACMODE_DPS: True},
  117. {PRESET_DPS: "auto"},
  118. ):
  119. await self.subject.async_set_hvac_mode(HVAC_MODE_HEAT)
  120. async def test_turn_off(self):
  121. async with assert_device_properties_set(
  122. self.subject._device,
  123. {HVACMODE_DPS: False},
  124. ):
  125. await self.subject.async_set_hvac_mode(HVAC_MODE_OFF)
  126. async def test_turn_on_fan(self):
  127. async with assert_device_properties_set_optional(
  128. self.subject._device,
  129. {HVACMODE_DPS: True},
  130. {PRESET_DPS: "off"},
  131. ):
  132. await self.subject.async_set_hvac_mode(HVAC_MODE_FAN_ONLY)
  133. def test_preset_mode(self):
  134. self.dps[PRESET_DPS] = "auto"
  135. self.assertEqual(self.subject.preset_mode, "Auto")
  136. self.dps[PRESET_DPS] = "off"
  137. self.assertEqual(self.subject.preset_mode, "Fan")
  138. self.dps[PRESET_DPS] = "4"
  139. self.assertEqual(self.subject.preset_mode, "4")
  140. self.dps[PRESET_DPS] = None
  141. self.assertIs(self.subject.preset_mode, None)
  142. def test_preset_modes(self):
  143. self.assertCountEqual(
  144. self.subject.preset_modes,
  145. ["Fan", "1", "2", "3", "4", "5", "Auto"],
  146. )
  147. async def test_set_preset_mode_numeric(self):
  148. async with assert_device_properties_set(
  149. self.subject._device,
  150. {PRESET_DPS: "3"},
  151. ):
  152. await self.subject.async_set_preset_mode("3")
  153. def test_swing_mode(self):
  154. self.dps[SWING_DPS] = True
  155. self.assertEqual(self.subject.swing_mode, SWING_VERTICAL)
  156. self.dps[SWING_DPS] = False
  157. self.assertEqual(self.subject.swing_mode, SWING_OFF)
  158. def test_swing_modes(self):
  159. self.assertCountEqual(
  160. self.subject.swing_modes,
  161. [SWING_OFF, SWING_VERTICAL],
  162. )
  163. async def test_set_swing_mode_on(self):
  164. async with assert_device_properties_set(
  165. self.subject._device, {SWING_DPS: True}
  166. ):
  167. await self.subject.async_set_swing_mode(SWING_VERTICAL)
  168. async def test_set_swing_mode_off(self):
  169. async with assert_device_properties_set(
  170. self.subject._device, {SWING_DPS: False}
  171. ):
  172. await self.subject.async_set_swing_mode(SWING_OFF)
  173. def test_light_supported_color_modes(self):
  174. self.assertCountEqual(
  175. self.light.supported_color_modes,
  176. [COLOR_MODE_ONOFF],
  177. )
  178. def test_light_color_mode(self):
  179. self.assertEqual(self.light.color_mode, COLOR_MODE_ONOFF)
  180. def test_light_icon(self):
  181. self.dps[LIGHTOFF_DPS] = False
  182. self.assertEqual(self.light.icon, "mdi:led-on")
  183. self.dps[LIGHTOFF_DPS] = True
  184. self.assertEqual(self.light.icon, "mdi:led-off")
  185. def test_light_is_on(self):
  186. self.dps[LIGHTOFF_DPS] = False
  187. self.assertTrue(self.light.is_on)
  188. self.dps[LIGHTOFF_DPS] = True
  189. self.assertFalse(self.light.is_on)
  190. def test_light_state_attributes(self):
  191. self.assertEqual(self.light.device_state_attributes, {})
  192. async def test_light_turn_on(self):
  193. async with assert_device_properties_set(
  194. self.light._device, {LIGHTOFF_DPS: False}
  195. ):
  196. await self.light.async_turn_on()
  197. async def test_light_turn_off(self):
  198. async with assert_device_properties_set(
  199. self.light._device, {LIGHTOFF_DPS: True}
  200. ):
  201. await self.light.async_turn_off()
  202. async def test_toggle_turns_the_light_on_when_it_was_off(self):
  203. self.dps[LIGHTOFF_DPS] = True
  204. async with assert_device_properties_set(
  205. self.light._device, {LIGHTOFF_DPS: False}
  206. ):
  207. await self.light.async_toggle()
  208. async def test_toggle_turns_the_light_off_when_it_was_on(self):
  209. self.dps[LIGHTOFF_DPS] = False
  210. async with assert_device_properties_set(
  211. self.light._device, {LIGHTOFF_DPS: True}
  212. ):
  213. await self.light.async_toggle()