test_motion_sensor_light.py 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. from homeassistant.const import LIGHT_LUX, UnitOfTime
  2. from ..const import MOTION_LIGHT_PAYLOAD
  3. from ..helpers import assert_device_properties_set
  4. from ..mixins.number import MultiNumberTests
  5. from ..mixins.switch import BasicSwitchTests
  6. from .base_device_tests import TuyaDeviceTestCase
  7. EFFECT_DPS = "101"
  8. SWITCH_DPS = "102"
  9. PROX_DPS = "103"
  10. TIME_DPS = "104"
  11. LUX_DPS = "105"
  12. RESET_DPS = "106"
  13. class TestMotionLight(BasicSwitchTests, MultiNumberTests, TuyaDeviceTestCase):
  14. __test__ = True
  15. def setUp(self):
  16. self.setUpForConfig("motion_sensor_light.yaml", MOTION_LIGHT_PAYLOAD)
  17. self.subject = self.entities.get("light")
  18. self.auto_sw = self.entities.get("switch_auto_mode")
  19. self.setUpBasicSwitch(RESET_DPS, self.entities.get("switch_auto_reset"))
  20. self.setUpMultiNumber(
  21. [
  22. {
  23. "dps": PROX_DPS,
  24. "name": "number_sensitivity",
  25. "min": 0,
  26. "max": 4,
  27. "testdata": (1, 3),
  28. },
  29. {
  30. "dps": TIME_DPS,
  31. "name": "number_duration",
  32. "min": 10,
  33. "max": 900,
  34. "step": 10,
  35. "unit": UnitOfTime.SECONDS,
  36. },
  37. {
  38. "dps": LUX_DPS,
  39. "name": "number_light_level",
  40. "min": 0,
  41. "max": 3900,
  42. "unit": LIGHT_LUX,
  43. "testdata": (1900, 2000),
  44. },
  45. ]
  46. )
  47. self.mark_secondary(
  48. [
  49. "number_duration",
  50. "number_light_level",
  51. "number_sensitivity",
  52. "switch_auto_reset",
  53. ]
  54. )
  55. def test_effects(self):
  56. self.assertCountEqual(
  57. self.subject.effect_list,
  58. ["auto", "off", "on"],
  59. )
  60. def test_effect(self):
  61. self.dps[EFFECT_DPS] = "mode_on"
  62. self.assertEqual(self.subject.effect, "on")
  63. self.dps[EFFECT_DPS] = "mode_off"
  64. self.assertEqual(self.subject.effect, "off")
  65. self.dps[EFFECT_DPS] = "mode_auto"
  66. self.assertEqual(self.subject.effect, "auto")
  67. def test_is_on_reflects_switch(self):
  68. self.dps[SWITCH_DPS] = True
  69. self.assertTrue(self.subject.is_on)
  70. self.dps[SWITCH_DPS] = False
  71. self.assertFalse(self.subject.is_on)
  72. async def test_turn_on_via_effect(self):
  73. self.dps[SWITCH_DPS] = False
  74. async with assert_device_properties_set(
  75. self.subject._device,
  76. {EFFECT_DPS: "mode_on"},
  77. ):
  78. await self.subject.async_turn_on()
  79. async def test_turn_off_via_effect(self):
  80. async with assert_device_properties_set(
  81. self.subject._device,
  82. {EFFECT_DPS: "mode_off"},
  83. ):
  84. await self.subject.async_turn_off()
  85. async def test_set_to_auto(self):
  86. async with assert_device_properties_set(
  87. self.subject._device,
  88. {EFFECT_DPS: "mode_auto"},
  89. ):
  90. await self.subject.async_turn_on(effect="auto")
  91. def test_auto_mode_is_on(self):
  92. self.dps[SWITCH_DPS] = False
  93. self.dps[EFFECT_DPS] = "mode_auto"
  94. self.assertTrue(self.auto_sw.is_on)
  95. self.assertFalse(self.subject.is_on)
  96. self.dps[EFFECT_DPS] = "mode_off"
  97. self.assertFalse(self.auto_sw.is_on)
  98. self.assertFalse(self.subject.is_on)
  99. self.dps[SWITCH_DPS] = True
  100. self.dps[EFFECT_DPS] = "mode_auto"
  101. self.assertTrue(self.auto_sw.is_on)
  102. self.assertTrue(self.subject.is_on)
  103. self.dps[EFFECT_DPS] = "mode_on"
  104. self.assertFalse(self.auto_sw.is_on)
  105. self.assertTrue(self.subject.is_on)
  106. async def test_auto_mode_async_turn_on_off(self):
  107. self.dps[SWITCH_DPS] = True
  108. self.dps[EFFECT_DPS] = "mode_auto"
  109. async with assert_device_properties_set(
  110. self.subject._device,
  111. {EFFECT_DPS: "mode_on"},
  112. ):
  113. await self.auto_sw.async_turn_off()
  114. self.dps[SWITCH_DPS] = False
  115. self.dps[EFFECT_DPS] = "mode_auto"
  116. async with assert_device_properties_set(
  117. self.subject._device,
  118. {EFFECT_DPS: "mode_off"},
  119. ):
  120. await self.auto_sw.async_turn_off()
  121. self.dps[SWITCH_DPS] = True
  122. self.dps[EFFECT_DPS] = "mode_on"
  123. async with assert_device_properties_set(
  124. self.subject._device,
  125. {EFFECT_DPS: "mode_auto"},
  126. ):
  127. await self.auto_sw.async_turn_on()
  128. self.dps[SWITCH_DPS] = False
  129. self.dps[EFFECT_DPS] = "mode_off"
  130. async with assert_device_properties_set(
  131. self.subject._device,
  132. {EFFECT_DPS: "mode_auto"},
  133. ):
  134. await self.auto_sw.async_turn_on()