Skip to content

Commit

Permalink
Remove generated ID from listening positions
Browse files Browse the repository at this point in the history
Tweak
  • Loading branch information
mj23000 committed May 24, 2023
1 parent e6591cf commit 1e4179a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
2 changes: 1 addition & 1 deletion custom_components/bangolufsen/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ def on_volume_notification(self, notification: VolumeState) -> None:
notification,
)

def on_software_update_state(self, _: SoftwareUpdateState) -> None:
def on_software_update_state(self, notification: SoftwareUpdateState) -> None:
"""Check device sw version."""

# Get software version.
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 @@ -7,6 +7,6 @@
"iot_class": "local_push",
"issue_tracker": "https://github.com/bang-olufsen/bangolufsen-hacs/issues",
"requirements": ["mozart-api==2.5.3.123.1"],
"version": "1.0.5",
"version": "1.0.6",
"zeroconf": ["_bangolufsen._tcp.local."]
}
21 changes: 14 additions & 7 deletions custom_components/bangolufsen/select.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"""Select entities for the Bang & Olufsen Mozart integration."""
from __future__ import annotations

import logging

from mozart_api.models import ListeningModeProps, SpeakerGroupOverview

from homeassistant.components.select import SelectEntity
Expand All @@ -12,6 +14,8 @@

from .const import DOMAIN, BangOlufsenEntity, EntityEnum, WebSocketNotification

_LOGGER = logging.getLogger(__name__)


async def async_setup_entry(
hass: HomeAssistant,
Expand Down Expand Up @@ -151,23 +155,26 @@ async def _update_listening_positions(
).get()

self._listening_positions = {}
index = 0

# Listening positions
for scene_key in scenes:
scene = scenes[scene_key]

if scene.tags is not None and "listeningposition" in scene.tags:
# Ensure that the label is unique
label = f"{scene.label} - {index}"
# Ignore listening positions with the same name
if scene.label in self._listening_positions:
_LOGGER.warning(
"Ignoring listening position with duplicate name: %s and ID: %s",
scene.label,
scene_key,
)
continue

self._listening_positions[label] = scene_key
self._listening_positions[scene.label] = scene_key

# Currently guess the current active listening position by the speakergroup ID
if active_speaker_group.id == scene.action_list[0].speaker_group_id:
self._attr_current_option = label

index += 1
self._attr_current_option = scene.label

self._attr_options = list(self._listening_positions.keys())

Expand Down

0 comments on commit 1e4179a

Please sign in to comment.