The Message Class
Python SDK, Javascript SDK
To provide an abstraction of the information exchanged in the bus without requiring the developer to deal with topics and messages' payload, any message received or sent is represented as a Message object.
The following information are directly accessible for each instance of Message
:
message.topic
: topic from which the message comes from, populated only for incoming messagesmessage.house_id
: house idmessage.sender
: sender modulemessage.recipient
: recipient modulemessage.command
: requested command to executemessage.args
: arguments of the commandmessage.config_schema
: version of the schema of configuration file (if a configuration)message.is_null
: set to true when payload is null (e.g. deleted configuration file)
The information above are automatically populated by the SDK when receiving a new message from the message bus or by the developer when sending out a new message.
Additionally, the following functions are provided:
reset()
: reset the messageclear()
: clear the payload onlyparse(topic, payload, retain)
: parse MQTT message (topic and payload)set_data(value)
: set the payload to value (value can be of any type, e.g. string, dict, etc.)set(key, value)
: set key of the payload to valueset_null()
: set the payload to nullget(key)
: get the value of key of the payloadhas(key)
: return true if payload has the given keyget_data()
: get the value of the payloadget_request_id()
: get the request_idreply()
: reply to this messageforward(recipient)
: forward this message to another moduledump()
: print out the content of this message