Add discovery support to mqtt climate component. (#15085)
* Add discovery support to mqtt climate component. * - Fix flake8 error (./homeassistant/components/climate/mqtt.py:130:1: D202 No blank lines allowed after function docstring) - Fix test error (since climate component was expected not to work - changed it to "lock" component, which also does not have MQTT discovery support yet) * Fix old assert statement to reflect new lock component usage * Change invalid MQTT discovery component type from 'lock' to 'timer', since contrary to the documentation the lock component is properly supported when using MQTT discovery. * Make configuration of invalid MQTT config component a single point of entry to prevent missing the assertion later in the code when changing. * Add new testcases to cover not-yet-covered code paths in https://github.com/home-assistant/home-assistant/blob/dev/homeassistant/components/climate/mqtt.py
This commit is contained in:
1 parent
d3ceb9080c
commit
73034c933e
4 files changed
+118
-4
No files matched your search
@@ -52,12 +52,21 @@ def test_invalid_json(mock_load_platform, hass, mqtt_mock, caplog):
|
||||
@asyncio.coroutine
|
||||
def test_only_valid_components(mock_load_platform, hass, mqtt_mock, caplog):
|
||||
"""Test for a valid component."""
|
||||
invalid_component = "timer"
|
||||
|
||||
mock_load_platform.return_value = mock_coro()
|
||||
yield from async_start(hass, 'homeassistant', {})
|
||||
|
||||
async_fire_mqtt_message(hass, 'homeassistant/climate/bla/config', '{}')
|
||||
async_fire_mqtt_message(hass, 'homeassistant/{}/bla/config'.format(
|
||||
invalid_component
|
||||
), '{}')
|
||||
|
||||
yield from hass.async_block_till_done()
|
||||
assert 'Component climate is not supported' in caplog.text
|
||||
|
||||
assert 'Component {} is not supported'.format(
|
||||
invalid_component
|
||||
) in caplog.text
|
||||
|
||||
assert not mock_load_platform.called
|
||||
|
||||
|
||||
@@ -94,6 +103,27 @@ def test_discover_fan(hass, mqtt_mock, caplog):
|
||||
assert ('fan', 'bla') in hass.data[ALREADY_DISCOVERED]
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def test_discover_climate(hass, mqtt_mock, caplog):
|
||||
"""Test discovering an MQTT climate component."""
|
||||
yield from async_start(hass, 'homeassistant', {})
|
||||
|
||||
data = (
|
||||
'{ "name": "ClimateTest",'
|
||||
' "current_temperature_topic": "climate/bla/current_temp",'
|
||||
' "temperature_command_topic": "climate/bla/target_temp" }'
|
||||
)
|
||||
|
||||
async_fire_mqtt_message(hass, 'homeassistant/climate/bla/config', data)
|
||||
yield from hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get('climate.ClimateTest')
|
||||
|
||||
assert state is not None
|
||||
assert state.name == 'ClimateTest'
|
||||
assert ('climate', 'bla') in hass.data[ALREADY_DISCOVERED]
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def test_discovery_incl_nodeid(hass, mqtt_mock, caplog):
|
||||
"""Test sending in correct JSON with optional node_id included."""
|
||||
|
||||
Reference in new issue
Block a user