Skip to content

Commit

Permalink
Add support for alarm_control_panel to MQTT Discovery. (#15689)
Browse files Browse the repository at this point in the history
  • Loading branch information
rorr73 authored and balloob committed Jul 27, 2018
1 parent b2f4bbf commit cd6544d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
3 changes: 3 additions & 0 deletions homeassistant/components/alarm_control_panel/mqtt.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@
@asyncio.coroutine
def async_setup_platform(hass, config, async_add_devices, discovery_info=None):
"""Set up the MQTT Alarm Control Panel platform."""
if discovery_info is not None:
config = PLATFORM_SCHEMA(discovery_info)

async_add_devices([MqttAlarm(
config.get(CONF_NAME),
config.get(CONF_STATE_TOPIC),
Expand Down
4 changes: 3 additions & 1 deletion homeassistant/components/mqtt/discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@

SUPPORTED_COMPONENTS = [
'binary_sensor', 'camera', 'cover', 'fan',
'light', 'sensor', 'switch', 'lock', 'climate']
'light', 'sensor', 'switch', 'lock', 'climate',
'alarm_control_panel']

ALLOWED_PLATFORMS = {
'binary_sensor': ['mqtt'],
Expand All @@ -33,6 +34,7 @@
'sensor': ['mqtt'],
'switch': ['mqtt'],
'climate': ['mqtt'],
'alarm_control_panel': ['mqtt'],
}

ALREADY_DISCOVERED = 'mqtt_discovered_components'
Expand Down
22 changes: 22 additions & 0 deletions tests/components/mqtt/test_discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,28 @@ def test_discover_climate(hass, mqtt_mock, caplog):
assert ('climate', 'bla') in hass.data[ALREADY_DISCOVERED]


@asyncio.coroutine
def test_discover_alarm_control_panel(hass, mqtt_mock, caplog):
"""Test discovering an MQTT alarm control panel component."""
yield from async_start(hass, 'homeassistant', {})

data = (
'{ "name": "AlarmControlPanelTest",'
' "state_topic": "test_topic",'
' "command_topic": "test_topic" }'
)

async_fire_mqtt_message(
hass, 'homeassistant/alarm_control_panel/bla/config', data)
yield from hass.async_block_till_done()

state = hass.states.get('alarm_control_panel.AlarmControlPanelTest')

assert state is not None
assert state.name == 'AlarmControlPanelTest'
assert ('alarm_control_panel', '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."""
Expand Down

0 comments on commit cd6544d

Please sign in to comment.