async def test_color_temperature_light(hass): """Test ColorTemperature trait support for light domain.""" assert not trait.ColorTemperatureTrait.supported(light.DOMAIN, 0) assert trait.ColorTemperatureTrait.supported(light.DOMAIN, light.SUPPORT_COLOR_TEMP) trt = trait.ColorTemperatureTrait(hass, State('light.bla', STATE_ON, { light.ATTR_MIN_MIREDS: 200, light.ATTR_COLOR_TEMP: 300, light.ATTR_MAX_MIREDS: 500, }), BASIC_CONFIG) assert trt.sync_attributes() == { 'temperatureMinK': 2000, 'temperatureMaxK': 5000, } assert trt.query_attributes() == { 'color': { 'temperature': 3333 } } assert trt.can_execute(trait.COMMAND_COLOR_ABSOLUTE, { 'color': { 'temperature': 400 } }) assert not trt.can_execute(trait.COMMAND_COLOR_ABSOLUTE, { 'color': { 'spectrumRGB': 16715792 } }) calls = async_mock_service(hass, light.DOMAIN, SERVICE_TURN_ON) with pytest.raises(helpers.SmartHomeError) as err: await trt.execute(trait.COMMAND_COLOR_ABSOLUTE, BASIC_DATA, { 'color': { 'temperature': 5555 } }) assert err.value.code == const.ERR_VALUE_OUT_OF_RANGE await trt.execute(trait.COMMAND_COLOR_ABSOLUTE, BASIC_DATA, { 'color': { 'temperature': 2857 } }) assert len(calls) == 1 assert calls[0].data == { ATTR_ENTITY_ID: 'light.bla', light.ATTR_COLOR_TEMP: color.color_temperature_kelvin_to_mired(2857) }
async def test_color_temperature_light_bad_temp(hass): """Test ColorTemperature trait support for light domain.""" assert not trait.ColorTemperatureTrait.supported(light.DOMAIN, 0) assert trait.ColorTemperatureTrait.supported(light.DOMAIN, light.SUPPORT_COLOR_TEMP) trt = trait.ColorTemperatureTrait(hass, State('light.bla', STATE_ON, { light.ATTR_MIN_MIREDS: 200, light.ATTR_COLOR_TEMP: 0, light.ATTR_MAX_MIREDS: 500, }), BASIC_CONFIG) assert trt.query_attributes() == { }