test_motion_sensor_light.py 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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.setUpBasicSwitch(RESET_DPS, self.entities.get("switch_auto_reset"))
  19. self.setUpMultiNumber(
  20. [
  21. {
  22. "dps": PROX_DPS,
  23. "name": "number_sensitivity",
  24. "min": 0,
  25. "max": 4,
  26. "testdata": (1, 3),
  27. },
  28. {
  29. "dps": TIME_DPS,
  30. "name": "number_duration",
  31. "min": 10,
  32. "max": 900,
  33. "step": 10,
  34. "unit": UnitOfTime.SECONDS,
  35. },
  36. {
  37. "dps": LUX_DPS,
  38. "name": "number_light_level",
  39. "min": 0,
  40. "max": 3900,
  41. "unit": LIGHT_LUX,
  42. "testdata": (1900, 2000),
  43. },
  44. ]
  45. )
  46. self.mark_secondary(
  47. [
  48. "number_duration",
  49. "number_light_level",
  50. "number_sensitivity",
  51. "switch_auto_reset",
  52. ]
  53. )
  54. def test_effects(self):
  55. self.assertCountEqual(
  56. self.subject.effect_list,
  57. ["auto", "off", "on"],
  58. )
  59. def test_effect(self):
  60. self.dps[EFFECT_DPS] = "mode_on"
  61. self.assertEqual(self.subject.effect, "on")
  62. self.dps[EFFECT_DPS] = "mode_off"
  63. self.assertEqual(self.subject.effect, "off")
  64. self.dps[EFFECT_DPS] = "mode_auto"
  65. self.assertEqual(self.subject.effect, "auto")
  66. def test_is_on_reflects_switch(self):
  67. self.dps[SWITCH_DPS] = True
  68. self.assertTrue(self.subject.is_on)
  69. self.dps[SWITCH_DPS] = False
  70. self.assertFalse(self.subject.is_on)
  71. async def test_turn_on_via_effect(self):
  72. self.dps[SWITCH_DPS] = False
  73. async with assert_device_properties_set(
  74. self.subject._device,
  75. {EFFECT_DPS: "mode_on"},
  76. ):
  77. await self.subject.async_turn_on()
  78. async def test_turn_off_via_effect(self):
  79. async with assert_device_properties_set(
  80. self.subject._device,
  81. {EFFECT_DPS: "mode_off"},
  82. ):
  83. await self.subject.async_turn_off()
  84. async def test_set_to_auto(self):
  85. async with assert_device_properties_set(
  86. self.subject._device,
  87. {EFFECT_DPS: "mode_auto"},
  88. ):
  89. await self.subject.async_turn_on(effect="auto")