Use keywords for MQTT birth and will (#38040)

pull/38050/head
Erik Montnemery 2020-07-21 23:10:34 +02:00 committed by GitHub
parent 908b72370b
commit fa0e12ffe8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 12 deletions

View File

@ -714,11 +714,10 @@ class MQTT:
if will_message is not None:
self._mqttc.will_set( # pylint: disable=no-value-for-parameter
*attr.astuple(
will_message,
filter=lambda attr, value: attr.name
not in ["subscribed_topic", "timestamp"],
)
topic=will_message.topic,
payload=will_message.payload,
qos=will_message.qos,
retain=will_message.retain,
)
async def async_publish(
@ -865,11 +864,10 @@ class MQTT:
birth_message = Message(**self.conf[CONF_BIRTH_MESSAGE])
self.hass.add_job(
self.async_publish( # pylint: disable=no-value-for-parameter
*attr.astuple(
birth_message,
filter=lambda attr, value: attr.name
not in ["subscribed_topic", "timestamp"],
)
topic=birth_message.topic,
payload=birth_message.payload,
qos=birth_message.qos,
retain=birth_message.retain,
)
)

View File

@ -799,13 +799,15 @@ async def test_no_birth_message(hass, mqtt_client_mock, mqtt_mock):
)
async def test_custom_will_message(hass, mqtt_client_mock, mqtt_mock):
"""Test will message."""
mqtt_client_mock.will_set.assert_called_with("death", "death", 0, False)
mqtt_client_mock.will_set.assert_called_with(
topic="death", payload="death", qos=0, retain=False
)
async def test_default_will_message(hass, mqtt_client_mock, mqtt_mock):
"""Test will message."""
mqtt_client_mock.will_set.assert_called_with(
"homeassistant/status", "offline", 0, False
topic="homeassistant/status", payload="offline", qos=0, retain=False
)