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

Fix producers can be null #21

Merged
merged 1 commit into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion go2rtc_client/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from __future__ import annotations

from dataclasses import dataclass, field
from typing import Literal
from typing import Any, Literal

from awesomeversion import AwesomeVersion
from mashumaro import field_options
Expand Down Expand Up @@ -44,6 +44,15 @@ class Stream:

producers: list[Producer]

@classmethod
def __pre_deserialize__(cls, d: dict[Any, Any]) -> dict[Any, Any]:
"""Pre deserialize."""
# Ensure producers is always a list
if "producers" in d and d["producers"] is None:
d["producers"] = []

return d


@dataclass
class Producer:
Expand Down
8 changes: 8 additions & 0 deletions tests/__snapshots__/test_rest.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@
}),
})
# ---
# name: test_streams_get[without producers]
dict({
'camera.12mp_fluent': dict({
'producers': list([
]),
}),
})
# ---
# name: test_webrtc_offer
dict({
'sdp': 'v=0...',
Expand Down
31 changes: 31 additions & 0 deletions tests/fixtures/streams_without_producers.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"camera.12mp_fluent": {
"producers": null,
"consumers": [
{
"id": 1,
"format_name": "webrtc/json",
"protocol": "http+udp",
"remote_addr": "192.168.10.20:44460 prflx",
"user_agent": "HomeAssistant/2024.10.0.dev0 aiohttp/3.10.5 Python/3.12",
"medias": [
"video, sendonly, VP8, VP9, H264",
"audio, sendonly, OPUS/48000/2, G722/8000, PCMU/8000, PCMA/8000, L16, PCML"
],
"senders": [
{
"id": 4,
"codec": {
"codec_name": "h264",
"codec_type": "video"
},
"parent": 3,
"bytes": 1714455,
"packets": 1255
}
],
"bytes_send": 1733057
}
]
}
}
6 changes: 2 additions & 4 deletions tests/test_rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,11 @@ async def test_application_info(

@pytest.mark.parametrize(
"filename",
[
"streams_one.json",
"streams_none.json",
],
["streams_one.json", "streams_none.json", "streams_without_producers.json"],
ids=[
"one stream",
"empty",
"without producers",
],
)
async def test_streams_get(
Expand Down