Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MQTT camera can't use encoding: b64 with availability topic #75597

Closed
mdegat01 opened this issue Jul 21, 2022 · 3 comments · Fixed by #76124
Closed

MQTT camera can't use encoding: b64 with availability topic #75597

mdegat01 opened this issue Jul 21, 2022 · 3 comments · Fixed by #76124
Assignees

Comments

@mdegat01
Copy link
Contributor

The problem

If you configure an MQTT camera with encoding: b64 then you cannot provide an availability_topic. If you do when the integration attempts to read messages from the availability topic then you receive errors like this:

Logger: homeassistant
Source: components/mqtt/client.py:586
First occurred: 6:21:14 PM (14 occurrences)
Last logged: 6:21:29 PM

    Error doing job: Exception in callback MQTT._mqtt_handle_message(<paho.mqtt.cl...xffff8bc5ef80>)
    Error doing job: Exception in callback MQTT._mqtt_handle_message(<paho.mqtt.cl...xffff8bc5f060>)
    Error doing job: Exception in callback MQTT._mqtt_handle_message(<paho.mqtt.cl...xffff8bc5f300>)
    Error doing job: Exception in callback MQTT._mqtt_handle_message(<paho.mqtt.cl...xffff87f78040>)
    Error doing job: Exception in callback MQTT._mqtt_handle_message(<paho.mqtt.cl...xffff8d381690>)

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/asyncio/events.py", line 80, in _run
    self._context.run(self._callback, *self._args)
  File "/usr/src/homeassistant/homeassistant/components/mqtt/client.py", line 586, in _mqtt_handle_message
    payload = msg.payload.decode(subscription.encoding)
LookupError: unknown encoding: b64

As you can see it tries to provide that value to paho mqtt which does not understand it. Removing the availability_topic fixes it because this config option is handled correctly for normal messages to the cameras topic here:

if self._config[CONF_ENCODING] == "b64":
self._last_image = b64decode(msg.payload)

What version of Home Assistant Core has the issue?

core-2022.7.6

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant OS

Integration causing the issue

camera.mqtt

Link to integration documentation on our website

https://www.home-assistant.io/integrations/camera.mqtt/

Diagnostics information

No response

Example YAML snippet

mqtt:
  camera:
  - name: Family Room alert images test
    availability:
      - topic: blueiris/family-room/state
    topic: "blueiris/family-room/alert-image-b64"
    icon: mdi:cctv
    encoding: b64

Anything in the logs that might be useful for us?

Logger: homeassistant
Source: components/mqtt/client.py:586
First occurred: 6:21:14 PM (14 occurrences)
Last logged: 6:21:29 PM

    Error doing job: Exception in callback MQTT._mqtt_handle_message(<paho.mqtt.cl...xffff8bc5ef80>)
    Error doing job: Exception in callback MQTT._mqtt_handle_message(<paho.mqtt.cl...xffff8bc5f060>)
    Error doing job: Exception in callback MQTT._mqtt_handle_message(<paho.mqtt.cl...xffff8bc5f300>)
    Error doing job: Exception in callback MQTT._mqtt_handle_message(<paho.mqtt.cl...xffff87f78040>)
    Error doing job: Exception in callback MQTT._mqtt_handle_message(<paho.mqtt.cl...xffff8d381690>)

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/asyncio/events.py", line 80, in _run
    self._context.run(self._callback, *self._args)
  File "/usr/src/homeassistant/homeassistant/components/mqtt/client.py", line 586, in _mqtt_handle_message
    payload = msg.payload.decode(subscription.encoding)
LookupError: unknown encoding: b64

Additional information

No response

@probot-home-assistant
Copy link

mqtt documentation
mqtt source
(message by IssueLinks)

@probot-home-assistant
Copy link

Hey there @emontnemery, mind taking a look at this issue as it has been labeled with an integration (mqtt) you are listed as a code owner for? Thanks!
(message by CodeOwnersMention)

@jbouwh jbouwh mentioned this issue Aug 3, 2022
23 tasks
@jbouwh
Copy link
Contributor

jbouwh commented Aug 3, 2022

The problem is that the encoding parameter is used in two ways. For availability it should be utf-8 which is the default.
The linked PR will introduce a new image_encoding parameter to set the image encoding.
Setting encoding to b64 will work too with this fix, but is deprecated and will give a warning message in the log.

@github-actions github-actions bot locked and limited conversation to collaborators Sep 14, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants