Skip to content

Commit

Permalink
Enable Beoremote One to be paired to several devices
Browse files Browse the repository at this point in the history
Small tweaks
  • Loading branch information
mj23000 committed Feb 12, 2025
1 parent 9781e53 commit 0019d7b
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 12 deletions.
6 changes: 4 additions & 2 deletions custom_components/bang_olufsen/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,10 @@ async def _handle_remote_devices(
device_registry = dr.async_get(hass)
device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id,
identifiers={(DOMAIN, remote.serial_number)},
name=f"{BangOlufsenModel.BEOREMOTE_ONE}-{remote.serial_number}",
identifiers={
(DOMAIN, f"{remote.serial_number}_{config_entry.unique_id}")
},
name=f"{BangOlufsenModel.BEOREMOTE_ONE}-{remote.serial_number}-{config_entry.unique_id}",
model=BangOlufsenModel.BEOREMOTE_ONE,
serial_number=remote.serial_number,
sw_version=remote.app_version,
Expand Down
2 changes: 1 addition & 1 deletion custom_components/bang_olufsen/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from mozart_api.mozart_client import MozartClient
import voluptuous as vol

from homeassistant.components.zeroconf import ZeroconfServiceInfo
from homeassistant.config_entries import (
ConfigEntry,
ConfigFlow,
Expand All @@ -31,6 +30,7 @@
SelectSelector,
SelectSelectorConfig,
)
from homeassistant.helpers.service_info.zeroconf import ZeroconfServiceInfo
from homeassistant.util.ssl import get_default_context
from homeassistant.util.uuid import random_uuid_hex

Expand Down
2 changes: 1 addition & 1 deletion custom_components/bang_olufsen/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class BangOlufsenSource:
"stopped": MediaPlayerState.PAUSED,
"ended": MediaPlayerState.PAUSED,
"error": MediaPlayerState.IDLE,
# A devices initial state is "unknown" and should be treated as "idle"
# A device's initial state is "unknown" and should be treated as "idle"
"unknown": MediaPlayerState.IDLE,
}

Expand Down
2 changes: 1 addition & 1 deletion custom_components/bang_olufsen/diagnostics.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from homeassistant.components.media_player import DOMAIN as MEDIA_PLAYER_DOMAIN
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
import homeassistant.helpers.entity_registry as er
from homeassistant.helpers import entity_registry as er

from .const import DOMAIN

Expand Down
6 changes: 4 additions & 2 deletions custom_components/bang_olufsen/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,11 @@ def __init__(

assert remote.serial_number

self._attr_unique_id = f"{remote.serial_number}_{key_type}"
self._attr_unique_id = (
f"{remote.serial_number}_{config_entry.unique_id}_{key_type}"
)
self._attr_device_info = DeviceInfo(
identifiers={(DOMAIN, remote.serial_number)}
identifiers={(DOMAIN, f"{remote.serial_number}_{config_entry.unique_id}")}
)
# Make the native key name Home Assistant compatible
self._attr_translation_key = key_type.lower().replace("/", "_")
Expand Down
2 changes: 1 addition & 1 deletion custom_components/bang_olufsen/halo.py
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ async def send(self, data: BaseConfiguration | BaseUpdate) -> bool:

try:
self._websocket_queue.put_nowait(data.to_json())
except (asyncio.QueueFull, asyncio.QueueShutDown): # type: ignore[attr-defined]
except (asyncio.QueueFull, asyncio.QueueShutDown):
return False
else:
return True
Expand Down
2 changes: 1 addition & 1 deletion custom_components/bang_olufsen/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
"iot_class": "local_push",
"issue_tracker": "https://github.com/bang-olufsen/bang_olufsen-hacs/issues",
"requirements": ["mozart-api==4.1.1.116.6"],
"version": "3.4.4",
"version": "3.5.0",
"zeroconf": ["_bangolufsen._tcp.local.", "_zenith._tcp.local."]
}
6 changes: 4 additions & 2 deletions custom_components/bang_olufsen/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,11 @@ def __init__(self, config_entry: MozartConfigEntry, remote: PairedRemote) -> Non
assert remote.serial_number

self._attr_device_class = SensorDeviceClass.BATTERY
self._attr_unique_id = f"{remote.serial_number}_remote_battery_level"
self._attr_unique_id = (
f"{remote.serial_number}_{config_entry.unique_id}_remote_battery_level"
)
self._attr_device_info = DeviceInfo(
identifiers={(DOMAIN, remote.serial_number)}
identifiers={(DOMAIN, f"{remote.serial_number}_{config_entry.unique_id}")}
)
self._attr_native_value = remote.battery_level

Expand Down
2 changes: 1 addition & 1 deletion hacs.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "Bang & Olufsen",
"homeassistant": "2024.12.0",
"homeassistant": "2025.2.0",
"render_readme": true
}

0 comments on commit 0019d7b

Please sign in to comment.