mirror of
https://github.com/home-assistant/core.git
synced 2025-07-16 09:47:13 +00:00
Add subscription tier attribute to Twitch integration. (#128870)
* Add subscription tier to Twitch integration.
* Add test for Twitch tiers. Tests do not currently pass, so this is only theoretical.
* Fix variable type
* Show tier levels as 1,2,3 instead of the raw API values of 1000,2000,3000.
* Make Twitch subscription tier fixtures strings.
* Use proper assertion value for subscription tier test.
Edited on a bus on my phone. 😎
* Update homeassistant/components/twitch/coordinator.py
* Update tests/components/twitch/test_sensor.py
---------
Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
This commit is contained in:
parent
63582bb489
commit
d21b8166f0
@ -36,6 +36,7 @@ class TwitchUpdate:
|
|||||||
picture: str
|
picture: str
|
||||||
subscribed: bool | None
|
subscribed: bool | None
|
||||||
subscription_gifted: bool | None
|
subscription_gifted: bool | None
|
||||||
|
subscription_tier: int | None
|
||||||
follows: bool
|
follows: bool
|
||||||
following_since: datetime | None
|
following_since: datetime | None
|
||||||
viewers: int | None
|
viewers: int | None
|
||||||
@ -111,6 +112,7 @@ class TwitchCoordinator(DataUpdateCoordinator[dict[str, TwitchUpdate]]):
|
|||||||
channel.profile_image_url,
|
channel.profile_image_url,
|
||||||
sub is not None if sub else None,
|
sub is not None if sub else None,
|
||||||
sub.is_gift if sub else None,
|
sub.is_gift if sub else None,
|
||||||
|
{"1000": 1, "2000": 2, "3000": 3}.get(sub.tier) if sub else None,
|
||||||
follows is not None and follows.total > 0,
|
follows is not None and follows.total > 0,
|
||||||
follows.data[0].followed_at if follows and follows.total else None,
|
follows.data[0].followed_at if follows and follows.total else None,
|
||||||
stream.viewer_count if stream else None,
|
stream.viewer_count if stream else None,
|
||||||
|
@ -18,8 +18,8 @@ from .coordinator import TwitchUpdate
|
|||||||
ATTR_GAME = "game"
|
ATTR_GAME = "game"
|
||||||
ATTR_TITLE = "title"
|
ATTR_TITLE = "title"
|
||||||
ATTR_SUBSCRIPTION = "subscribed"
|
ATTR_SUBSCRIPTION = "subscribed"
|
||||||
ATTR_SUBSCRIPTION_SINCE = "subscribed_since"
|
|
||||||
ATTR_SUBSCRIPTION_GIFTED = "subscription_is_gifted"
|
ATTR_SUBSCRIPTION_GIFTED = "subscription_is_gifted"
|
||||||
|
ATTR_SUBSCRIPTION_TIER = "subscription_tier"
|
||||||
ATTR_FOLLOW = "following"
|
ATTR_FOLLOW = "following"
|
||||||
ATTR_FOLLOW_SINCE = "following_since"
|
ATTR_FOLLOW_SINCE = "following_since"
|
||||||
ATTR_FOLLOWING = "followers"
|
ATTR_FOLLOWING = "followers"
|
||||||
@ -89,6 +89,7 @@ class TwitchSensor(CoordinatorEntity[TwitchCoordinator], SensorEntity):
|
|||||||
if channel.subscribed is not None:
|
if channel.subscribed is not None:
|
||||||
resp[ATTR_SUBSCRIPTION] = channel.subscribed
|
resp[ATTR_SUBSCRIPTION] = channel.subscribed
|
||||||
resp[ATTR_SUBSCRIPTION_GIFTED] = channel.subscription_gifted
|
resp[ATTR_SUBSCRIPTION_GIFTED] = channel.subscription_gifted
|
||||||
|
resp[ATTR_SUBSCRIPTION_TIER] = channel.subscription_tier
|
||||||
resp[ATTR_FOLLOW] = channel.follows
|
resp[ATTR_FOLLOW] = channel.follows
|
||||||
if channel.follows:
|
if channel.follows:
|
||||||
resp[ATTR_FOLLOW_SINCE] = channel.following_since
|
resp[ATTR_FOLLOW_SINCE] = channel.following_since
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
{
|
{
|
||||||
"is_gift": true
|
"is_gift": true,
|
||||||
|
"tier": "2000"
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
{
|
{
|
||||||
"is_gift": false
|
"is_gift": false,
|
||||||
|
"tier": "1000"
|
||||||
}
|
}
|
||||||
|
@ -80,6 +80,7 @@ async def test_oauth_with_sub(
|
|||||||
sensor_state = hass.states.get(ENTITY_ID)
|
sensor_state = hass.states.get(ENTITY_ID)
|
||||||
assert sensor_state.attributes["subscribed"] is True
|
assert sensor_state.attributes["subscribed"] is True
|
||||||
assert sensor_state.attributes["subscription_is_gifted"] is False
|
assert sensor_state.attributes["subscription_is_gifted"] is False
|
||||||
|
assert sensor_state.attributes["subscription_tier"] == 1
|
||||||
assert sensor_state.attributes["following"] is False
|
assert sensor_state.attributes["following"] is False
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user