mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 20:27:08 +00:00
Add Twitch stream viewer as readable data for integration (#128787)
This commit is contained in:
parent
0c6a640e50
commit
711c448242
@ -38,6 +38,7 @@ class TwitchUpdate:
|
||||
subscription_gifted: bool | None
|
||||
follows: bool
|
||||
following_since: datetime | None
|
||||
viewers: int | None
|
||||
|
||||
|
||||
class TwitchCoordinator(DataUpdateCoordinator[dict[str, TwitchUpdate]]):
|
||||
@ -112,5 +113,6 @@ class TwitchCoordinator(DataUpdateCoordinator[dict[str, TwitchUpdate]]):
|
||||
sub.is_gift if sub else None,
|
||||
follows is not None and follows.total > 0,
|
||||
follows.data[0].followed_at if follows and follows.total else None,
|
||||
stream.viewer_count if stream else None,
|
||||
)
|
||||
return data
|
||||
|
@ -24,6 +24,7 @@ ATTR_FOLLOW = "following"
|
||||
ATTR_FOLLOW_SINCE = "following_since"
|
||||
ATTR_FOLLOWING = "followers"
|
||||
ATTR_VIEWS = "views"
|
||||
ATTR_VIEWERS = "viewers"
|
||||
ATTR_STARTED_AT = "started_at"
|
||||
|
||||
STATE_OFFLINE = "offline"
|
||||
@ -82,6 +83,7 @@ class TwitchSensor(CoordinatorEntity[TwitchCoordinator], SensorEntity):
|
||||
ATTR_GAME: channel.game,
|
||||
ATTR_TITLE: channel.title,
|
||||
ATTR_STARTED_AT: channel.started_at,
|
||||
ATTR_VIEWERS: channel.viewers,
|
||||
}
|
||||
resp[ATTR_SUBSCRIPTION] = False
|
||||
if channel.subscribed is not None:
|
||||
|
@ -3,6 +3,7 @@
|
||||
"game_name": "Good game",
|
||||
"title": "Title",
|
||||
"thumbnail_url": "stream-medium.png",
|
||||
"started_at": "2021-03-10T03:18:11Z"
|
||||
"started_at": "2021-03-10T03:18:11Z",
|
||||
"viewer_count": 42
|
||||
}
|
||||
]
|
||||
|
@ -45,6 +45,7 @@ async def test_streaming(
|
||||
assert sensor_state.attributes["started_at"] == datetime(
|
||||
year=2021, month=3, day=10, hour=3, minute=18, second=11, tzinfo=tzutc()
|
||||
)
|
||||
assert sensor_state.attributes["viewers"] == 42
|
||||
|
||||
|
||||
async def test_oauth_without_sub_and_follow(
|
||||
|
Loading…
x
Reference in New Issue
Block a user