MQTT: Managing binary payloads (#6976)

* Managing binary payloads

Hello,
background: I wrote a HA camera component that gets the image from a binary payload. I'm testing it with Zanzito (https://play.google.com/store/apps/details?id=it.barbaro.zanzito) and it works apparently well: it gets the image and correctly displays it in the front-end.
But I had to make the changes I'm proposing here: the message was being blocked because the utf-8 decoding failed.
As far as I know, the utf-8 encoding is required for the topic, not for the payload. What I did here was try the utf-8 decoding, but even if unsuccessful, it dispatches the message anyway.
Is there anything else I'm missing?
thanks
Gianluca

* Update __init__.py

* Update __init__.py

* Update __init__.py

* git test - ignore

* Should work

* minor fixes

* updated mqtt/services.yaml

* added two tests, modified threaded subscribe

* removing polymer

* requested changes

* requested changes - minor fix

* security wrap around payload_file_path

* services.yaml updated

* removed file publishing

* minor fix
This commit is contained in:
Gianluca Barbaro authored and Paulus Schoutsen committed 2017-04-13 07:38:09 -07:00
1 parent 9a9342ec3f
commit fa65783f39
3 files changed
+64 -58

No files matched your search

+4 -1
View File
@@ -170,8 +170,11 @@ def mock_service(hass, domain, service):
@ha.callback
def async_fire_mqtt_message(hass, topic, payload, qos=0):
"""Fire the MQTT message."""
if isinstance(payload, str):
payload = payload.encode('utf-8')
async_dispatcher_send(
hass, mqtt.SIGNAL_MQTT_MESSAGE_RECEIVED, topic, payload, qos)
hass, mqtt.SIGNAL_MQTT_MESSAGE_RECEIVED, topic,
payload, qos)
def fire_mqtt_message(hass, topic, payload, qos=0):