Config validation for MQTT device_tracker platform.
This commit is contained in:
parent
287f0f4f68
commit
88da42fe62
2 changed files with 14 additions and 13 deletions
|
@ -6,28 +6,26 @@ https://home-assistant.io/components/device_tracker.mqtt/
|
||||||
"""
|
"""
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
import voluptuous as vol
|
||||||
|
|
||||||
import homeassistant.components.mqtt as mqtt
|
import homeassistant.components.mqtt as mqtt
|
||||||
from homeassistant import util
|
import homeassistant.helpers.config_validation as cv
|
||||||
|
|
||||||
DEPENDENCIES = ['mqtt']
|
DEPENDENCIES = ['mqtt']
|
||||||
|
|
||||||
CONF_QOS = 'qos'
|
|
||||||
CONF_DEVICES = 'devices'
|
CONF_DEVICES = 'devices'
|
||||||
|
|
||||||
DEFAULT_QOS = 0
|
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
PLATFORM_SCHEMA = mqtt.MQTT_BASE_PLATFORM_SCHEMA.extend({
|
||||||
|
vol.Required(CONF_DEVICES): {cv.string: mqtt.valid_subscribe_topic},
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
def setup_scanner(hass, config, see):
|
def setup_scanner(hass, config, see):
|
||||||
"""Setup the MQTT tracker."""
|
"""Setup the MQTT tracker."""
|
||||||
devices = config.get(CONF_DEVICES)
|
devices = config[CONF_DEVICES]
|
||||||
qos = util.convert(config.get(CONF_QOS), int, DEFAULT_QOS)
|
qos = config[mqtt.CONF_QOS]
|
||||||
|
|
||||||
if not isinstance(devices, dict):
|
|
||||||
_LOGGER.error('Expected %s to be a dict, found %s', CONF_DEVICES,
|
|
||||||
devices)
|
|
||||||
return False
|
|
||||||
|
|
||||||
dev_id_lookup = {}
|
dev_id_lookup = {}
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
import unittest
|
import unittest
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
from homeassistant.bootstrap import _setup_component
|
||||||
from homeassistant.components import device_tracker
|
from homeassistant.components import device_tracker
|
||||||
from homeassistant.const import CONF_PLATFORM
|
from homeassistant.const import CONF_PLATFORM
|
||||||
|
|
||||||
|
@ -31,11 +32,13 @@ class TestComponentsDeviceTrackerMQTT(unittest.TestCase):
|
||||||
topic = '/location/paulus'
|
topic = '/location/paulus'
|
||||||
location = 'work'
|
location = 'work'
|
||||||
|
|
||||||
self.assertTrue(device_tracker.setup(self.hass, {
|
self.hass.config.components = ['mqtt', 'zone']
|
||||||
|
assert _setup_component(self.hass, device_tracker.DOMAIN, {
|
||||||
device_tracker.DOMAIN: {
|
device_tracker.DOMAIN: {
|
||||||
CONF_PLATFORM: 'mqtt',
|
CONF_PLATFORM: 'mqtt',
|
||||||
'devices': {dev_id: topic}
|
'devices': {dev_id: topic}
|
||||||
}}))
|
}
|
||||||
|
})
|
||||||
fire_mqtt_message(self.hass, topic, location)
|
fire_mqtt_message(self.hass, topic, location)
|
||||||
self.hass.pool.block_till_done()
|
self.hass.pool.block_till_done()
|
||||||
self.assertEqual(location, self.hass.states.get(enttiy_id).state)
|
self.assertEqual(location, self.hass.states.get(enttiy_id).state)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue