mirror of
https://github.com/home-assistant/core.git
synced 2025-07-24 13:47:35 +00:00
Add support for params in send_command (#23071)
* add support for params in send_command * add more tests
This commit is contained in:
parent
df580b2322
commit
1d2e9b6915
@ -1,5 +1,6 @@
|
|||||||
"""Support for a generic MQTT vacuum."""
|
"""Support for a generic MQTT vacuum."""
|
||||||
import logging
|
import logging
|
||||||
|
import json
|
||||||
|
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
@ -507,8 +508,13 @@ class MqttVacuum(MqttAttributes, MqttAvailability, MqttDiscoveryUpdate,
|
|||||||
"""Send a command to a vacuum cleaner."""
|
"""Send a command to a vacuum cleaner."""
|
||||||
if self.supported_features & SUPPORT_SEND_COMMAND == 0:
|
if self.supported_features & SUPPORT_SEND_COMMAND == 0:
|
||||||
return
|
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,
|
mqtt.async_publish(self.hass, self._send_command_topic,
|
||||||
command, self._qos, self._retain)
|
message, self._qos, self._retain)
|
||||||
self._status = "Sending command {}...".format(command)
|
self._status = "Sending command {}...".format(message)
|
||||||
self.async_write_ha_state()
|
self.async_write_ha_state()
|
||||||
|
@ -130,6 +130,15 @@ async def test_all_commands(hass, mock_publish):
|
|||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
mock_publish.async_publish.assert_called_once_with(
|
mock_publish.async_publish.assert_called_once_with(
|
||||||
'vacuum/send_command', '44 FE 93', 0, False)
|
'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):
|
async def test_status(hass, mock_publish):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user