From 8dbc6b10855b1317a736c08ece0cb8c3f58ef69b Mon Sep 17 00:00:00 2001 From: Jonny Bergdahl Date: Wed, 22 Jun 2022 10:22:09 +0200 Subject: [PATCH] Fix thumbnail issues in Twitch integration (#72564) Co-authored-by: Franck Nijhof Co-authored-by: Franck Nijhof --- homeassistant/components/twitch/sensor.py | 9 ++++++--- tests/components/twitch/test_twitch.py | 1 + 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/twitch/sensor.py b/homeassistant/components/twitch/sensor.py index 95006a4cab7..dcc2dc9bbf6 100644 --- a/homeassistant/components/twitch/sensor.py +++ b/homeassistant/components/twitch/sensor.py @@ -108,10 +108,8 @@ class TwitchSensor(SensorEntity): def update(self) -> None: """Update device state.""" - followers = self._client.get_users_follows(to_id=self.unique_id)["total"] channel = self._client.get_users(user_ids=[self.unique_id])["data"][0] - self._attr_extra_state_attributes = { ATTR_FOLLOWING: followers, ATTR_VIEWS: channel["view_count"], @@ -151,8 +149,13 @@ class TwitchSensor(SensorEntity): self._attr_extra_state_attributes[ATTR_GAME] = stream["game_name"] self._attr_extra_state_attributes[ATTR_TITLE] = stream["title"] self._attr_entity_picture = stream["thumbnail_url"] + if self._attr_entity_picture is not None: + self._attr_entity_picture = self._attr_entity_picture.format( + height=24, + width=24, + ) else: self._attr_native_value = STATE_OFFLINE self._attr_extra_state_attributes[ATTR_GAME] = None self._attr_extra_state_attributes[ATTR_TITLE] = None - self._attr_entity_picture = channel["offline_image_url"] + self._attr_entity_picture = channel["profile_image_url"] diff --git a/tests/components/twitch/test_twitch.py b/tests/components/twitch/test_twitch.py index bfffeb4ae7f..0e086fe6f7a 100644 --- a/tests/components/twitch/test_twitch.py +++ b/tests/components/twitch/test_twitch.py @@ -28,6 +28,7 @@ USER_OBJECT = { "id": 123, "display_name": "channel123", "offline_image_url": "logo.png", + "profile_image_url": "logo.png", "view_count": 42, } STREAM_OBJECT_ONLINE = {