Fix MQTT to allow setting an unknown Select state (#53227)
This commit is contained in:
parent
9b2d98f027
commit
4546e14674
2 changed files with 12 additions and 2 deletions
|
@ -126,7 +126,10 @@ class MqttSelect(MqttEntity, SelectEntity, RestoreEntity):
|
|||
if value_template is not None:
|
||||
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(
|
||||
"Invalid option for %s: '%s' (valid options: %s)",
|
||||
self.entity_id,
|
||||
|
|
|
@ -15,7 +15,7 @@ from homeassistant.components.select import (
|
|||
DOMAIN as SELECT_DOMAIN,
|
||||
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
|
||||
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")
|
||||
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):
|
||||
"""Test that set_value service works in optimistic mode."""
|
||||
|
|
Loading…
Add table
Reference in a new issue