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

Add MediaPlayerSupportedFormat #925

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
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):
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
Loading