test_motion_sensor_light.py 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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. "min": 10,
  34. "max": 900,
  35. "step": 10,
  36. "unit": UnitOfTime.SECONDS,
  37. },
  38. {
  39. "dps": LUX_DPS,
  40. "name": "number_light_level",
  41. "device_class": NumberDeviceClass.ILLUMINANCE,
  42. "min": 0,
  43. "max": 3900,
  44. "unit": LIGHT_LUX,
  45. "testdata": (1900, 2000),
  46. },
  47. ]
  48. )
  49. self.mark_secondary(
  50. [
  51. "number_duration",
  52. "number_light_level",
  53. "number_sensitivity",
  54. "switch_auto_reset",
  55. ]
  56. )
  57. def test_effects(self):
  58. self.assertCountEqual(
  59. self.subject.effect_list,
  60. ["auto", "off", "on"],
  61. )
  62. def test_effect(self):
  63. self.dps[EFFECT_DPS] = "mode_on"
  64. self.assertEqual(self.subject.effect, "on")
  65. self.dps[EFFECT_DPS] = "mode_off"
  66. self.assertEqual(self.subject.effect, "off")
  67. self.dps[EFFECT_DPS] = "mode_auto"
  68. self.assertEqual(self.subject.effect, "auto")
  69. def test_is_on_reflects_switch(self):
  70. self.dps[SWITCH_DPS] = True
  71. self.assertTrue(self.subject.is_on)
  72. self.dps[SWITCH_DPS] = False
  73. self.assertFalse(self.subject.is_on)
  74. async def test_turn_on_via_effect(self):
  75. self.dps[SWITCH_DPS] = False
  76. async with assert_device_properties_set(
  77. self.subject._device,
  78. {EFFECT_DPS: "mode_on"},
  79. ):
  80. await self.subject.async_turn_on()
  81. async def test_turn_off_via_effect(self):
  82. async with assert_device_properties_set(
  83. self.subject._device,
  84. {EFFECT_DPS: "mode_off"},
  85. ):
  86. await self.subject.async_turn_off()
  87. async def test_set_to_auto(self):
  88. async with assert_device_properties_set(
  89. self.subject._device,
  90. {EFFECT_DPS: "mode_auto"},
  91. ):
  92. await self.subject.async_turn_on(effect="auto")
  93. def test_auto_mode_is_on(self):
  94. self.dps[SWITCH_DPS] = False
  95. self.dps[EFFECT_DPS] = "mode_auto"
  96. self.assertTrue(self.auto_sw.is_on)
  97. self.assertFalse(self.subject.is_on)
  98. self.dps[EFFECT_DPS] = "mode_off"
  99. self.assertFalse(self.auto_sw.is_on)
  100. self.assertFalse(self.subject.is_on)
  101. self.dps[SWITCH_DPS] = True
  102. self.dps[EFFECT_DPS] = "mode_auto"
  103. self.assertTrue(self.auto_sw.is_on)
  104. self.assertTrue(self.subject.is_on)
  105. self.dps[EFFECT_DPS] = "mode_on"
  106. self.assertFalse(self.auto_sw.is_on)
  107. self.assertTrue(self.subject.is_on)
  108. async def test_auto_mode_async_turn_on_off(self):
  109. self.dps[SWITCH_DPS] = True
  110. self.dps[EFFECT_DPS] = "mode_auto"
  111. async with assert_device_properties_set(
  112. self.subject._device,
  113. {EFFECT_DPS: "mode_on"},
  114. ):
  115. await self.auto_sw.async_turn_off()
  116. self.dps[SWITCH_DPS] = False
  117. self.dps[EFFECT_DPS] = "mode_auto"
  118. async with assert_device_properties_set(
  119. self.subject._device,
  120. {EFFECT_DPS: "mode_off"},
  121. ):
  122. await self.auto_sw.async_turn_off()
  123. self.dps[SWITCH_DPS] = True
  124. self.dps[EFFECT_DPS] = "mode_on"
  125. async with assert_device_properties_set(
  126. self.subject._device,
  127. {EFFECT_DPS: "mode_auto"},
  128. ):
  129. await self.auto_sw.async_turn_on()
  130. self.dps[SWITCH_DPS] = False
  131. self.dps[EFFECT_DPS] = "mode_off"
  132. async with assert_device_properties_set(
  133. self.subject._device,
  134. {EFFECT_DPS: "mode_auto"},
  135. ):
  136. await self.auto_sw.async_turn_on()