Reject MQTT light discovery using unsupported value_template (#62682)

* Reject MQTT light discovery using unsupported value_template

* Tweak
This commit is contained in:
Erik Montnemery 2022-01-03 17:16:26 +01:00 committed by GitHub
parent a039d245fd
commit 1995a825f3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 38 deletions

View file

@ -207,7 +207,6 @@ _PLATFORM_SCHEMA_BASE = (
vol.Optional(CONF_WHITE_SCALE, default=DEFAULT_WHITE_SCALE): vol.All(
vol.Coerce(int), vol.Range(min=1)
),
vol.Optional(CONF_VALUE_TEMPLATE): cv.template,
vol.Optional(CONF_WHITE_VALUE_COMMAND_TOPIC): mqtt.valid_publish_topic,
vol.Optional(
CONF_WHITE_VALUE_SCALE, default=DEFAULT_WHITE_VALUE_SCALE
@ -224,14 +223,12 @@ _PLATFORM_SCHEMA_BASE = (
)
PLATFORM_SCHEMA_BASIC = vol.All(
# CONF_VALUE_TEMPLATE is deprecated, support will be removed in 2021.10
cv.deprecated(CONF_VALUE_TEMPLATE, CONF_STATE_VALUE_TEMPLATE),
_PLATFORM_SCHEMA_BASE,
)
DISCOVERY_SCHEMA_BASIC = vol.All(
# CONF_VALUE_TEMPLATE is deprecated, support will be removed in 2021.10
cv.deprecated(CONF_VALUE_TEMPLATE, CONF_STATE_VALUE_TEMPLATE),
# CONF_VALUE_TEMPLATE is no longer supported, support was removed in 2022.2
cv.removed(CONF_VALUE_TEMPLATE),
_PLATFORM_SCHEMA_BASE.extend({}, extra=vol.REMOVE_EXTRA),
)

View file

@ -1117,37 +1117,6 @@ async def test_controlling_state_via_topic_with_templates(hass, mqtt_mock):
assert state.attributes.get(light.ATTR_SUPPORTED_COLOR_MODES) == color_modes
async def test_controlling_state_via_topic_with_value_template(hass, mqtt_mock, caplog):
"""Test the setting of the state with undocumented value_template."""
config = {
light.DOMAIN: {
"platform": "mqtt",
"name": "test",
"state_topic": "test_light_rgb/status",
"command_topic": "test_light_rgb/set",
"value_template": "{{ value_json.hello }}",
}
}
assert await async_setup_component(hass, light.DOMAIN, config)
await hass.async_block_till_done()
assert "The 'value_template' option is deprecated" in caplog.text
state = hass.states.get("light.test")
assert state.state == STATE_OFF
async_fire_mqtt_message(hass, "test_light_rgb/status", '{"hello": "ON"}')
state = hass.states.get("light.test")
assert state.state == STATE_ON
async_fire_mqtt_message(hass, "test_light_rgb/status", '{"hello": "OFF"}')
state = hass.states.get("light.test")
assert state.state == STATE_OFF
async def test_legacy_sending_mqtt_commands_and_optimistic(hass, mqtt_mock):
"""Test the sending of command in optimistic mode."""
config = {
@ -2289,7 +2258,7 @@ async def test_on_command_white(hass, mqtt_mock):
"platform": "mqtt",
"name": "test",
"command_topic": "tasmota_B94927/cmnd/POWER",
"value_template": "{{ value_json.POWER }}",
"state_value_template": "{{ value_json.POWER }}",
"payload_off": "OFF",
"payload_on": "ON",
"brightness_command_topic": "tasmota_B94927/cmnd/Dimmer",
@ -2598,7 +2567,7 @@ async def test_white_state_update(hass, mqtt_mock):
"name": "test",
"state_topic": "tasmota_B94927/tele/STATE",
"command_topic": "tasmota_B94927/cmnd/POWER",
"value_template": "{{ value_json.POWER }}",
"state_value_template": "{{ value_json.POWER }}",
"payload_off": "OFF",
"payload_on": "ON",
"brightness_command_topic": "tasmota_B94927/cmnd/Dimmer",