blakeblackshear / frigate-hass-integration

Frigate integration for Home Assistant
MIT License
728 stars 114 forks source link

Fix media browser errors when used with Frigate 0.12 #618

Closed NickM-27 closed 8 months ago

NickM-27 commented 8 months ago

fixes https://github.com/blakeblackshear/frigate-hass-integration/issues/600

codecov[bot] commented 8 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Comparison is base (02ab137) 100.00% compared to head (0fe132f) 100.00%.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #618 +/- ## ========================================= Coverage 100.00% 100.00% ========================================= Files 16 16 Lines 2017 2017 ========================================= Hits 2017 2017 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

dermotduffy commented 8 months ago

Planning a new build from master, or should we put this in the dev branch?

NickM-27 commented 8 months ago

I figured it would be good to get it out soon, so master made sense

mcauwelier commented 6 months ago

I'm currently on frigate 0.13.2 and frigate-hass-integration 5.0.1 and I still have these media browser errors for clips and snapshots. By downgrading the frigate-hass-integration to 5.0.0 this is resolved.

NickM-27 commented 6 months ago

the error definitely won't be the same given the way that the code changed. It is all using safe access

mcauwelier commented 6 months ago

Below you can find the error for frigate 0.13.2 in combination with frigate-hass-integration 5.0.1:

`Logger: homeassistant.components.websocket_api.http.connection Source: custom_components/frigate/media_source.py:860 integration: Home Assistant WebSocket API (documentation, issues) First occurred: 21:05:14 (1 occurrences) Last logged: 21:05:14

[547275896384] Error handling message: Unknown error (unknown_error) Matthias Cauwelier from 157.97.122.59 (Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36) Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/components/websocket_api/decorators.py", line 26, in _handle_async_response await func(hass, connection, msg) File "/usr/src/homeassistant/homeassistant/components/media_source/init.py", line 177, in websocket_browse_media media = await async_browse_media(hass, msg.get("media_content_id", "")) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/media_source/init.py", line 125, in async_browse_media item = await _get_media_item(hass, media_content_id, None).async_browse() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/media_source/models.py", line 79, in async_browse return await self.async_media_source().async_browse_media(self) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/frigate/media_source.py", line 692, in async_browse_media return self._browse_events( ^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/frigate/media_source.py", line 774, in _browse_events event_items = self._build_event_response(identifier, events) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/frigate/media_source.py", line 860, in _build_event_response title=f"{dt.datetime.fromtimestamp(event['start_time'], DEFAULT_TIME_ZONE).strftime(DATE_STR_FORMAT)} [{duration}s, {event['label'].capitalize()} {int((event['data'].get('top_score') or event['top_score'])*100)}%]",


TypeError: unsupported operand type(s) for *: 'NoneType' and 'int'
`
This seems to be the same as in #600 
NickM-27 commented 6 months ago

It's not the same exactly, we can see here that the new code is having this issue because somehow top score doesn't exist in either place which is a separate issue and potentially a backend issue. It would be good to know what the metadata is for this event that is causing the error.

mcauwelier commented 6 months ago

I'm using 'manually' triggered event (https://docs.frigate.video/integrations/api/#post-apieventscamera_namelabelcreate) instead of an event triggered by a motion or an object detection.

perhaps this is the reason why there is no top_score. If you need more info or metadata, could you explain what exactly and where to extract it?