| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200 |
- from homeassistant.components.light import (
- EFFECT_OFF,
- ColorMode,
- LightEntityFeature,
- )
- from homeassistant.components.number import NumberDeviceClass
- from homeassistant.const import UnitOfTime
- from ..const import RGBCW_LIGHTBULB_PAYLOAD
- from ..helpers import assert_device_properties_set
- from ..mixins.number import BasicNumberTests
- from ..mixins.text import TEXT_PATTERN_HEX, BasicTextTests
- from .base_device_tests import TuyaDeviceTestCase
- SWITCH_DPS = "20"
- MODE_DPS = "21"
- BRIGHTNESS_DPS = "22"
- COLORTEMP_DPS = "23"
- HSV_DPS = "24"
- SCENE_DPS = "25"
- TIMER_DPS = "26"
- class TestRGBCWLightbulb(BasicNumberTests, BasicTextTests, TuyaDeviceTestCase):
- __test__ = True
- def setUp(self):
- self.setUpForConfig("rgbcw_lightbulb.yaml", RGBCW_LIGHTBULB_PAYLOAD)
- self.subject = self.entities.get("light")
- self.setUpBasicNumber(
- TIMER_DPS,
- self.entities.get("number_timer"),
- max=1440.0,
- unit=UnitOfTime.MINUTES,
- device_class=NumberDeviceClass.DURATION,
- scale=60,
- )
- self.setUpBasicText(
- SCENE_DPS,
- self.entities.get("text_scene"),
- pattern=TEXT_PATTERN_HEX,
- )
- self.mark_secondary(
- [
- "number_timer",
- "select_scene",
- "text_scene",
- "time_timer",
- "switch_do_not_disturb",
- ]
- )
- def test_is_on(self):
- self.dps[SWITCH_DPS] = True
- self.assertTrue(self.subject.is_on)
- self.dps[SWITCH_DPS] = False
- self.assertFalse(self.subject.is_on)
- def test_brightness(self):
- self.dps[BRIGHTNESS_DPS] = 500
- self.assertAlmostEqual(self.subject.brightness, 126, 0)
- def test_color_temp(self):
- self.dps[COLORTEMP_DPS] = 500
- self.assertEqual(self.subject.color_temp_kelvin, 4600)
- self.dps[COLORTEMP_DPS] = 1000
- self.assertEqual(self.subject.color_temp_kelvin, 6500)
- self.dps[COLORTEMP_DPS] = 0
- self.assertEqual(self.subject.color_temp_kelvin, 2700)
- self.dps[COLORTEMP_DPS] = None
- self.assertEqual(self.subject.color_temp_kelvin, None)
- def test_color_temp_range(self):
- self.assertEqual(self.subject.min_color_temp_kelvin, 2700)
- self.assertEqual(self.subject.max_color_temp_kelvin, 6500)
- def test_color_mode(self):
- self.dps[MODE_DPS] = "white"
- self.assertEqual(self.subject.color_mode, ColorMode.COLOR_TEMP)
- self.dps[MODE_DPS] = "colour"
- self.assertEqual(self.subject.color_mode, ColorMode.HS)
- self.dps[MODE_DPS] = "scene"
- self.assertEqual(self.subject.color_mode, ColorMode.HS)
- self.dps[MODE_DPS] = "music"
- self.assertEqual(self.subject.color_mode, ColorMode.HS)
- def test_hs_color(self):
- self.dps[HSV_DPS] = "003c03e803e8"
- self.dps[BRIGHTNESS_DPS] = 1000
- self.assertSequenceEqual(self.subject.hs_color, (60, 100))
- # Lights have been observed to return N, O and P mixed in with the hex
- # number. Maybe it has some special meaning, but since it is undocumented,
- # we just want to reject such values without an exception.
- def test_invalid_hs_color(self):
- self.dps[HSV_DPS] = "0010001000OP"
- self.dps[BRIGHTNESS_DPS] = 1000
- self.assertIsNone(self.subject.hs_color)
- def test_effect_list(self):
- self.assertCountEqual(
- self.subject.effect_list,
- ["Scene", "Music", EFFECT_OFF],
- )
- def test_effect(self):
- self.dps[MODE_DPS] = "scene"
- self.assertEqual(self.subject.effect, "Scene")
- self.dps[MODE_DPS] = "music"
- self.assertEqual(self.subject.effect, "Music")
- self.dps[MODE_DPS] = "white"
- self.assertEqual(self.subject.effect, EFFECT_OFF)
- self.dps[MODE_DPS] = "colour"
- self.assertEqual(self.subject.effect, EFFECT_OFF)
- def test_supported_color_modes(self):
- self.assertCountEqual(
- self.subject.supported_color_modes,
- {ColorMode.HS, ColorMode.COLOR_TEMP},
- )
- def test_supported_features(self):
- self.assertEqual(self.subject.supported_features, LightEntityFeature.EFFECT)
- async def test_turn_on(self):
- self.dps[SWITCH_DPS] = False
- async with assert_device_properties_set(
- self.subject._device,
- {SWITCH_DPS: True},
- ):
- await self.subject.async_turn_on()
- async def test_turn_off(self):
- async with assert_device_properties_set(
- self.subject._device,
- {SWITCH_DPS: False},
- ):
- await self.subject.async_turn_off()
- async def test_set_brightness_white(self):
- self.dps[SWITCH_DPS] = True
- self.dps[MODE_DPS] = "white"
- async with assert_device_properties_set(
- self.subject._device,
- {
- BRIGHTNESS_DPS: 506,
- },
- ):
- await self.subject.async_turn_on(brightness=128)
- async def test_set_brightness_color(self):
- self.dps[SWITCH_DPS] = True
- self.dps[MODE_DPS] = "colour"
- self.dps[HSV_DPS] = "000003e803e8"
- async with assert_device_properties_set(
- self.subject._device,
- {
- HSV_DPS: "000003e801f6",
- },
- ):
- await self.subject.async_turn_on(brightness=128)
- async def test_set_hs_color(self):
- self.dps[BRIGHTNESS_DPS] = 1000
- self.dps[SWITCH_DPS] = True
- self.dps[MODE_DPS] = "colour"
- async with assert_device_properties_set(
- self.subject._device,
- {
- HSV_DPS: "000003e803e8",
- },
- ):
- await self.subject.async_turn_on(
- hs_color=(0, 100),
- )
- async def test_set_hs_from_white(self):
- self.dps[BRIGHTNESS_DPS] = 1000
- self.dps[SWITCH_DPS] = True
- self.dps[MODE_DPS] = "white"
- async with assert_device_properties_set(
- self.subject._device,
- {
- MODE_DPS: "colour",
- HSV_DPS: "000003e803e8",
- },
- ):
- await self.subject.async_turn_on(
- hs_color=(0, 100),
- )
- def test_available(self):
- self.assertFalse(self.entities.get("switch_do_not_disturb").available)
- self.assertTrue(self.subject.available)
- def test_disabled_by_default(self):
- self.assertFalse(self.basicText.entity_registry_enabled_default)
- self.assertTrue(self.subject.entity_registry_enabled_default)
|