Fix MQTT cover not using tilt_command_template (#63080)
parent
1ce75f8e6b
commit
0dab5e69db
|
@ -603,10 +603,20 @@ class MqttCover(MqttEntity, CoverEntity):
|
|||
|
||||
async def async_open_cover_tilt(self, **kwargs):
|
||||
"""Tilt the cover open."""
|
||||
tilt_open_position = self._config[CONF_TILT_OPEN_POSITION]
|
||||
variables = {
|
||||
"tilt_position": tilt_open_position,
|
||||
"entity_id": self.entity_id,
|
||||
"position_open": self._config.get(CONF_POSITION_OPEN),
|
||||
"position_closed": self._config.get(CONF_POSITION_CLOSED),
|
||||
"tilt_min": self._config.get(CONF_TILT_MIN),
|
||||
"tilt_max": self._config.get(CONF_TILT_MAX),
|
||||
}
|
||||
tilt_payload = self._set_tilt_template(tilt_open_position, variables=variables)
|
||||
await mqtt.async_publish(
|
||||
self.hass,
|
||||
self._config.get(CONF_TILT_COMMAND_TOPIC),
|
||||
self._config[CONF_TILT_OPEN_POSITION],
|
||||
tilt_payload,
|
||||
self._config[CONF_QOS],
|
||||
self._config[CONF_RETAIN],
|
||||
self._config[CONF_ENCODING],
|
||||
|
@ -619,10 +629,22 @@ class MqttCover(MqttEntity, CoverEntity):
|
|||
|
||||
async def async_close_cover_tilt(self, **kwargs):
|
||||
"""Tilt the cover closed."""
|
||||
tilt_closed_position = self._config[CONF_TILT_CLOSED_POSITION]
|
||||
variables = {
|
||||
"tilt_position": tilt_closed_position,
|
||||
"entity_id": self.entity_id,
|
||||
"position_open": self._config.get(CONF_POSITION_OPEN),
|
||||
"position_closed": self._config.get(CONF_POSITION_CLOSED),
|
||||
"tilt_min": self._config.get(CONF_TILT_MIN),
|
||||
"tilt_max": self._config.get(CONF_TILT_MAX),
|
||||
}
|
||||
tilt_payload = self._set_tilt_template(
|
||||
tilt_closed_position, variables=variables
|
||||
)
|
||||
await mqtt.async_publish(
|
||||
self.hass,
|
||||
self._config.get(CONF_TILT_COMMAND_TOPIC),
|
||||
self._config[CONF_TILT_CLOSED_POSITION],
|
||||
tilt_payload,
|
||||
self._config[CONF_QOS],
|
||||
self._config[CONF_RETAIN],
|
||||
self._config[CONF_ENCODING],
|
||||
|
|
|
@ -934,12 +934,11 @@ async def test_set_tilt_templated_and_attributes(hass, mqtt_mock):
|
|||
"position_closed": 0,
|
||||
"set_position_topic": "set-position-topic",
|
||||
"set_position_template": "{{position-1}}",
|
||||
"tilt_command_template": '\
|
||||
{% if state_attr(entity_id, "friendly_name") != "test" %}\
|
||||
{{ 5 }}\
|
||||
{% else %}\
|
||||
{{ 23 }}\
|
||||
{% endif %}',
|
||||
"tilt_command_template": "{"
|
||||
'"enitity_id": "{{ entity_id }}",'
|
||||
'"value": {{ value }},'
|
||||
'"tilt_position": {{ tilt_position }}'
|
||||
"}",
|
||||
"payload_open": "OPEN",
|
||||
"payload_close": "CLOSE",
|
||||
"payload_stop": "STOP",
|
||||
|
@ -951,12 +950,57 @@ async def test_set_tilt_templated_and_attributes(hass, mqtt_mock):
|
|||
await hass.services.async_call(
|
||||
cover.DOMAIN,
|
||||
SERVICE_SET_COVER_TILT_POSITION,
|
||||
{ATTR_ENTITY_ID: "cover.test", ATTR_TILT_POSITION: 99},
|
||||
{ATTR_ENTITY_ID: "cover.test", ATTR_TILT_POSITION: 45},
|
||||
blocking=True,
|
||||
)
|
||||
|
||||
mqtt_mock.async_publish.assert_called_once_with(
|
||||
"tilt-command-topic", "23", 0, False
|
||||
"tilt-command-topic",
|
||||
'{"enitity_id": "cover.test","value": 45,"tilt_position": 45}',
|
||||
0,
|
||||
False,
|
||||
)
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
|
||||
await hass.services.async_call(
|
||||
cover.DOMAIN,
|
||||
SERVICE_OPEN_COVER_TILT,
|
||||
{ATTR_ENTITY_ID: "cover.test"},
|
||||
blocking=True,
|
||||
)
|
||||
mqtt_mock.async_publish.assert_called_once_with(
|
||||
"tilt-command-topic",
|
||||
'{"enitity_id": "cover.test","value": 100,"tilt_position": 100}',
|
||||
0,
|
||||
False,
|
||||
)
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
|
||||
await hass.services.async_call(
|
||||
cover.DOMAIN,
|
||||
SERVICE_CLOSE_COVER_TILT,
|
||||
{ATTR_ENTITY_ID: "cover.test"},
|
||||
blocking=True,
|
||||
)
|
||||
mqtt_mock.async_publish.assert_called_once_with(
|
||||
"tilt-command-topic",
|
||||
'{"enitity_id": "cover.test","value": 0,"tilt_position": 0}',
|
||||
0,
|
||||
False,
|
||||
)
|
||||
mqtt_mock.async_publish.reset_mock()
|
||||
|
||||
await hass.services.async_call(
|
||||
cover.DOMAIN,
|
||||
SERVICE_TOGGLE_COVER_TILT,
|
||||
{ATTR_ENTITY_ID: "cover.test"},
|
||||
blocking=True,
|
||||
)
|
||||
mqtt_mock.async_publish.assert_called_once_with(
|
||||
"tilt-command-topic",
|
||||
'{"enitity_id": "cover.test","value": 100,"tilt_position": 100}',
|
||||
0,
|
||||
False,
|
||||
)
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue