Add sample_bytes to media player supported format and a test (#955)

This commit is contained in:
Michael Hansen 2024-09-09 15:12:04 -05:00 committed by GitHub
parent 5a120d7293
commit a2a0bbfb4b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 226 additions and 194 deletions

View File

@ -1145,6 +1145,7 @@ message MediaPlayerSupportedFormat {
uint32 sample_rate = 2;
uint32 num_channels = 3;
MediaPlayerFormatPurpose purpose = 4;
uint32 sample_bytes = 5;
}
message ListEntitiesMediaPlayerResponse {
option (id) = 63;

File diff suppressed because one or more lines are too long

View File

@ -835,6 +835,7 @@ class MediaPlayerSupportedFormat(APIModelBase):
default=MediaPlayerFormatPurpose.DEFAULT,
converter=MediaPlayerFormatPurpose.convert,
)
sample_bytes: int = 0
@classmethod
def convert_list(cls, value: list[Any]) -> list[MediaPlayerSupportedFormat]:

View File

@ -45,6 +45,7 @@ from aioesphomeapi.api_pb2 import (
ListEntitiesValveResponse,
LockStateResponse,
MediaPlayerStateResponse,
MediaPlayerSupportedFormat,
NumberStateResponse,
SelectStateResponse,
SensorStateResponse,
@ -651,3 +652,32 @@ async def test_bluetooth_gatt_services_from_dict() -> None:
assert BluetoothGATTDescriptorModel.from_dict(
{"uuid": [1, 3], "handle": 3},
) == BluetoothGATTDescriptorModel(uuid=[1, 3], handle=3)
def test_media_player_supported_format_convert_list() -> None:
"""Test list conversion for MediaPlayerSupportedFormat."""
assert MediaPlayerInfo.from_dict(
{
"supports_pause": False,
"supported_formats": [
{
"format": "flac",
"sample_rate": 48000,
"num_channels": 2,
"purpose": 1,
"sample_bytes": 2,
}
],
}
) == MediaPlayerInfo(
supports_pause=False,
supported_formats=[
MediaPlayerSupportedFormat(
format="flac",
sample_rate=48000,
num_channels=2,
purpose=1,
sample_bytes=2,
)
],
)