Skip to content

Commit

Permalink
Add MediaPlayerSupportedFormat (#925)
Browse files Browse the repository at this point in the history
Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>
  • Loading branch information
synesthesiam and jesserockz authored Aug 27, 2024
1 parent 7d07197 commit 2ba7774
Show file tree
Hide file tree
Showing 3 changed files with 250 additions and 187 deletions.
15 changes: 15 additions & 0 deletions aioesphomeapi/api.proto
Original file line number Diff line number Diff line change
Expand Up @@ -1134,6 +1134,19 @@ enum MediaPlayerCommand {
MEDIA_PLAYER_COMMAND_MUTE = 3;
MEDIA_PLAYER_COMMAND_UNMUTE = 4;
}
enum MediaPlayerFormatPurpose {
MEDIA_PLAYER_FORMAT_PURPOSE_DEFAULT = 0;
MEDIA_PLAYER_FORMAT_PURPOSE_ANNOUNCEMENT = 1;
}
message MediaPlayerSupportedFormat {
option (id) = 119;
option (ifdef) = "USE_MEDIA_PLAYER";

string format = 1;
uint32 sample_rate = 2;
uint32 num_channels = 3;
MediaPlayerFormatPurpose purpose = 4;
}
message ListEntitiesMediaPlayerResponse {
option (id) = 63;
option (source) = SOURCE_SERVER;
Expand All @@ -1149,6 +1162,8 @@ message ListEntitiesMediaPlayerResponse {
EntityCategory entity_category = 7;

bool supports_pause = 8;

repeated MediaPlayerSupportedFormat supported_formats = 9;
}
message MediaPlayerStateResponse {
option (id) = 64;
Expand Down
392 changes: 205 additions & 187 deletions aioesphomeapi/api_pb2.py

Large diffs are not rendered by default.

30 changes: 30 additions & 0 deletions aioesphomeapi/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -820,10 +820,40 @@ class MediaPlayerCommand(APIIntEnum):
UNMUTE = 4


class MediaPlayerFormatPurpose(APIIntEnum):
DEFAULT = 0
ANNOUNCEMENT = 1


@_frozen_dataclass_decorator
class MediaPlayerSupportedFormat(APIModelBase):
format: str
sample_rate: int
num_channels: int
purpose: MediaPlayerFormatPurpose | None = converter_field(
default=MediaPlayerFormatPurpose.DEFAULT,
converter=MediaPlayerFormatPurpose.convert,
)

@classmethod
def convert_list(cls, value: list[Any]) -> list[MediaPlayerSupportedFormat]:
ret = []
for x in value:
if isinstance(x, dict):

This comment has been minimized.

Copy link
@bdraco

bdraco Sep 3, 2024

Member

It looks like we are missing coverage for these lines.

It also looks like codecov reporting is broken for this repo.

ret.append(MediaPlayerSupportedFormat.from_dict(x))
else:
ret.append(MediaPlayerSupportedFormat.from_pb(x))
return ret


@_frozen_dataclass_decorator
class MediaPlayerInfo(EntityInfo):
supports_pause: bool = False

supported_formats: list[MediaPlayerSupportedFormat] = converter_field(
default_factory=list, converter=MediaPlayerSupportedFormat.convert_list
)


@_frozen_dataclass_decorator
class MediaPlayerEntityState(EntityState):
Expand Down

0 comments on commit 2ba7774

Please sign in to comment.