mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 04:37:06 +00:00
Expose Twitch "Started At" attribute (#121265)
This commit is contained in:
parent
f2c9188e46
commit
9d204613e8
@ -28,6 +28,7 @@ ATTR_FOLLOW = "following"
|
||||
ATTR_FOLLOW_SINCE = "following_since"
|
||||
ATTR_FOLLOWING = "followers"
|
||||
ATTR_VIEWS = "views"
|
||||
ATTR_STARTED_AT = "started_at"
|
||||
|
||||
STATE_OFFLINE = "offline"
|
||||
STATE_STREAMING = "streaming"
|
||||
@ -104,6 +105,7 @@ class TwitchSensor(SensorEntity):
|
||||
self._attr_native_value = STATE_STREAMING
|
||||
self._attr_extra_state_attributes[ATTR_GAME] = stream.game_name
|
||||
self._attr_extra_state_attributes[ATTR_TITLE] = stream.title
|
||||
self._attr_extra_state_attributes[ATTR_STARTED_AT] = stream.started_at
|
||||
self._attr_entity_picture = stream.thumbnail_url
|
||||
if self._attr_entity_picture is not None:
|
||||
self._attr_entity_picture = self._attr_entity_picture.format(
|
||||
@ -114,6 +116,7 @@ class TwitchSensor(SensorEntity):
|
||||
self._attr_native_value = STATE_OFFLINE
|
||||
self._attr_extra_state_attributes[ATTR_GAME] = None
|
||||
self._attr_extra_state_attributes[ATTR_TITLE] = None
|
||||
self._attr_extra_state_attributes[ATTR_STARTED_AT] = None
|
||||
self._attr_entity_picture = self._channel.profile_image_url
|
||||
|
||||
async def _async_add_user_attributes(self) -> None:
|
||||
|
@ -2,6 +2,7 @@
|
||||
{
|
||||
"game_name": "Good game",
|
||||
"title": "Title",
|
||||
"thumbnail_url": "stream-medium.png"
|
||||
"thumbnail_url": "stream-medium.png",
|
||||
"started_at": "2021-03-10T03:18:11Z"
|
||||
}
|
||||
]
|
||||
|
@ -3,6 +3,7 @@
|
||||
from datetime import datetime
|
||||
from unittest.mock import AsyncMock
|
||||
|
||||
from dateutil.tz import tzutc
|
||||
from twitchAPI.object.api import FollowedChannel, Stream, UserSubscription
|
||||
from twitchAPI.type import TwitchResourceNotFound
|
||||
|
||||
@ -41,6 +42,9 @@ async def test_streaming(
|
||||
assert sensor_state.attributes["entity_picture"] == "stream-medium.png"
|
||||
assert sensor_state.attributes["game"] == "Good game"
|
||||
assert sensor_state.attributes["title"] == "Title"
|
||||
assert sensor_state.attributes["started_at"] == datetime(
|
||||
year=2021, month=3, day=10, hour=3, minute=18, second=11, tzinfo=tzutc()
|
||||
)
|
||||
|
||||
|
||||
async def test_oauth_without_sub_and_follow(
|
||||
|
Loading…
x
Reference in New Issue
Block a user