Home Assistant Unofficial Reference 2024.12.1
const.py
Go to the documentation of this file.
1 """Constants for the Bang & Olufsen integration."""
2 
3 from __future__ import annotations
4 
5 from enum import StrEnum
6 from typing import Final
7 
8 from mozart_api.models import Source, SourceArray, SourceTypeEnum
9 
11  MediaPlayerState,
12  MediaType,
13  RepeatMode,
14 )
15 
16 
18  """Class used for associating device source ids with friendly names. May not include all sources."""
19 
20  LINE_IN: Final[Source] = Source(name="Line-In", id="lineIn")
21  SPDIF: Final[Source] = Source(name="Optical", id="spdif")
22  URI_STREAMER: Final[Source] = Source(name="Audio Streamer", id="uriStreamer")
23 
24 
25 BANG_OLUFSEN_STATES: dict[str, MediaPlayerState] = {
26  # Dict used for translating device states to Home Assistant states.
27  "started": MediaPlayerState.PLAYING,
28  "buffering": MediaPlayerState.PLAYING,
29  "idle": MediaPlayerState.IDLE,
30  "paused": MediaPlayerState.PAUSED,
31  "stopped": MediaPlayerState.PAUSED,
32  "ended": MediaPlayerState.PAUSED,
33  "error": MediaPlayerState.IDLE,
34  # A device's initial state is "unknown" and should be treated as "idle"
35  "unknown": MediaPlayerState.IDLE,
36 }
37 
38 # Dict used for translating Home Assistant settings to device repeat settings.
39 BANG_OLUFSEN_REPEAT_FROM_HA: dict[RepeatMode, str] = {
40  RepeatMode.ALL: "all",
41  RepeatMode.ONE: "track",
42  RepeatMode.OFF: "none",
43 }
44 # Dict used for translating device repeat settings to Home Assistant settings.
45 BANG_OLUFSEN_REPEAT_TO_HA: dict[str, RepeatMode] = {
46  value: key for key, value in BANG_OLUFSEN_REPEAT_FROM_HA.items()
47 }
48 
49 
50 # Media types for play_media
51 class BangOlufsenMediaType(StrEnum):
52  """Bang & Olufsen specific media types."""
53 
54  FAVOURITE = "favourite"
55  DEEZER = "deezer"
56  RADIO = "radio"
57  TIDAL = "tidal"
58  TTS = "provider"
59  OVERLAY_TTS = "overlay_tts"
60 
61 
62 class BangOlufsenModel(StrEnum):
63  """Enum for compatible model names."""
64 
65  BEOCONNECT_CORE = "Beoconnect Core"
66  BEOLAB_8 = "BeoLab 8"
67  BEOLAB_28 = "BeoLab 28"
68  BEOSOUND_2 = "Beosound 2 3rd Gen"
69  BEOSOUND_A5 = "Beosound A5"
70  BEOSOUND_A9 = "Beosound A9 5th Gen"
71  BEOSOUND_BALANCE = "Beosound Balance"
72  BEOSOUND_EMERGE = "Beosound Emerge"
73  BEOSOUND_LEVEL = "Beosound Level"
74  BEOSOUND_THEATRE = "Beosound Theatre"
75 
76 
77 # Dispatcher events
78 class WebsocketNotification(StrEnum):
79  """Enum for WebSocket notification types."""
80 
81  ACTIVE_LISTENING_MODE = "active_listening_mode"
82  PLAYBACK_ERROR = "playback_error"
83  PLAYBACK_METADATA = "playback_metadata"
84  PLAYBACK_PROGRESS = "playback_progress"
85  PLAYBACK_SOURCE = "playback_source"
86  PLAYBACK_STATE = "playback_state"
87  SOFTWARE_UPDATE_STATE = "software_update_state"
88  SOURCE_CHANGE = "source_change"
89  VOLUME = "volume"
90 
91  # Sub-notifications
92  BEOLINK = "beolink"
93  BEOLINK_PEERS = "beolinkPeers"
94  BEOLINK_LISTENERS = "beolinkListeners"
95  BEOLINK_AVAILABLE_LISTENERS = "beolinkAvailableListeners"
96  CONFIGURATION = "configuration"
97  NOTIFICATION = "notification"
98  REMOTE_MENU_CHANGED = "remoteMenuChanged"
99 
100  ALL = "all"
101 
102 
103 DOMAIN: Final[str] = "bang_olufsen"
104 
105 # Default values for configuration.
106 DEFAULT_MODEL: Final[str] = BangOlufsenModel.BEOSOUND_BALANCE
107 
108 # Configuration.
109 CONF_SERIAL_NUMBER: Final = "serial_number"
110 CONF_BEOLINK_JID: Final = "jid"
111 
112 # Models to choose from in manual configuration.
113 COMPATIBLE_MODELS: list[str] = [x.value for x in BangOlufsenModel]
114 
115 # Attribute names for zeroconf discovery.
116 ATTR_TYPE_NUMBER: Final[str] = "tn"
117 ATTR_SERIAL_NUMBER: Final[str] = "sn"
118 ATTR_ITEM_NUMBER: Final[str] = "in"
119 ATTR_FRIENDLY_NAME: Final[str] = "fn"
120 
121 # Power states.
122 BANG_OLUFSEN_ON: Final[str] = "on"
123 
124 VALID_MEDIA_TYPES: Final[tuple] = (
125  BangOlufsenMediaType.FAVOURITE,
126  BangOlufsenMediaType.DEEZER,
127  BangOlufsenMediaType.RADIO,
128  BangOlufsenMediaType.TTS,
129  BangOlufsenMediaType.TIDAL,
130  BangOlufsenMediaType.OVERLAY_TTS,
131  MediaType.MUSIC,
132  MediaType.URL,
133  MediaType.CHANNEL,
134 )
135 
136 
137 # Fallback sources to use in case of API failure.
138 FALLBACK_SOURCES: Final[SourceArray] = SourceArray(
139  items=[
140  Source(
141  id="uriStreamer",
142  is_enabled=True,
143  is_playable=True,
144  name="Audio Streamer",
145  type=SourceTypeEnum(value="uriStreamer"),
146  is_seekable=False,
147  ),
148  Source(
149  id="bluetooth",
150  is_enabled=True,
151  is_playable=True,
152  name="Bluetooth",
153  type=SourceTypeEnum(value="bluetooth"),
154  is_seekable=False,
155  ),
156  Source(
157  id="spotify",
158  is_enabled=True,
159  is_playable=True,
160  name="Spotify Connect",
161  type=SourceTypeEnum(value="spotify"),
162  is_seekable=True,
163  ),
164  Source(
165  id="lineIn",
166  is_enabled=True,
167  is_playable=True,
168  name="Line-In",
169  type=SourceTypeEnum(value="lineIn"),
170  is_seekable=False,
171  ),
172  Source(
173  id="spdif",
174  is_enabled=True,
175  is_playable=True,
176  name="Optical",
177  type=SourceTypeEnum(value="spdif"),
178  is_seekable=False,
179  ),
180  Source(
181  id="netRadio",
182  is_enabled=True,
183  is_playable=True,
184  name="B&O Radio",
185  type=SourceTypeEnum(value="netRadio"),
186  is_seekable=False,
187  ),
188  Source(
189  id="deezer",
190  is_enabled=True,
191  is_playable=True,
192  name="Deezer",
193  type=SourceTypeEnum(value="deezer"),
194  is_seekable=True,
195  ),
196  Source(
197  id="tidalConnect",
198  is_enabled=True,
199  is_playable=True,
200  name="Tidal Connect",
201  type=SourceTypeEnum(value="tidalConnect"),
202  is_seekable=True,
203  ),
204  ]
205 )
206 
207 
208 # Device events
209 BANG_OLUFSEN_WEBSOCKET_EVENT: Final[str] = f"{DOMAIN}_websocket_event"
210 
211 
212 CONNECTION_STATUS: Final[str] = "CONNECTION_STATUS"