From 37eef965adc72efbc786a1395dbd9ef21aaedf86 Mon Sep 17 00:00:00 2001 From: Manu <4445816+tr4nt0r@users.noreply.github.com> Date: Tue, 4 Nov 2025 11:27:48 +0100 Subject: [PATCH] Add friend count sensor to Xbox integration (#155761) --- homeassistant/components/xbox/icons.json | 3 + homeassistant/components/xbox/sensor.py | 6 + homeassistant/components/xbox/strings.json | 4 + .../xbox/snapshots/test_sensor.ambr | 147 ++++++++++++++++++ 4 files changed, 160 insertions(+) diff --git a/homeassistant/components/xbox/icons.json b/homeassistant/components/xbox/icons.json index ed9334c860d..48abb1c2073 100644 --- a/homeassistant/components/xbox/icons.json +++ b/homeassistant/components/xbox/icons.json @@ -23,6 +23,9 @@ "following": { "default": "mdi:account-arrow-right" }, + "friends": { + "default": "mdi:account-heart" + }, "gamer_score": { "default": "mdi:alpha-g-circle" }, diff --git a/homeassistant/components/xbox/sensor.py b/homeassistant/components/xbox/sensor.py index 9732339f607..8485c83cf0b 100644 --- a/homeassistant/components/xbox/sensor.py +++ b/homeassistant/components/xbox/sensor.py @@ -36,6 +36,7 @@ class XboxSensor(StrEnum): FOLLOWING = "following" FOLLOWER = "follower" NOW_PLAYING = "now_playing" + FRIENDS = "friends" @dataclass(kw_only=True, frozen=True) @@ -153,6 +154,11 @@ SENSOR_DESCRIPTIONS: tuple[XboxSensorEntityDescription, ...] = ( attributes_fn=now_playing_attributes, entity_picture_fn=title_logo, ), + XboxSensorEntityDescription( + key=XboxSensor.FRIENDS, + translation_key=XboxSensor.FRIENDS, + value_fn=lambda x, _: x.detail.friend_count if x.detail else None, + ), ) diff --git a/homeassistant/components/xbox/strings.json b/homeassistant/components/xbox/strings.json index adb0fb6fcc0..cef14d1589e 100644 --- a/homeassistant/components/xbox/strings.json +++ b/homeassistant/components/xbox/strings.json @@ -65,6 +65,10 @@ "name": "Following", "unit_of_measurement": "people" }, + "friends": { + "name": "Friends", + "unit_of_measurement": "[%key:component::xbox::entity::sensor::following::unit_of_measurement%]" + }, "gamer_score": { "name": "Gamerscore", "unit_of_measurement": "points" diff --git a/tests/components/xbox/snapshots/test_sensor.ambr b/tests/components/xbox/snapshots/test_sensor.ambr index afceba9b807..b6c27ea8a6f 100644 --- a/tests/components/xbox/snapshots/test_sensor.ambr +++ b/tests/components/xbox/snapshots/test_sensor.ambr @@ -97,6 +97,55 @@ 'state': '12', }) # --- +# name: test_sensors[sensor.erics273_friends-entry] + EntityRegistryEntrySnapshot({ + 'aliases': set({ + }), + 'area_id': None, + 'capabilities': None, + 'config_entry_id': , + 'config_subentry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'sensor', + 'entity_category': None, + 'entity_id': 'sensor.erics273_friends', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'options': dict({ + }), + 'original_device_class': None, + 'original_icon': None, + 'original_name': 'Friends', + 'platform': 'xbox', + 'previous_unique_id': None, + 'suggested_object_id': None, + 'supported_features': 0, + 'translation_key': , + 'unique_id': '2533274913657542_friends', + 'unit_of_measurement': 'people', + }) +# --- +# name: test_sensors[sensor.erics273_friends-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + 'friendly_name': 'erics273 Friends', + 'unit_of_measurement': 'people', + }), + 'context': , + 'entity_id': 'sensor.erics273_friends', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': '150', + }) +# --- # name: test_sensors[sensor.erics273_gamerscore-entry] EntityRegistryEntrySnapshot({ 'aliases': set({ @@ -398,6 +447,55 @@ 'state': '121', }) # --- +# name: test_sensors[sensor.gsr_ae_friends-entry] + EntityRegistryEntrySnapshot({ + 'aliases': set({ + }), + 'area_id': None, + 'capabilities': None, + 'config_entry_id': , + 'config_subentry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'sensor', + 'entity_category': None, + 'entity_id': 'sensor.gsr_ae_friends', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'options': dict({ + }), + 'original_device_class': None, + 'original_icon': None, + 'original_name': 'Friends', + 'platform': 'xbox', + 'previous_unique_id': None, + 'suggested_object_id': None, + 'supported_features': 0, + 'translation_key': , + 'unique_id': '271958441785640_friends', + 'unit_of_measurement': 'people', + }) +# --- +# name: test_sensors[sensor.gsr_ae_friends-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + 'friendly_name': 'GSR Ae Friends', + 'unit_of_measurement': 'people', + }), + 'context': , + 'entity_id': 'sensor.gsr_ae_friends', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': '150', + }) +# --- # name: test_sensors[sensor.gsr_ae_gamerscore-entry] EntityRegistryEntrySnapshot({ 'aliases': set({ @@ -700,6 +798,55 @@ 'state': '73', }) # --- +# name: test_sensors[sensor.ikken_hissatsuu_friends-entry] + EntityRegistryEntrySnapshot({ + 'aliases': set({ + }), + 'area_id': None, + 'capabilities': None, + 'config_entry_id': , + 'config_subentry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'sensor', + 'entity_category': None, + 'entity_id': 'sensor.ikken_hissatsuu_friends', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'options': dict({ + }), + 'original_device_class': None, + 'original_icon': None, + 'original_name': 'Friends', + 'platform': 'xbox', + 'previous_unique_id': None, + 'suggested_object_id': None, + 'supported_features': 0, + 'translation_key': , + 'unique_id': '2533274838782903_friends', + 'unit_of_measurement': 'people', + }) +# --- +# name: test_sensors[sensor.ikken_hissatsuu_friends-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + 'friendly_name': 'Ikken Hissatsuu Friends', + 'unit_of_measurement': 'people', + }), + 'context': , + 'entity_id': 'sensor.ikken_hissatsuu_friends', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': '150', + }) +# --- # name: test_sensors[sensor.ikken_hissatsuu_gamerscore-entry] EntityRegistryEntrySnapshot({ 'aliases': set({