mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
Fix MQTT to allow setting an unknown Select state (#53227)
This commit is contained in:
parent
9b2d98f027
commit
4546e14674
@ -126,7 +126,10 @@ class MqttSelect(MqttEntity, SelectEntity, RestoreEntity):
|
|||||||
if value_template is not None:
|
if value_template is not None:
|
||||||
payload = value_template.async_render_with_possible_json_value(payload)
|
payload = value_template.async_render_with_possible_json_value(payload)
|
||||||
|
|
||||||
if payload not in self.options:
|
if payload.lower() == "none":
|
||||||
|
payload = None
|
||||||
|
|
||||||
|
if payload is not None and payload not in self.options:
|
||||||
_LOGGER.error(
|
_LOGGER.error(
|
||||||
"Invalid option for %s: '%s' (valid options: %s)",
|
"Invalid option for %s: '%s' (valid options: %s)",
|
||||||
self.entity_id,
|
self.entity_id,
|
||||||
|
@ -15,7 +15,7 @@ from homeassistant.components.select import (
|
|||||||
DOMAIN as SELECT_DOMAIN,
|
DOMAIN as SELECT_DOMAIN,
|
||||||
SERVICE_SELECT_OPTION,
|
SERVICE_SELECT_OPTION,
|
||||||
)
|
)
|
||||||
from homeassistant.const import ATTR_ASSUMED_STATE, ATTR_ENTITY_ID
|
from homeassistant.const import ATTR_ASSUMED_STATE, ATTR_ENTITY_ID, STATE_UNKNOWN
|
||||||
import homeassistant.core as ha
|
import homeassistant.core as ha
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
|
||||||
@ -122,6 +122,13 @@ async def test_value_template(hass, mqtt_mock):
|
|||||||
state = hass.states.get("select.test_select")
|
state = hass.states.get("select.test_select")
|
||||||
assert state.state == "beer"
|
assert state.state == "beer"
|
||||||
|
|
||||||
|
async_fire_mqtt_message(hass, topic, '{"val": null}')
|
||||||
|
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
state = hass.states.get("select.test_select")
|
||||||
|
assert state.state == STATE_UNKNOWN
|
||||||
|
|
||||||
|
|
||||||
async def test_run_select_service_optimistic(hass, mqtt_mock):
|
async def test_run_select_service_optimistic(hass, mqtt_mock):
|
||||||
"""Test that set_value service works in optimistic mode."""
|
"""Test that set_value service works in optimistic mode."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user