1# Copyright 2024 Google LLC
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7#      https://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15# -----------------------------------------------------------------------------
16# Imports
17# -----------------------------------------------------------------------------
18from __future__ import annotations
19import dataclasses
20import enum
21from typing_extensions import Self
22
23from bumble.profiles import le_audio
24
25
26# -----------------------------------------------------------------------------
27# Classes
28# -----------------------------------------------------------------------------
29@dataclasses.dataclass
30class PublicBroadcastAnnouncement:
31    class Features(enum.IntFlag):
32        ENCRYPTED = 1 << 0
33        STANDARD_QUALITY_CONFIGURATION = 1 << 1
34        HIGH_QUALITY_CONFIGURATION = 1 << 2
35
36    features: Features
37    metadata: le_audio.Metadata
38
39    @classmethod
40    def from_bytes(cls, data: bytes) -> Self:
41        features = cls.Features(data[0])
42        metadata_length = data[1]
43        metadata_ltv = data[1 : 1 + metadata_length]
44        return cls(
45            features=features, metadata=le_audio.Metadata.from_bytes(metadata_ltv)
46        )
47