mirror of
https://github.com/home-assistant/core.git
synced 2025-07-27 15:17:35 +00:00
Make all MQTT cover payloads optional (#50579)
* Remove unused constant * Make payload_close optional * Make payload_open optional * Compute supported features based on config
This commit is contained in:
parent
1de0d20a76
commit
5a5a145778
@ -94,7 +94,6 @@ DEFAULT_TILT_MIN = 0
|
|||||||
DEFAULT_TILT_OPEN_POSITION = 100
|
DEFAULT_TILT_OPEN_POSITION = 100
|
||||||
DEFAULT_TILT_OPTIMISTIC = False
|
DEFAULT_TILT_OPTIMISTIC = False
|
||||||
|
|
||||||
OPEN_CLOSE_FEATURES = SUPPORT_OPEN | SUPPORT_CLOSE
|
|
||||||
TILT_FEATURES = (
|
TILT_FEATURES = (
|
||||||
SUPPORT_OPEN_TILT
|
SUPPORT_OPEN_TILT
|
||||||
| SUPPORT_CLOSE_TILT
|
| SUPPORT_CLOSE_TILT
|
||||||
@ -151,8 +150,12 @@ PLATFORM_SCHEMA = vol.All(
|
|||||||
vol.Optional(CONF_GET_POSITION_TOPIC): mqtt.valid_subscribe_topic,
|
vol.Optional(CONF_GET_POSITION_TOPIC): mqtt.valid_subscribe_topic,
|
||||||
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
|
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
|
||||||
vol.Optional(CONF_OPTIMISTIC, default=DEFAULT_OPTIMISTIC): cv.boolean,
|
vol.Optional(CONF_OPTIMISTIC, default=DEFAULT_OPTIMISTIC): cv.boolean,
|
||||||
vol.Optional(CONF_PAYLOAD_CLOSE, default=DEFAULT_PAYLOAD_CLOSE): cv.string,
|
vol.Optional(CONF_PAYLOAD_CLOSE, default=DEFAULT_PAYLOAD_CLOSE): vol.Any(
|
||||||
vol.Optional(CONF_PAYLOAD_OPEN, default=DEFAULT_PAYLOAD_OPEN): cv.string,
|
cv.string, None
|
||||||
|
),
|
||||||
|
vol.Optional(CONF_PAYLOAD_OPEN, default=DEFAULT_PAYLOAD_OPEN): vol.Any(
|
||||||
|
cv.string, None
|
||||||
|
),
|
||||||
vol.Optional(CONF_PAYLOAD_STOP, default=DEFAULT_PAYLOAD_STOP): vol.Any(
|
vol.Optional(CONF_PAYLOAD_STOP, default=DEFAULT_PAYLOAD_STOP): vol.Any(
|
||||||
cv.string, None
|
cv.string, None
|
||||||
),
|
),
|
||||||
@ -474,8 +477,10 @@ class MqttCover(MqttEntity, CoverEntity):
|
|||||||
"""Flag supported features."""
|
"""Flag supported features."""
|
||||||
supported_features = 0
|
supported_features = 0
|
||||||
if self._config.get(CONF_COMMAND_TOPIC) is not None:
|
if self._config.get(CONF_COMMAND_TOPIC) is not None:
|
||||||
supported_features = OPEN_CLOSE_FEATURES
|
if self._config.get(CONF_PAYLOAD_OPEN) is not None:
|
||||||
|
supported_features |= SUPPORT_OPEN
|
||||||
|
if self._config.get(CONF_PAYLOAD_CLOSE) is not None:
|
||||||
|
supported_features |= SUPPORT_CLOSE
|
||||||
if self._config.get(CONF_PAYLOAD_STOP) is not None:
|
if self._config.get(CONF_PAYLOAD_STOP) is not None:
|
||||||
supported_features |= SUPPORT_STOP
|
supported_features |= SUPPORT_STOP
|
||||||
|
|
||||||
|
@ -1014,6 +1014,50 @@ async def test_no_command_topic(hass, mqtt_mock):
|
|||||||
assert hass.states.get("cover.test").attributes["supported_features"] == 240
|
assert hass.states.get("cover.test").attributes["supported_features"] == 240
|
||||||
|
|
||||||
|
|
||||||
|
async def test_no_payload_close(hass, mqtt_mock):
|
||||||
|
"""Test with no close payload."""
|
||||||
|
assert await async_setup_component(
|
||||||
|
hass,
|
||||||
|
cover.DOMAIN,
|
||||||
|
{
|
||||||
|
cover.DOMAIN: {
|
||||||
|
"platform": "mqtt",
|
||||||
|
"name": "test",
|
||||||
|
"command_topic": "command-topic",
|
||||||
|
"qos": 0,
|
||||||
|
"payload_open": "OPEN",
|
||||||
|
"payload_close": None,
|
||||||
|
"payload_stop": "STOP",
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
assert hass.states.get("cover.test").attributes["supported_features"] == 9
|
||||||
|
|
||||||
|
|
||||||
|
async def test_no_payload_open(hass, mqtt_mock):
|
||||||
|
"""Test with no open payload."""
|
||||||
|
assert await async_setup_component(
|
||||||
|
hass,
|
||||||
|
cover.DOMAIN,
|
||||||
|
{
|
||||||
|
cover.DOMAIN: {
|
||||||
|
"platform": "mqtt",
|
||||||
|
"name": "test",
|
||||||
|
"command_topic": "command-topic",
|
||||||
|
"qos": 0,
|
||||||
|
"payload_open": None,
|
||||||
|
"payload_close": "CLOSE",
|
||||||
|
"payload_stop": "STOP",
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
assert hass.states.get("cover.test").attributes["supported_features"] == 10
|
||||||
|
|
||||||
|
|
||||||
async def test_no_payload_stop(hass, mqtt_mock):
|
async def test_no_payload_stop(hass, mqtt_mock):
|
||||||
"""Test with no stop payload."""
|
"""Test with no stop payload."""
|
||||||
assert await async_setup_component(
|
assert await async_setup_component(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user