frigate-hass-integration: Adding debug: true to Home Assistant 2024.5.0b0 generates Exception in _state_message_received errors

Version of the custom_component

5.1.0

Configuration


Logger: homeassistant.util.logging
Source: util/logging.py:98
First occurred: 6:45:40 AM (10 occurrences)
Last logged: 6:45:41 AM

Exception in _state_message_received when handling msg on 'frigate/camera/recordings/state': 'ON' Traceback (most recent call last): File "/config/custom_components/frigate/camera.py", line 241, in _state_message_received self._attr_is_recording = msg.payload.decode("utf-8") == "ON" ^^^^^^^^^^^^^^^^^^ AttributeError: 'str' object has no attribute 'decode'. Did you mean: 'encode'?
Exception in _motion_message_received when handling msg on 'frigate/camera_2/motion/state': 'ON' Traceback (most recent call last): File "/config/custom_components/frigate/camera.py", line 247, in _motion_message_received self._attr_motion_detection_enabled = msg.payload.decode("utf-8") == "ON" ^^^^^^^^^^^^^^^^^^ AttributeError: 'str' object has no attribute 'decode'. Did you mean: 'encode'?
Exception in _state_message_received when handling msg on 'frigate/camera_2/recordings/state': 'ON' Traceback (most recent call last): File "/config/custom_components/frigate/camera.py", line 241, in _state_message_received self._attr_is_recording = msg.payload.decode("utf-8") == "ON" ^^^^^^^^^^^^^^^^^^ AttributeError: 'str' object has no attribute 'decode'. Did you mean: 'encode'?
Exception in _motion_message_received when handling msg on 'frigate/g_camera/motion/state': 'ON' Traceback (most recent call last): File "/config/custom_components/frigate/camera.py", line 247, in _motion_message_received self._attr_motion_detection_enabled = msg.payload.decode("utf-8") == "ON" ^^^^^^^^^^^^^^^^^^ AttributeError: 'str' object has no attribute 'decode'. Did you mean: 'encode'?
Exception in _state_message_received when handling msg on 'frigate/g_camera/recordings/state': 'ON' Traceback (most recent call last): File "/config/custom_components/frigate/camera.py", line 241, in _state_message_received self._attr_is_recording = msg.payload.decode("utf-8") == "ON" ^^^^^^^^^^^^^^^^^^ AttributeError: 'str' object has no attribute 'decode'. Did you mean: 'encode'?

Describe the bug

Changing line 247 and 241 from decode to encode fixes the error but I have no idea if this is the right path

Debug log


Add your logs here.

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 5
  • Comments: 41

Most upvoted comments

Confirming 5.2.0 working as expected, and many thanks for the prompt fix. (thumbs-up + party emoticons)

The fix PR is merged. I’ll do a v5.2.0 release tomorrow.

Right but the issue at hand is that the switch provided by the integration is toggling itself off

Prior to the “fix”, the backend would report ‘ON’ but the integration would interpret it as ‘OFF’. That causes the HA state to appear to be out of sync. Here’s how it looks now:

Peek 2024-05-05 10-20

It’s a little hard to see without the mouse cursor, but:

  • When detect is manually turned on, you’ll notice motion turns on too.
  • When motion is manually turned off, but detect is on, motion will reset itself to on.
  • When detect is manually turned off, then motion can be turned off.

Some progress: The recordings state data is being received as b'ON' not ON, yet the comparison to determine the state in the integration is just against ON If we decode the string first, the recordings switch starts to work correctly. There’s a similar issue in reverse in camera.py which explains the exceptions shown at the start of this issue.

I think motion might be a subtly different problem / race condition, still looking…

I suspect there might be multiple unrelated reports mixed here. I cannot get any exceptions thrown no matter what I do, with or without debug: true.

However, I can definitely see the switch state behavior problem with recordings and motion only. In this image, I turn all 4 entities on and 2 of them immediately reset:

problem

Versions:

  • Integration/Frigate: 5.1.0/0.13.2-6476f8a
  • HA: 2024.5.1

Right but the issue at hand is that the switch provided by the integration is toggling itself off

Prior to the “fix”, the backend would report ‘ON’ but the integration would interpret it as ‘OFF’. That causes the HA state to appear to be out of sync. Here’s how it looks now:

Peek 2024-05-05 10-20 Peek 2024-05-05 10-20

It’s a little hard to see without the mouse cursor, but:

  • When detect is manually turned on, you’ll notice motion turns on too.
  • When motion is manually turned off, but detect is on, motion will reset itself to on.
  • When detect is manually turned off, then motion can be turned off.

I have the same issue with the “Motion” boolean. I can confirm the other booleans (Detect, Recordings, Snapshot) work correct after the v5.2 update .

Thank you for your support and attention to this. Much appreciated!

YMMV on this but I rolled back to 2024.4.4 without any issues. Everything is back to working as expected.