Skip to content

Commit

Permalink
Fix various casts with assertions
Browse files Browse the repository at this point in the history
Fix comment placement
Fix group leader group_members rebase error
Replace entity_id method call with attribute
  • Loading branch information
mj23000 committed Sep 25, 2024
1 parent 140273d commit d517169
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions homeassistant/components/bang_olufsen/media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
device_registry as dr,
entity_registry as er,
)
from homeassistant.helpers.device_registry import DeviceEntry, DeviceInfo
from homeassistant.helpers.device_registry import DeviceInfo
from homeassistant.helpers.dispatcher import async_dispatcher_connect
from homeassistant.helpers.entity_platform import (
AddEntitiesCallback,
Expand Down Expand Up @@ -422,8 +422,10 @@ async def _async_update_name_and_beolink(self) -> None:

# Update device name
device_registry = dr.async_get(self.hass)
assert self.device_entry is not None

device_registry.async_update_device(
device_id=cast(DeviceEntry, self.device_entry).id,
device_id=self.device_entry.id,
name=beolink_self.friendly_name,
)

Expand All @@ -434,10 +436,10 @@ async def _async_update_beolink(self) -> None:

self._beolink_attributes = {}

# Add Beolink self
assert self.device_entry
assert self.device_entry.name
assert self.device_entry is not None
assert self.device_entry.name is not None

# Add Beolink self
self._beolink_attributes = {
"beolink": {"self": {self.device_entry.name: self._beolink_jid}}
}
Expand All @@ -452,24 +454,24 @@ async def _async_update_beolink(self) -> None:
peer.jid
)

self._remote_leader = self._playback_metadata.remote_leader

# Add Beolink listeners / leader
self._remote_leader = self._playback_metadata.remote_leader

# Create group members list
group_members = []

# If the device is a listener.
if self._remote_leader is not None:
# Add leader
# Add leader if available in Home Assistant
leader = self._get_entity_id_from_jid(self._remote_leader.jid)
group_members.append(
cast(str, self._get_entity_id_from_jid(self._remote_leader.jid))
leader
if leader is not None
else f"leader_not_in_hass-{self._remote_leader.friendly_name}"
)

# Add self
group_members.append(
cast(str, self._get_entity_id_from_jid(self._beolink_jid))
)
group_members.append(self.entity_id)

self._beolink_attributes["beolink"]["leader"] = {
self._remote_leader.friendly_name: self._remote_leader.jid,
Expand Down

0 comments on commit d517169

Please sign in to comment.