Avoid Xbox friends polling when no friends are configured (#190495)

Co-authored-by: Steve Wall <24417289+stevebwall@users.noreply.github.com>
This commit is contained in:
Steve Wall
2026-11-05 15:19:25 +00:00
committed by GitHub
co-authored by Steve Wall
parent 10419de49e
commit 041a2b0c55
2 changed files with 36 additions and 8 deletions
+9 -8
View File
@@ -213,16 +213,17 @@ class XboxPresenceCoordinator(XboxBaseCoordinator[XboxData]):
"""Fetch presence data."""
me = await self.client.people.get_friend_by_xuid(self.client.xuid)
friends = await self.client.people.get_friends_own()
presence_data = {self.client.xuid: me.people[0]}
presence_data.update(
{
friend.xuid: friend
for friend in friends.people
if friend.xuid in self.friend_subentries()
}
)
if friend_xuids := self.friend_subentries():
friends = await self.client.people.get_friends_own()
presence_data.update(
{
friend.xuid: friend
for friend in friends.people
if friend.xuid in friend_xuids
}
)
# retrieve title details
for person in presence_data.values():
+27
View File
@@ -123,3 +123,30 @@ async def test_achievement_total_failure_keeps_entities_available(
assert state
assert state.state != "unavailable"
assert state.attributes["achievements"] == "2 / 0"
async def test_no_friend_polling_without_friend_subentries(
hass: HomeAssistant,
config_entry: MockConfigEntry,
xbox_live_client: AsyncMock,
freezer: FrozenDateTimeFactory,
) -> None:
"""Do not call the rate-limited friends endpoint without tracked friends."""
entry = MockConfigEntry(
domain=DOMAIN,
title=config_entry.title,
data=config_entry.data,
unique_id=config_entry.unique_id,
minor_version=3,
)
entry.add_to_hass(hass)
assert await hass.config_entries.async_setup(entry.entry_id)
await hass.async_block_till_done()
xbox_live_client.people.get_friends_own.assert_not_awaited()
xbox_live_client.people.get_friend_by_xuid.assert_awaited()
assert hass.states.get("sensor.gsr_ae_now_playing") is not None
freezer.tick(PRESENCE_INTERVAL)
async_fire_time_changed(hass)
await hass.async_block_till_done()
xbox_live_client.people.get_friends_own.assert_not_awaited()