Add MQTT cover stop tilt (#139912)

* Stop tilt move.

Stop tilt use same payload as cover - payload_stop

* Add test for STOP_TILT

* Tilt action

* Revert "Tilt action"

This reverts commit 7ce4fbb086.

* Update tests/components/mqtt/test_cover.py

Co-authored-by: Abílio Costa <abmantis@users.noreply.github.com>

* Update homeassistant/components/mqtt/cover.py

Co-authored-by: Abílio Costa <abmantis@users.noreply.github.com>

* Append CONF_PAYLOAD_STOP_TILT

* Update homeassistant/components/mqtt/cover.py

Co-authored-by: Jan Bouwhuis <jbouwh@users.noreply.github.com>

* Test for new payload

* Update tests/components/mqtt/test_cover.py

Co-authored-by: Jan Bouwhuis <jbouwh@users.noreply.github.com>

* Update tests/components/mqtt/test_cover.py

Co-authored-by: Jan Bouwhuis <jbouwh@users.noreply.github.com>

* Ruff format

* abbreviation

---------

Co-authored-by: Abílio Costa <abmantis@users.noreply.github.com>
Co-authored-by: Jan Bouwhuis <jbouwh@users.noreply.github.com>
pull/141009/head^2
poucz 2025-03-20 19:20:12 +01:00 committed by GitHub
parent f9bb250621
commit a030502489
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 69 additions and 0 deletions

View File

@ -150,6 +150,7 @@ ABBREVIATIONS = {
"pl_rst_pct": "payload_reset_percentage",
"pl_rst_pr_mode": "payload_reset_preset_mode",
"pl_stop": "payload_stop",
"pl_stop_tilt": "payload_stop_tilt",
"pl_strt": "payload_start",
"pl_ret": "payload_return_to_base",
"pl_toff": "payload_turn_off",

View File

@ -81,6 +81,7 @@ CONF_TILT_STATUS_TOPIC = "tilt_status_topic"
CONF_TILT_STATUS_TEMPLATE = "tilt_status_template"
CONF_STATE_STOPPED = "state_stopped"
CONF_PAYLOAD_STOP_TILT = "payload_stop_tilt"
CONF_TILT_CLOSED_POSITION = "tilt_closed_value"
CONF_TILT_MAX = "tilt_max"
CONF_TILT_MIN = "tilt_min"
@ -203,6 +204,9 @@ _PLATFORM_SCHEMA_BASE = MQTT_BASE_SCHEMA.extend(
vol.Optional(CONF_VALUE_TEMPLATE): cv.template,
vol.Optional(CONF_GET_POSITION_TEMPLATE): cv.template,
vol.Optional(CONF_TILT_COMMAND_TEMPLATE): cv.template,
vol.Optional(CONF_PAYLOAD_STOP_TILT, default=DEFAULT_PAYLOAD_STOP): vol.Any(
cv.string, None
),
}
).extend(MQTT_ENTITY_COMMON_SCHEMA.schema)
@ -592,6 +596,12 @@ class MqttCover(MqttEntity, CoverEntity):
self._attr_current_cover_tilt_position = tilt_percentage
self.async_write_ha_state()
async def async_stop_cover_tilt(self, **kwargs: Any) -> None:
"""Stop moving the cover tilt."""
await self.async_publish_with_config(
self._config[CONF_TILT_COMMAND_TOPIC], self._config[CONF_PAYLOAD_STOP_TILT]
)
async def async_set_cover_position(self, **kwargs: Any) -> None:
"""Move the cover to a specific position."""
position_percentage = kwargs[ATTR_POSITION]

View File

@ -37,6 +37,7 @@ from homeassistant.const import (
SERVICE_SET_COVER_POSITION,
SERVICE_SET_COVER_TILT_POSITION,
SERVICE_STOP_COVER,
SERVICE_STOP_COVER_TILT,
SERVICE_TOGGLE,
SERVICE_TOGGLE_COVER_TILT,
STATE_CLOSED,
@ -936,6 +937,63 @@ async def test_send_stop_cover_command(
assert state.state == STATE_UNKNOWN
@pytest.mark.parametrize(
("hass_config", "payload_stop"),
[
(
{
mqtt.DOMAIN: {
cover.DOMAIN: {
"name": "test",
"state_topic": "state-topic",
"tilt_command_topic": "tilt-command-topic",
"payload_stop_tilt": "TILT_STOP",
"qos": 2,
}
}
},
"TILT_STOP",
),
(
{
mqtt.DOMAIN: {
cover.DOMAIN: {
"name": "test",
"state_topic": "state-topic",
"tilt_command_topic": "tilt-command-topic",
"qos": 2,
}
}
},
"STOP",
),
],
)
async def test_send_stop_tilt_command(
hass: HomeAssistant,
mqtt_mock_entry: MqttMockHAClientGenerator,
payload_stop: str,
) -> None:
"""Test the sending of stop_cover_tilt."""
mqtt_mock = await mqtt_mock_entry()
state = hass.states.get("cover.test")
assert state.state == STATE_UNKNOWN
await hass.services.async_call(
cover.DOMAIN,
SERVICE_STOP_COVER_TILT,
{ATTR_ENTITY_ID: "cover.test"},
blocking=True,
)
mqtt_mock.async_publish.assert_called_once_with(
"tilt-command-topic", payload_stop, 2, False
)
state = hass.states.get("cover.test")
assert state.state == STATE_UNKNOWN
@pytest.mark.parametrize(
"hass_config",
[