mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 05:07:41 +00:00
Adds MQTT Fan Discovery (#9463)
This commit is contained in:
parent
bda6d2c696
commit
8a3f8457e8
@ -78,6 +78,9 @@ PLATFORM_SCHEMA = mqtt.MQTT_RW_PLATFORM_SCHEMA.extend({
|
|||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def async_setup_platform(hass, config, async_add_devices, discovery_info=None):
|
def async_setup_platform(hass, config, async_add_devices, discovery_info=None):
|
||||||
"""Set up the MQTT fan platform."""
|
"""Set up the MQTT fan platform."""
|
||||||
|
if discovery_info is not None:
|
||||||
|
config = PLATFORM_SCHEMA(discovery_info)
|
||||||
|
|
||||||
async_add_devices([MqttFan(
|
async_add_devices([MqttFan(
|
||||||
config.get(CONF_NAME),
|
config.get(CONF_NAME),
|
||||||
{
|
{
|
||||||
|
@ -20,10 +20,11 @@ TOPIC_MATCHER = re.compile(
|
|||||||
r'(?P<prefix_topic>\w+)/(?P<component>\w+)/'
|
r'(?P<prefix_topic>\w+)/(?P<component>\w+)/'
|
||||||
r'(?:(?P<node_id>[a-zA-Z0-9_-]+)/)?(?P<object_id>[a-zA-Z0-9_-]+)/config')
|
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 = {
|
ALLOWED_PLATFORMS = {
|
||||||
'binary_sensor': ['mqtt'],
|
'binary_sensor': ['mqtt'],
|
||||||
|
'fan': ['mqtt'],
|
||||||
'light': ['mqtt', 'mqtt_json', 'mqtt_template'],
|
'light': ['mqtt', 'mqtt_json', 'mqtt_template'],
|
||||||
'sensor': ['mqtt'],
|
'sensor': ['mqtt'],
|
||||||
'switch': ['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]
|
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
|
@asyncio.coroutine
|
||||||
def test_discovery_incl_nodeid(hass, mqtt_mock, caplog):
|
def test_discovery_incl_nodeid(hass, mqtt_mock, caplog):
|
||||||
"""Test sending in correct JSON with optional node_id included."""
|
"""Test sending in correct JSON with optional node_id included."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user