test_rgbcw_lightbulb.py 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. from homeassistant.components.light import (
  2. ColorMode,
  3. LightEntityFeature,
  4. )
  5. from homeassistant.const import UnitOfTime
  6. from ..const import RGBCW_LIGHTBULB_PAYLOAD
  7. from ..helpers import assert_device_properties_set
  8. from ..mixins.number import BasicNumberTests
  9. from .base_device_tests import TuyaDeviceTestCase
  10. SWITCH_DPS = "20"
  11. MODE_DPS = "21"
  12. BRIGHTNESS_DPS = "22"
  13. COLORTEMP_DPS = "23"
  14. HSV_DPS = "24"
  15. SCENE_DPS = "25"
  16. TIMER_DPS = "26"
  17. class TestRGBCWLightbulb(BasicNumberTests, TuyaDeviceTestCase):
  18. __test__ = True
  19. def setUp(self):
  20. self.setUpForConfig("rgbcw_lightbulb.yaml", RGBCW_LIGHTBULB_PAYLOAD)
  21. self.subject = self.entities.get("light")
  22. self.setUpBasicNumber(
  23. TIMER_DPS,
  24. self.entities.get("number_timer"),
  25. max=1440.0,
  26. unit=UnitOfTime.MINUTES,
  27. scale=60,
  28. )
  29. self.mark_secondary(["number_timer", "select_scene"])
  30. def test_is_on(self):
  31. self.dps[SWITCH_DPS] = True
  32. self.assertTrue(self.subject.is_on)
  33. self.dps[SWITCH_DPS] = False
  34. self.assertFalse(self.subject.is_on)
  35. def test_brightness(self):
  36. self.dps[BRIGHTNESS_DPS] = 500
  37. self.assertAlmostEqual(self.subject.brightness, 128, 0)
  38. def test_color_temp(self):
  39. self.dps[COLORTEMP_DPS] = 500
  40. self.assertAlmostEqual(self.subject.color_temp, 326, 0)
  41. self.dps[COLORTEMP_DPS] = 1000
  42. self.assertAlmostEqual(self.subject.color_temp, 153, 0)
  43. self.dps[COLORTEMP_DPS] = 0
  44. self.assertAlmostEqual(self.subject.color_temp, 500, 0)
  45. self.dps[COLORTEMP_DPS] = None
  46. self.assertEqual(self.subject.color_temp, None)
  47. def test_color_mode(self):
  48. self.dps[MODE_DPS] = "white"
  49. self.assertEqual(self.subject.color_mode, ColorMode.COLOR_TEMP)
  50. self.dps[MODE_DPS] = "colour"
  51. self.assertEqual(self.subject.color_mode, ColorMode.RGBW)
  52. self.dps[MODE_DPS] = "scene"
  53. self.assertEqual(self.subject.color_mode, ColorMode.RGBW)
  54. self.dps[MODE_DPS] = "music"
  55. self.assertEqual(self.subject.color_mode, ColorMode.RGBW)
  56. def test_rgbw_color(self):
  57. self.dps[HSV_DPS] = "003c03e803e8"
  58. self.dps[BRIGHTNESS_DPS] = 1000
  59. self.assertSequenceEqual(
  60. self.subject.rgbw_color,
  61. (255, 255, 0, 255),
  62. )
  63. def test_effect_list(self):
  64. self.assertCountEqual(
  65. self.subject.effect_list,
  66. ["Scene", "Music"],
  67. )
  68. def test_effect(self):
  69. self.dps[MODE_DPS] = "scene"
  70. self.assertEqual(self.subject.effect, "Scene")
  71. self.dps[MODE_DPS] = "music"
  72. self.assertEqual(self.subject.effect, "Music")
  73. self.dps[MODE_DPS] = "white"
  74. self.assertIsNone(self.subject.effect)
  75. self.dps[MODE_DPS] = "colour"
  76. self.assertIsNone(self.subject.effect)
  77. def test_supported_color_modes(self):
  78. self.assertCountEqual(
  79. self.subject.supported_color_modes,
  80. {ColorMode.RGBW, ColorMode.COLOR_TEMP},
  81. )
  82. def test_supported_features(self):
  83. self.assertEqual(self.subject.supported_features, LightEntityFeature.EFFECT)
  84. async def test_turn_on(self):
  85. self.dps[SWITCH_DPS] = False
  86. async with assert_device_properties_set(
  87. self.subject._device,
  88. {SWITCH_DPS: True},
  89. ):
  90. await self.subject.async_turn_on()
  91. async def test_turn_off(self):
  92. async with assert_device_properties_set(
  93. self.subject._device,
  94. {SWITCH_DPS: False},
  95. ):
  96. await self.subject.async_turn_off()
  97. async def test_set_brightness_white(self):
  98. self.dps[SWITCH_DPS] = True
  99. self.dps[MODE_DPS] = "white"
  100. async with assert_device_properties_set(
  101. self.subject._device,
  102. {
  103. BRIGHTNESS_DPS: 502,
  104. },
  105. ):
  106. await self.subject.async_turn_on(brightness=128)
  107. async def test_set_brightness_color(self):
  108. self.dps[SWITCH_DPS] = True
  109. self.dps[MODE_DPS] = "colour"
  110. self.dps[HSV_DPS] = "000003e803e8"
  111. async with assert_device_properties_set(
  112. self.subject._device,
  113. {
  114. HSV_DPS: "000003e801f6",
  115. },
  116. ):
  117. await self.subject.async_turn_on(brightness=128)
  118. async def test_set_rgbw(self):
  119. self.dps[BRIGHTNESS_DPS] = 1000
  120. self.dps[SWITCH_DPS] = True
  121. self.dps[MODE_DPS] = "colour"
  122. async with assert_device_properties_set(
  123. self.subject._device,
  124. {
  125. HSV_DPS: "000003e803e8",
  126. },
  127. ):
  128. await self.subject.async_turn_on(
  129. rgbw_color=(255, 0, 0, 255),
  130. )
  131. async def test_set_rgbw_from_white(self):
  132. self.dps[BRIGHTNESS_DPS] = 1000
  133. self.dps[SWITCH_DPS] = True
  134. self.dps[MODE_DPS] = "white"
  135. async with assert_device_properties_set(
  136. self.subject._device,
  137. {
  138. MODE_DPS: "colour",
  139. HSV_DPS: "000003e803e8",
  140. },
  141. ):
  142. await self.subject.async_turn_on(
  143. rgbw_color=(255, 0, 0, 255),
  144. )
  145. def test_extra_state_attributes(self):
  146. self.dps[SCENE_DPS] = "test"
  147. self.assertDictEqual(
  148. self.subject.extra_state_attributes,
  149. {
  150. "scene_data": "test",
  151. },
  152. )