Add support for params in send_command (#23071)

* add support for params in send_command

* add more tests
This commit is contained in:
Pawel 2019-04-14 20:09:46 +02:00 committed by Paulus Schoutsen
parent df580b2322
commit 1d2e9b6915
2 changed files with 18 additions and 3 deletions

View File

@ -1,5 +1,6 @@
"""Support for a generic MQTT vacuum."""
import logging
import json
import voluptuous as vol
@ -507,8 +508,13 @@ class MqttVacuum(MqttAttributes, MqttAvailability, MqttDiscoveryUpdate,
"""Send a command to a vacuum cleaner."""
if self.supported_features & SUPPORT_SEND_COMMAND == 0:
return
if params:
message = {"command": command}
message.update(params)
message = json.dumps(message)
else:
message = command
mqtt.async_publish(self.hass, self._send_command_topic,
command, self._qos, self._retain)
self._status = "Sending command {}...".format(command)
message, self._qos, self._retain)
self._status = "Sending command {}...".format(message)
self.async_write_ha_state()

View File

@ -130,6 +130,15 @@ async def test_all_commands(hass, mock_publish):
await hass.async_block_till_done()
mock_publish.async_publish.assert_called_once_with(
'vacuum/send_command', '44 FE 93', 0, False)
mock_publish.async_publish.reset_mock()
common.send_command(hass, '44 FE 93', {"key": "value"},
entity_id='vacuum.mqtttest')
await hass.async_block_till_done()
await hass.async_block_till_done()
mock_publish.async_publish.assert_called_once_with(
'vacuum/send_command', '{"command": "44 FE 93", "key": "value"}',
0, False)
async def test_status(hass, mock_publish):