mirror of
https://github.com/home-assistant/core.git
synced 2026-12-02 19:57:03 -04:00
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:
@@ -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():
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user