Fix thumbnail issues in Twitch integration (#72564)

Co-authored-by: Franck Nijhof <frenck@frenck.nl>
Co-authored-by: Franck Nijhof <git@frenck.dev>
pull/73821/head
Jonny Bergdahl 2022-06-22 10:22:09 +02:00 committed by Franck Nijhof
parent 574ec5a507
commit 8dbc6b1085
No known key found for this signature in database
GPG Key ID: D62583BA8AB11CA3
2 changed files with 7 additions and 3 deletions

View File

@ -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"]

View File

@ -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 = {