mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Flag brightness support for MQTT RGB lights (#48718)
This commit is contained in:
parent
b57d02d786
commit
9f2fb37e17
@ -197,7 +197,9 @@ class MqttLightJson(MqttEntity, LightEntity, RestoreEntity):
|
|||||||
self._supported_features |= config[CONF_BRIGHTNESS] and SUPPORT_BRIGHTNESS
|
self._supported_features |= config[CONF_BRIGHTNESS] and SUPPORT_BRIGHTNESS
|
||||||
self._supported_features |= config[CONF_COLOR_TEMP] and SUPPORT_COLOR_TEMP
|
self._supported_features |= config[CONF_COLOR_TEMP] and SUPPORT_COLOR_TEMP
|
||||||
self._supported_features |= config[CONF_HS] and SUPPORT_COLOR
|
self._supported_features |= config[CONF_HS] and SUPPORT_COLOR
|
||||||
self._supported_features |= config[CONF_RGB] and SUPPORT_COLOR
|
self._supported_features |= config[CONF_RGB] and (
|
||||||
|
SUPPORT_COLOR | SUPPORT_BRIGHTNESS
|
||||||
|
)
|
||||||
self._supported_features |= config[CONF_WHITE_VALUE] and SUPPORT_WHITE_VALUE
|
self._supported_features |= config[CONF_WHITE_VALUE] and SUPPORT_WHITE_VALUE
|
||||||
self._supported_features |= config[CONF_XY] and SUPPORT_COLOR
|
self._supported_features |= config[CONF_XY] and SUPPORT_COLOR
|
||||||
|
|
||||||
|
@ -417,7 +417,7 @@ class MqttLightTemplate(MqttEntity, LightEntity, RestoreEntity):
|
|||||||
and self._templates[CONF_GREEN_TEMPLATE] is not None
|
and self._templates[CONF_GREEN_TEMPLATE] is not None
|
||||||
and self._templates[CONF_BLUE_TEMPLATE] is not None
|
and self._templates[CONF_BLUE_TEMPLATE] is not None
|
||||||
):
|
):
|
||||||
features = features | SUPPORT_COLOR
|
features = features | SUPPORT_COLOR | SUPPORT_BRIGHTNESS
|
||||||
if self._config.get(CONF_EFFECT_LIST) is not None:
|
if self._config.get(CONF_EFFECT_LIST) is not None:
|
||||||
features = features | SUPPORT_EFFECT
|
features = features | SUPPORT_EFFECT
|
||||||
if self._templates[CONF_COLOR_TEMP_TEMPLATE] is not None:
|
if self._templates[CONF_COLOR_TEMP_TEMPLATE] is not None:
|
||||||
|
@ -161,7 +161,13 @@ import pytest
|
|||||||
|
|
||||||
from homeassistant import config as hass_config
|
from homeassistant import config as hass_config
|
||||||
from homeassistant.components import light
|
from homeassistant.components import light
|
||||||
from homeassistant.const import ATTR_ASSUMED_STATE, SERVICE_RELOAD, STATE_OFF, STATE_ON
|
from homeassistant.const import (
|
||||||
|
ATTR_ASSUMED_STATE,
|
||||||
|
ATTR_SUPPORTED_FEATURES,
|
||||||
|
SERVICE_RELOAD,
|
||||||
|
STATE_OFF,
|
||||||
|
STATE_ON,
|
||||||
|
)
|
||||||
import homeassistant.core as ha
|
import homeassistant.core as ha
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
|
||||||
@ -206,6 +212,27 @@ async def test_fail_setup_if_no_command_topic(hass, mqtt_mock):
|
|||||||
assert hass.states.get("light.test") is None
|
assert hass.states.get("light.test") is None
|
||||||
|
|
||||||
|
|
||||||
|
async def test_rgb_light(hass, mqtt_mock):
|
||||||
|
"""Test RGB light flags brightness support."""
|
||||||
|
assert await async_setup_component(
|
||||||
|
hass,
|
||||||
|
light.DOMAIN,
|
||||||
|
{
|
||||||
|
light.DOMAIN: {
|
||||||
|
"platform": "mqtt",
|
||||||
|
"name": "test",
|
||||||
|
"command_topic": "test_light_rgb/set",
|
||||||
|
"rgb_command_topic": "test_light_rgb/rgb/set",
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
state = hass.states.get("light.test")
|
||||||
|
expected_features = light.SUPPORT_COLOR | light.SUPPORT_BRIGHTNESS
|
||||||
|
assert state.attributes.get(ATTR_SUPPORTED_FEATURES) == expected_features
|
||||||
|
|
||||||
|
|
||||||
async def test_no_color_brightness_color_temp_hs_white_xy_if_no_topics(hass, mqtt_mock):
|
async def test_no_color_brightness_color_temp_hs_white_xy_if_no_topics(hass, mqtt_mock):
|
||||||
"""Test if there is no color and brightness if no topic."""
|
"""Test if there is no color and brightness if no topic."""
|
||||||
assert await async_setup_component(
|
assert await async_setup_component(
|
||||||
|
@ -188,6 +188,33 @@ async def test_fail_setup_if_color_mode_deprecated(hass, mqtt_mock, deprecated):
|
|||||||
assert hass.states.get("light.test") is None
|
assert hass.states.get("light.test") is None
|
||||||
|
|
||||||
|
|
||||||
|
async def test_rgb_light(hass, mqtt_mock):
|
||||||
|
"""Test RGB light flags brightness support."""
|
||||||
|
assert await async_setup_component(
|
||||||
|
hass,
|
||||||
|
light.DOMAIN,
|
||||||
|
{
|
||||||
|
light.DOMAIN: {
|
||||||
|
"platform": "mqtt",
|
||||||
|
"schema": "json",
|
||||||
|
"name": "test",
|
||||||
|
"command_topic": "test_light_rgb/set",
|
||||||
|
"rgb": True,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
state = hass.states.get("light.test")
|
||||||
|
expected_features = (
|
||||||
|
light.SUPPORT_TRANSITION
|
||||||
|
| light.SUPPORT_COLOR
|
||||||
|
| light.SUPPORT_FLASH
|
||||||
|
| light.SUPPORT_BRIGHTNESS
|
||||||
|
)
|
||||||
|
assert state.attributes.get(ATTR_SUPPORTED_FEATURES) == expected_features
|
||||||
|
|
||||||
|
|
||||||
async def test_no_color_brightness_color_temp_white_val_if_no_topics(hass, mqtt_mock):
|
async def test_no_color_brightness_color_temp_white_val_if_no_topics(hass, mqtt_mock):
|
||||||
"""Test for no RGB, brightness, color temp, effect, white val or XY."""
|
"""Test for no RGB, brightness, color temp, effect, white val or XY."""
|
||||||
assert await async_setup_component(
|
assert await async_setup_component(
|
||||||
|
@ -141,6 +141,37 @@ async def test_setup_fails(hass, mqtt_mock):
|
|||||||
assert hass.states.get("light.test") is None
|
assert hass.states.get("light.test") is None
|
||||||
|
|
||||||
|
|
||||||
|
async def test_rgb_light(hass, mqtt_mock):
|
||||||
|
"""Test RGB light flags brightness support."""
|
||||||
|
assert await async_setup_component(
|
||||||
|
hass,
|
||||||
|
light.DOMAIN,
|
||||||
|
{
|
||||||
|
light.DOMAIN: {
|
||||||
|
"platform": "mqtt",
|
||||||
|
"schema": "template",
|
||||||
|
"name": "test",
|
||||||
|
"command_topic": "test_light_rgb/set",
|
||||||
|
"command_on_template": "on",
|
||||||
|
"command_off_template": "off",
|
||||||
|
"red_template": '{{ value.split(",")[4].' 'split("-")[0] }}',
|
||||||
|
"green_template": '{{ value.split(",")[4].' 'split("-")[1] }}',
|
||||||
|
"blue_template": '{{ value.split(",")[4].' 'split("-")[2] }}',
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
state = hass.states.get("light.test")
|
||||||
|
expected_features = (
|
||||||
|
light.SUPPORT_TRANSITION
|
||||||
|
| light.SUPPORT_COLOR
|
||||||
|
| light.SUPPORT_FLASH
|
||||||
|
| light.SUPPORT_BRIGHTNESS
|
||||||
|
)
|
||||||
|
assert state.attributes.get(ATTR_SUPPORTED_FEATURES) == expected_features
|
||||||
|
|
||||||
|
|
||||||
async def test_state_change_via_topic(hass, mqtt_mock):
|
async def test_state_change_via_topic(hass, mqtt_mock):
|
||||||
"""Test state change via topic."""
|
"""Test state change via topic."""
|
||||||
with assert_setup_component(1, light.DOMAIN):
|
with assert_setup_component(1, light.DOMAIN):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user