Skip to content

Commit df60de3

Browse files
authored
Add In party sensor to Xbox integration (home-assistant#155967)
1 parent cb086bb commit df60de3

File tree

5 files changed

+395
-2
lines changed

5 files changed

+395
-2
lines changed

homeassistant/components/xbox/icons.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,19 @@
2929
"gamer_score": {
3030
"default": "mdi:alpha-g-circle"
3131
},
32+
"in_party": {
33+
"default": "mdi:headset",
34+
"state": {
35+
"0": "mdi:headset-off"
36+
}
37+
},
38+
"join_restrictions": {
39+
"default": "mdi:account-voice-off",
40+
"state": {
41+
"invite_only": "mdi:email-newsletter",
42+
"joinable": "mdi:account-multiple-plus-outline"
43+
}
44+
},
3245
"last_online": {
3346
"default": "mdi:account-clock"
3447
},

homeassistant/components/xbox/sensor.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@
2424
from .coordinator import XboxConfigEntry
2525
from .entity import XboxBaseEntity, XboxBaseEntityDescription, check_deprecated_entity
2626

27+
MAP_JOIN_RESTRICTIONS = {
28+
"local": "invite_only",
29+
"followed": "joinable",
30+
}
31+
2732

2833
class XboxSensor(StrEnum):
2934
"""Xbox sensor."""
@@ -37,6 +42,8 @@ class XboxSensor(StrEnum):
3742
FOLLOWER = "follower"
3843
NOW_PLAYING = "now_playing"
3944
FRIENDS = "friends"
45+
IN_PARTY = "in_party"
46+
JOIN_RESTRICTIONS = "join_restrictions"
4047

4148

4249
@dataclass(kw_only=True, frozen=True)
@@ -95,6 +102,18 @@ def now_playing_attributes(_: Person, title: Title | None) -> dict[str, Any]:
95102
return attributes
96103

97104

105+
def join_restrictions(person: Person, _: Title | None = None) -> str | None:
106+
"""Join restrictions for current party the user is in."""
107+
108+
return (
109+
MAP_JOIN_RESTRICTIONS.get(
110+
person.multiplayer_summary.party_details[0].join_restriction
111+
)
112+
if person.multiplayer_summary and person.multiplayer_summary.party_details
113+
else None
114+
)
115+
116+
98117
def title_logo(_: Person, title: Title | None) -> str | None:
99118
"""Get the game logo."""
100119

@@ -159,6 +178,22 @@ def title_logo(_: Person, title: Title | None) -> str | None:
159178
translation_key=XboxSensor.FRIENDS,
160179
value_fn=lambda x, _: x.detail.friend_count if x.detail else None,
161180
),
181+
XboxSensorEntityDescription(
182+
key=XboxSensor.IN_PARTY,
183+
translation_key=XboxSensor.IN_PARTY,
184+
value_fn=(
185+
lambda x, _: x.multiplayer_summary.in_party
186+
if x.multiplayer_summary
187+
else None
188+
),
189+
),
190+
XboxSensorEntityDescription(
191+
key=XboxSensor.JOIN_RESTRICTIONS,
192+
translation_key=XboxSensor.JOIN_RESTRICTIONS,
193+
value_fn=join_restrictions,
194+
device_class=SensorDeviceClass.ENUM,
195+
options=list(MAP_JOIN_RESTRICTIONS.values()),
196+
),
162197
)
163198

164199

homeassistant/components/xbox/strings.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,17 @@
7373
"name": "Gamerscore",
7474
"unit_of_measurement": "points"
7575
},
76+
"in_party": {
77+
"name": "In party",
78+
"unit_of_measurement": "[%key:component::xbox::entity::sensor::following::unit_of_measurement%]"
79+
},
80+
"join_restrictions": {
81+
"name": "Party join restrictions",
82+
"state": {
83+
"invite_only": "Invite-only",
84+
"joinable": "Joinable"
85+
}
86+
},
7687
"last_online": {
7788
"name": "Last online"
7889
},

tests/components/xbox/fixtures/people_batch.json

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,21 @@
3333
"search": null,
3434
"titleHistory": null,
3535
"multiplayerSummary": {
36-
"inMultiplayerSession": 0,
37-
"inParty": 0
36+
"joinableActivities": [],
37+
"partyDetails": [
38+
{
39+
"sessionRef": {
40+
"scid": "7ffcfe63-a320-4086-85bb-a1734bef7a30",
41+
"templateName": "chat",
42+
"name": "d3804c40-ac93-4c7d-9414-6cb419931105"
43+
},
44+
"status": "active",
45+
"visibility": "open",
46+
"joinRestriction": "followed",
47+
"accepted": 2
48+
}
49+
],
50+
"inParty": 2
3851
},
3952
"recentPlayer": null,
4053
"follower": null,

0 commit comments

Comments
 (0)