mirror of
https://github.com/home-assistant/home-assistant.io.git
synced 2025-07-18 23:06:58 +00:00
Update python_component_mqtt_basic.markdown with new callback (#8932)
This commit is contained in:
parent
d44940a233
commit
1e5ffc33a6
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user