diff --git a/source/_cookbook/python_component_mqtt_basic.markdown b/source/_cookbook/python_component_mqtt_basic.markdown index f038f21969e..0d208a38736 100644 --- a/source/_cookbook/python_component_mqtt_basic.markdown +++ b/source/_cookbook/python_component_mqtt_basic.markdown @@ -34,8 +34,8 @@ DEFAULT_TOPIC = 'home-assistant/hello_mqtt' def setup(hass, config): """Set up the Hello MQTT component.""" - mqtt = loader.get_component('mqtt') - topic = config[DOMAIN].get('topic', DEFAULT_TOPIC) + mqtt = hass.components.mqtt + topic = config[DOMAIN].get(CONF_TOPIC, DEFAULT_TOPIC) entity_id = 'hello_mqtt.last_message' # Listener to be called when we receive a message. @@ -44,7 +44,7 @@ def setup(hass, config): hass.states.set(entity_id, payload) # Subscribe our listener to a topic. - mqtt.subscribe(hass, topic, message_received) + mqtt.subscribe(topic, message_received) # Set the initial state. hass.states.set(entity_id, 'No messages') @@ -52,7 +52,7 @@ def setup(hass, config): # Service to publish a message on MQTT. def set_state_service(call): """Service to send a message.""" - mqtt.publish(hass, topic, call.data.get('new_state')) + mqtt.publish(topic, call.data.get('new_state')) # Register our service with Home Assistant. hass.services.register(DOMAIN, 'set_state', set_state_service)