Skip to content

Commit

Permalink
Update documentation
Browse files Browse the repository at this point in the history
Add polling to sound mode select entity
  • Loading branch information
mj23000 committed Jan 6, 2023
1 parent 047b26e commit 165a897
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 21 deletions.
19 changes: 18 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ SUPPORTS_PROXIMITY_SENSOR = (
- Using the play_media service:
- Activate a favourite
- Play from a URI
- Play a local file
- Play a radio station
- Play a Deezer flow
- Play an album from Deezer (with optional starting position)
- Play a playlist from Deezer (with optional starting position)
Expand Down Expand Up @@ -118,6 +120,10 @@ Some entities are added according to lists of supported devices. These are curre
- Battery Charging Time (If available)
- Battery Playing Time (If available)

### Select entity

- Sound mode (If available)

### Switch entity

- Loudness
Expand Down Expand Up @@ -231,7 +237,7 @@ action:
### play_media services
The Bang & Olufsen integration supports different playback types in the `media_player.play_media` service: playback from URL, activating a favourite, playback from a local file, activating a Deezer flow and Deezer playlists, albums and tracks.
The Bang & Olufsen integration supports different playback types in the `media_player.play_media` service: playback from URL, activating a favourite, playback from a local file, playing a radio station, activating a Deezer flow and Deezer playlists, albums and tracks.

#### play_media examples

Expand Down Expand Up @@ -268,6 +274,17 @@ data:
media_content_type: music
```

Playing a radio station:

```yaml
service: media_player.play_media
target:
entity_id: media_player.beosound_balance_12345678
data:
media_content_id: 1234567890123456
media_content_type: radio
```

Playing a Deezer flow. Optionally define a Deezer user ID:

```yaml
Expand Down
2 changes: 1 addition & 1 deletion custom_components/bangolufsen/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"issue_tracker": "https://github.com/bang-olufsen/bangolufsen-hacs/issues",
"requirements": ["mozart-api==2.3.4.15123.6"],
"zeroconf": ["_bangolufsen._tcp.local."],
"version": "0.6.0",
"version": "0.6.1",
"codeowners": ["@mj23000"],
"iot_class": "local_push",
"config_flow": true
Expand Down
39 changes: 20 additions & 19 deletions custom_components/bangolufsen/select.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
)

_LOGGER = logging.getLogger(__name__)
SCAN_INTERVAL = timedelta(seconds=120)

SCAN_INTERVAL = timedelta(minutes=2)


async def async_setup_entry(
Expand Down Expand Up @@ -83,26 +84,9 @@ def __init__(self, entry: ConfigEntry) -> None:
self._attr_name = f"{self._name} Sound mode"
self._attr_unique_id = f"{self._unique_id}-sound-mode"
self._attr_icon = "mdi:sine-wave"
self._attr_should_poll = True

self._sound_modes: dict[int, str] = {}
self._initial_setup()

def _initial_setup(self) -> None:
"""Get the available sound modes and setup Select functionality."""
sound_modes = self._client.get_listening_mode_set(async_req=True).get()
active_sound_mode = self._client.get_active_listening_mode(async_req=True).get()

# Add the key to make the labels unique as well
self._sound_modes = {x["id"]: f"{x['name']} - {x['id']}" for x in sound_modes}

# Set available options and selected option.
self._attr_options = list(self._sound_modes.values())

# Temp fix for any invalid active sound mode
try:
self._attr_current_option = self._sound_modes[active_sound_mode.id]
except KeyError:
self._attr_current_option = None

async def async_added_to_hass(self) -> None:
"""Turn on the dispatchers."""
Expand Down Expand Up @@ -131,3 +115,20 @@ async def _update_sound_mode(self, data: ListeningModeProps) -> None:
self._attr_current_option = self._sound_modes[active_sound_mode.id]

self.async_write_ha_state()

async def async_update(self) -> None:
"""Get the available sound modes and setup Select functionality."""
sound_modes = self._client.get_listening_mode_set(async_req=True).get()
active_sound_mode = self._client.get_active_listening_mode(async_req=True).get()

# Add the key to make the labels unique as well
self._sound_modes = {x["id"]: f"{x['name']} - {x['id']}" for x in sound_modes}

# Set available options and selected option.
self._attr_options = list(self._sound_modes.values())

# Temp fix for any invalid active sound mode
try:
self._attr_current_option = self._sound_modes[active_sound_mode.id]
except KeyError:
self._attr_current_option = None

0 comments on commit 165a897

Please sign in to comment.