Skip to content

Commit c4f1ba4

Browse files
authored
Fix producers can be null (#21)
1 parent 61087e4 commit c4f1ba4

File tree

4 files changed

+51
-5
lines changed

4 files changed

+51
-5
lines changed

go2rtc_client/models.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from __future__ import annotations
44

55
from dataclasses import dataclass, field
6-
from typing import Literal
6+
from typing import Any, Literal
77

88
from awesomeversion import AwesomeVersion
99
from mashumaro import field_options
@@ -44,6 +44,15 @@ class Stream:
4444

4545
producers: list[Producer]
4646

47+
@classmethod
48+
def __pre_deserialize__(cls, d: dict[Any, Any]) -> dict[Any, Any]:
49+
"""Pre deserialize."""
50+
# Ensure producers is always a list
51+
if "producers" in d and d["producers"] is None:
52+
d["producers"] = []
53+
54+
return d
55+
4756

4857
@dataclass
4958
class Producer:

tests/__snapshots__/test_rest.ambr

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@
2424
}),
2525
})
2626
# ---
27+
# name: test_streams_get[without producers]
28+
dict({
29+
'camera.12mp_fluent': dict({
30+
'producers': list([
31+
]),
32+
}),
33+
})
34+
# ---
2735
# name: test_webrtc_offer
2836
dict({
2937
'sdp': 'v=0...',
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"camera.12mp_fluent": {
3+
"producers": null,
4+
"consumers": [
5+
{
6+
"id": 1,
7+
"format_name": "webrtc/json",
8+
"protocol": "http+udp",
9+
"remote_addr": "192.168.10.20:44460 prflx",
10+
"user_agent": "HomeAssistant/2024.10.0.dev0 aiohttp/3.10.5 Python/3.12",
11+
"medias": [
12+
"video, sendonly, VP8, VP9, H264",
13+
"audio, sendonly, OPUS/48000/2, G722/8000, PCMU/8000, PCMA/8000, L16, PCML"
14+
],
15+
"senders": [
16+
{
17+
"id": 4,
18+
"codec": {
19+
"codec_name": "h264",
20+
"codec_type": "video"
21+
},
22+
"parent": 3,
23+
"bytes": 1714455,
24+
"packets": 1255
25+
}
26+
],
27+
"bytes_send": 1733057
28+
}
29+
]
30+
}
31+
}

tests/test_rest.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,11 @@ async def test_application_info(
4444

4545
@pytest.mark.parametrize(
4646
"filename",
47-
[
48-
"streams_one.json",
49-
"streams_none.json",
50-
],
47+
["streams_one.json", "streams_none.json", "streams_without_producers.json"],
5148
ids=[
5249
"one stream",
5350
"empty",
51+
"without producers",
5452
],
5553
)
5654
async def test_streams_get(

0 commit comments

Comments
 (0)