Skip to content

Commit

Permalink
Update python_component_mqtt_basic.markdown with new callback (#8932)
Browse files Browse the repository at this point in the history
  • Loading branch information
emontnemery authored and balloob committed Mar 14, 2019
1 parent d44940a commit 1e5ffc3
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions source/_cookbook/python_component_mqtt_basic.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,11 @@ def setup(hass, config):
entity_id = 'hello_mqtt.last_message'

# Listener to be called when we receive a message.
def message_received(topic, payload, qos):
# The msg parameter is a Message object with the following members:
# - topic, payload, qos, retain
def message_received(msg):
"""Handle new MQTT messages."""
hass.states.set(entity_id, payload)
hass.states.set(entity_id, msg.payload)

# Subscribe our listener to a topic.
mqtt.subscribe(topic, message_received)
Expand Down

0 comments on commit 1e5ffc3

Please sign in to comment.