Fix MQTT retained message not being re-dispatched (#12004)
* Fix MQTT retained message not being re-dispatched * Fix tests * Use paho-mqtt for retained messages * Improve code style * Store list of subscribers * Fix lint error * Adhere to Home Assistant's logging standard "Try to avoid brackets and additional quotes around the output to make it easier for users to parse the log." - https://home-assistant.io/developers/development_guidelines/ * Add reconnect tests * Fix lint error * Introduce Subscription Tests still need to be updated * Use namedtuple for MQTT messages ... And fix issues Accessing the config manually at runtime isn't ideal * Fix MQTT __init__.py tests * Updated usage of Mocks * Moved tests that were testing subscriptions out of the MQTTComponent test, because of how mock.patch was used * Adjusted the remaining tests for the MQTT clients new behavior - e.g. self.progress was removed * Updated the async_fire_mqtt_message helper * ✅ Update MQTT tests * Re-introduce the MQTT subscriptions through the dispatcher for tests - quite ugly though... 🚧 * Update fixtures to use our new MQTT mock 🎨 * 📝 Update base code according to comments * 🔨 Adjust MQTT test base * 🔨 Update other MQTT tests * 🍎 Fix carriage return in source files Apparently test_mqtt_json.py and test_mqtt_template.py were written on Windows. In order to not mess up the diff, I'll just redo the carriage return. * 🎨 Remove unused import * 📝 Remove fire_mqtt_client_message * 🐛 Fix using python 3.6 method What's very interesting is that 3.4 didn't fail on travis... * 🐛 Fix using assert directly
This commit is contained in:
1 parent
17e5740a0c
commit
b1c0cabe6c
15 files changed
+1531
-1490
No files matched your search
@@ -71,52 +71,56 @@ class TestVacuumMQTT(unittest.TestCase):
|
||||
|
||||
vacuum.turn_on(self.hass, 'vacuum.mqtttest')
|
||||
self.hass.block_till_done()
|
||||
self.assertEqual(('vacuum/command', 'turn_on', 0, False),
|
||||
self.mock_publish.mock_calls[-2][1])
|
||||
self.mock_publish.async_publish.assert_called_once_with(
|
||||
'vacuum/command', 'turn_on', 0, False)
|
||||
self.mock_publish.async_publish.reset_mock()
|
||||
|
||||
vacuum.turn_off(self.hass, 'vacuum.mqtttest')
|
||||
self.hass.block_till_done()
|
||||
self.assertEqual(('vacuum/command', 'turn_off', 0, False),
|
||||
self.mock_publish.mock_calls[-2][1])
|
||||
self.mock_publish.async_publish.assert_called_once_with(
|
||||
'vacuum/command', 'turn_off', 0, False)
|
||||
self.mock_publish.async_publish.reset_mock()
|
||||
|
||||
vacuum.stop(self.hass, 'vacuum.mqtttest')
|
||||
self.hass.block_till_done()
|
||||
self.assertEqual(('vacuum/command', 'stop', 0, False),
|
||||
self.mock_publish.mock_calls[-2][1])
|
||||
self.mock_publish.async_publish.assert_called_once_with(
|
||||
'vacuum/command', 'stop', 0, False)
|
||||
self.mock_publish.async_publish.reset_mock()
|
||||
|
||||
vacuum.clean_spot(self.hass, 'vacuum.mqtttest')
|
||||
self.hass.block_till_done()
|
||||
self.assertEqual(('vacuum/command', 'clean_spot', 0, False),
|
||||
self.mock_publish.mock_calls[-2][1])
|
||||
self.mock_publish.async_publish.assert_called_once_with(
|
||||
'vacuum/command', 'clean_spot', 0, False)
|
||||
self.mock_publish.async_publish.reset_mock()
|
||||
|
||||
vacuum.locate(self.hass, 'vacuum.mqtttest')
|
||||
self.hass.block_till_done()
|
||||
self.assertEqual(('vacuum/command', 'locate', 0, False),
|
||||
self.mock_publish.mock_calls[-2][1])
|
||||
self.mock_publish.async_publish.assert_called_once_with(
|
||||
'vacuum/command', 'locate', 0, False)
|
||||
self.mock_publish.async_publish.reset_mock()
|
||||
|
||||
vacuum.start_pause(self.hass, 'vacuum.mqtttest')
|
||||
self.hass.block_till_done()
|
||||
self.assertEqual(('vacuum/command', 'start_pause', 0, False),
|
||||
self.mock_publish.mock_calls[-2][1])
|
||||
self.mock_publish.async_publish.assert_called_once_with(
|
||||
'vacuum/command', 'start_pause', 0, False)
|
||||
self.mock_publish.async_publish.reset_mock()
|
||||
|
||||
vacuum.return_to_base(self.hass, 'vacuum.mqtttest')
|
||||
self.hass.block_till_done()
|
||||
self.assertEqual(('vacuum/command', 'return_to_base', 0, False),
|
||||
self.mock_publish.mock_calls[-2][1])
|
||||
self.mock_publish.async_publish.assert_called_once_with(
|
||||
'vacuum/command', 'return_to_base', 0, False)
|
||||
self.mock_publish.async_publish.reset_mock()
|
||||
|
||||
vacuum.set_fan_speed(self.hass, 'high', 'vacuum.mqtttest')
|
||||
self.hass.block_till_done()
|
||||
self.assertEqual(
|
||||
('vacuum/set_fan_speed', 'high', 0, False),
|
||||
self.mock_publish.mock_calls[-2][1]
|
||||
)
|
||||
self.mock_publish.async_publish.assert_called_once_with(
|
||||
'vacuum/set_fan_speed', 'high', 0, False)
|
||||
self.mock_publish.async_publish.reset_mock()
|
||||
|
||||
vacuum.send_command(self.hass, '44 FE 93', entity_id='vacuum.mqtttest')
|
||||
self.hass.block_till_done()
|
||||
self.assertEqual(
|
||||
('vacuum/send_command', '44 FE 93', 0, False),
|
||||
self.mock_publish.mock_calls[-2][1]
|
||||
)
|
||||
self.mock_publish.async_publish.assert_called_once_with(
|
||||
'vacuum/send_command', '44 FE 93', 0, False)
|
||||
|
||||
def test_status(self):
|
||||
"""Test status updates from the vacuum."""
|
||||
|
||||
Reference in new issue
Block a user