Adds MQTT Fan Discovery (#9463)
This commit is contained in:
parent
bda6d2c696
commit
8a3f8457e8
3 changed files with 22 additions and 1 deletions
|
@ -78,6 +78,9 @@ PLATFORM_SCHEMA = mqtt.MQTT_RW_PLATFORM_SCHEMA.extend({
|
|||
@asyncio.coroutine
|
||||
def async_setup_platform(hass, config, async_add_devices, discovery_info=None):
|
||||
"""Set up the MQTT fan platform."""
|
||||
if discovery_info is not None:
|
||||
config = PLATFORM_SCHEMA(discovery_info)
|
||||
|
||||
async_add_devices([MqttFan(
|
||||
config.get(CONF_NAME),
|
||||
{
|
||||
|
|
|
@ -20,10 +20,11 @@ TOPIC_MATCHER = re.compile(
|
|||
r'(?P<prefix_topic>\w+)/(?P<component>\w+)/'
|
||||
r'(?:(?P<node_id>[a-zA-Z0-9_-]+)/)?(?P<object_id>[a-zA-Z0-9_-]+)/config')
|
||||
|
||||
SUPPORTED_COMPONENTS = ['binary_sensor', 'light', 'sensor', 'switch']
|
||||
SUPPORTED_COMPONENTS = ['binary_sensor', 'fan', 'light', 'sensor', 'switch']
|
||||
|
||||
ALLOWED_PLATFORMS = {
|
||||
'binary_sensor': ['mqtt'],
|
||||
'fan': ['mqtt'],
|
||||
'light': ['mqtt', 'mqtt_json', 'mqtt_template'],
|
||||
'sensor': ['mqtt'],
|
||||
'switch': ['mqtt'],
|
||||
|
|
|
@ -77,6 +77,23 @@ def test_correct_config_discovery(hass, mqtt_mock, caplog):
|
|||
assert ('binary_sensor', 'bla') in hass.data[ALREADY_DISCOVERED]
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def test_discover_fan(hass, mqtt_mock, caplog):
|
||||
"""Test discovering an MQTT fan."""
|
||||
yield from async_start(hass, 'homeassistant', {})
|
||||
|
||||
async_fire_mqtt_message(hass, 'homeassistant/fan/bla/config',
|
||||
('{ "name": "Beer",'
|
||||
' "command_topic": "test_topic" }'))
|
||||
yield from hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get('fan.beer')
|
||||
|
||||
assert state is not None
|
||||
assert state.name == 'Beer'
|
||||
assert ('fan', '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."""
|
||||
|
|
Loading…
Add table
Reference in a new issue