test_renpho_rp_ap001s.py 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. from homeassistant.components.fan import SUPPORT_PRESET_MODE
  2. from homeassistant.components.light import COLOR_MODE_ONOFF
  3. from homeassistant.components.lock import STATE_LOCKED, STATE_UNLOCKED
  4. from homeassistant.const import STATE_UNAVAILABLE
  5. from ..const import RENPHO_PURIFIER_PAYLOAD
  6. from ..helpers import assert_device_properties_set
  7. from .base_device_tests import TuyaDeviceTestCase
  8. SWITCH_DPS = "1"
  9. PRESET_DPS = "4"
  10. LOCK_DPS = "7"
  11. LIGHT_DPS = "8"
  12. TIMER_DPS = "19"
  13. QUALITY_DPS = "22"
  14. SLEEP_DPS = "101"
  15. PREFILTER_DPS = "102"
  16. CHARCOAL_DPS = "103"
  17. ACTIVATED_DPS = "104"
  18. HEPA_DPS = "105"
  19. class TestRenphoPurifier(TuyaDeviceTestCase):
  20. __test__ = True
  21. def setUp(self):
  22. self.setUpForConfig("renpho_rp_ap001s.yaml", RENPHO_PURIFIER_PAYLOAD)
  23. self.subject = self.entities["fan"]
  24. self.light = self.entities["light"]
  25. self.lock = self.entities["lock"]
  26. self.switch = self.entities["switch"]
  27. def test_supported_features(self):
  28. self.assertEqual(self.subject.supported_features, SUPPORT_PRESET_MODE)
  29. def test_is_on(self):
  30. self.dps[SWITCH_DPS] = True
  31. self.assertTrue(self.subject.is_on)
  32. self.dps[SWITCH_DPS] = False
  33. self.assertFalse(self.subject.is_on)
  34. self.dps[SWITCH_DPS] = None
  35. self.assertEqual(self.subject.is_on, STATE_UNAVAILABLE)
  36. async def test_turn_on(self):
  37. async with assert_device_properties_set(
  38. self.subject._device,
  39. {SWITCH_DPS: True},
  40. ):
  41. await self.subject.async_turn_on()
  42. async def test_turn_off(self):
  43. async with assert_device_properties_set(
  44. self.subject._device,
  45. {SWITCH_DPS: False},
  46. ):
  47. await self.subject.async_turn_off()
  48. def test_preset_modes(self):
  49. self.assertCountEqual(
  50. self.subject.preset_modes,
  51. ["low", "mid", "high", "auto"],
  52. )
  53. def test_preset_mode(self):
  54. self.dps[PRESET_DPS] = "low"
  55. self.assertEqual(self.subject.preset_mode, "low")
  56. self.dps[PRESET_DPS] = "mid"
  57. self.assertEqual(self.subject.preset_mode, "mid")
  58. self.dps[PRESET_DPS] = "high"
  59. self.assertEqual(self.subject.preset_mode, "high")
  60. self.dps[PRESET_DPS] = "auto"
  61. self.assertEqual(self.subject.preset_mode, "auto")
  62. async def test_set_preset_mode_to_low(self):
  63. async with assert_device_properties_set(
  64. self.subject._device,
  65. {PRESET_DPS: "low"},
  66. ):
  67. await self.subject.async_set_preset_mode("low")
  68. async def test_set_preset_mode_to_mid(self):
  69. async with assert_device_properties_set(
  70. self.subject._device,
  71. {PRESET_DPS: "mid"},
  72. ):
  73. await self.subject.async_set_preset_mode("mid")
  74. async def test_set_preset_mode_to_high(self):
  75. async with assert_device_properties_set(
  76. self.subject._device,
  77. {PRESET_DPS: "high"},
  78. ):
  79. await self.subject.async_set_preset_mode("high")
  80. async def test_set_preset_mode_to_auto(self):
  81. async with assert_device_properties_set(
  82. self.subject._device,
  83. {PRESET_DPS: "auto"},
  84. ):
  85. await self.subject.async_set_preset_mode("auto")
  86. def test_device_state_attributes(self):
  87. self.dps[TIMER_DPS] = "19"
  88. self.dps[QUALITY_DPS] = "22"
  89. self.dps[PREFILTER_DPS] = 102
  90. self.dps[CHARCOAL_DPS] = 103
  91. self.dps[ACTIVATED_DPS] = 104
  92. self.dps[HEPA_DPS] = 105
  93. self.assertDictEqual(
  94. self.subject.device_state_attributes,
  95. {
  96. "timer": "19",
  97. "air_quality": "22",
  98. "prefilter_life": 102,
  99. "charcoal_filter_life": 103,
  100. "activated_charcoal_filter_life": 104,
  101. "hepa_filter_life": 105,
  102. },
  103. )
  104. def test_lock_state(self):
  105. self.dps[LOCK_DPS] = True
  106. self.assertEqual(self.lock.state, STATE_LOCKED)
  107. self.dps[LOCK_DPS] = False
  108. self.assertEqual(self.lock.state, STATE_UNLOCKED)
  109. self.dps[LOCK_DPS] = None
  110. self.assertEqual(self.lock.state, STATE_UNAVAILABLE)
  111. def test_lock_is_locked(self):
  112. self.dps[LOCK_DPS] = True
  113. self.assertTrue(self.lock.is_locked)
  114. self.dps[LOCK_DPS] = False
  115. self.assertFalse(self.lock.is_locked)
  116. self.dps[LOCK_DPS] = None
  117. self.assertFalse(self.lock.is_locked)
  118. async def test_lock_locks(self):
  119. async with assert_device_properties_set(
  120. self.lock._device,
  121. {LOCK_DPS: True},
  122. ):
  123. await self.lock.async_lock()
  124. async def test_lock_unlocks(self):
  125. async with assert_device_properties_set(
  126. self.lock._device,
  127. {LOCK_DPS: False},
  128. ):
  129. await self.lock.async_unlock()
  130. def test_light_supported_color_modes(self):
  131. self.assertCountEqual(
  132. self.light.supported_color_modes,
  133. [COLOR_MODE_ONOFF],
  134. )
  135. def test_light_color_mode(self):
  136. self.assertEqual(self.light.color_mode, COLOR_MODE_ONOFF)
  137. def test_light_has_no_brightness(self):
  138. self.assertIsNone(self.light.brightness)
  139. def test_light_icon(self):
  140. self.dps[LIGHT_DPS] = True
  141. self.assertEqual(self.light.icon, "mdi:led-on")
  142. self.dps[LIGHT_DPS] = False
  143. self.assertEqual(self.light.icon, "mdi:led-off")
  144. def test_light_is_on(self):
  145. self.dps[LIGHT_DPS] = True
  146. self.assertEqual(self.light.is_on, True)
  147. self.dps[LIGHT_DPS] = False
  148. self.assertEqual(self.light.is_on, False)
  149. async def test_light_turn_on(self):
  150. async with assert_device_properties_set(self.light._device, {LIGHT_DPS: True}):
  151. await self.light.async_turn_on()
  152. async def test_light_turn_off(self):
  153. async with assert_device_properties_set(self.light._device, {LIGHT_DPS: False}):
  154. await self.light.async_turn_off()
  155. async def test_toggle_turns_the_light_on_when_it_was_off(self):
  156. self.dps[LIGHT_DPS] = False
  157. async with assert_device_properties_set(self.light._device, {LIGHT_DPS: True}):
  158. await self.light.async_toggle()
  159. async def test_toggle_turns_the_light_off_when_it_was_on(self):
  160. self.dps[LIGHT_DPS] = True
  161. async with assert_device_properties_set(self.light._device, {LIGHT_DPS: False}):
  162. await self.light.async_toggle()
  163. def test_switch_icon(self):
  164. self.assertEqual(self.switch.icon, "mdi:power-sleep")
  165. def test_switch_is_on(self):
  166. self.dps[SLEEP_DPS] = True
  167. self.assertEqual(self.switch.is_on, True)
  168. self.dps[SLEEP_DPS] = False
  169. self.assertEqual(self.switch.is_on, False)
  170. def test_switch_state_attributes(self):
  171. self.assertEqual(self.switch.device_state_attributes, {})
  172. async def test_switch_turn_on(self):
  173. async with assert_device_properties_set(self.switch._device, {SLEEP_DPS: True}):
  174. await self.switch.async_turn_on()
  175. async def test_switch_turn_off(self):
  176. async with assert_device_properties_set(
  177. self.switch._device, {SLEEP_DPS: False}
  178. ):
  179. await self.switch.async_turn_off()
  180. async def test_toggle_turns_the_switch_on_when_it_was_off(self):
  181. self.dps[SLEEP_DPS] = False
  182. async with assert_device_properties_set(self.switch._device, {SLEEP_DPS: True}):
  183. await self.switch.async_toggle()
  184. async def test_toggle_turns_the_switch_off_when_it_was_on(self):
  185. self.dps[SLEEP_DPS] = True
  186. async with assert_device_properties_set(
  187. self.switch._device, {SLEEP_DPS: False}
  188. ):
  189. await self.switch.async_toggle()