test_motion_sensor_light.py 5.0 KB

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