diff --git a/homeassistant/components/twitch/sensor.py b/homeassistant/components/twitch/sensor.py index bcd9e95a1ae..a6e2f4e04af 100644 --- a/homeassistant/components/twitch/sensor.py +++ b/homeassistant/components/twitch/sensor.py @@ -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: diff --git a/tests/components/twitch/fixtures/get_streams.json b/tests/components/twitch/fixtures/get_streams.json index 3714d97aaef..53330c9c82e 100644 --- a/tests/components/twitch/fixtures/get_streams.json +++ b/tests/components/twitch/fixtures/get_streams.json @@ -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" } ] diff --git a/tests/components/twitch/test_sensor.py b/tests/components/twitch/test_sensor.py index e5cddf8e192..8ce146adf07 100644 --- a/tests/components/twitch/test_sensor.py +++ b/tests/components/twitch/test_sensor.py @@ -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(