Skip to content

Commit

Permalink
Add stars and views attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
pinkywafer authored Jan 20, 2021
1 parent 989c77b commit ccc19f3
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions custom_components/youtube/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ def __init__(self, channel_id, name, session):
self._state = None
self.session = session
self._image = None
self.stars = 0
self.views = 0
self.stream = False
self.live = False
self._name = name
Expand Down Expand Up @@ -84,6 +86,8 @@ async def async_update(self):
'<media:thumbnail url="')[1].split('"')[0]
self._state = title
self._image = thumbnail_url
self.stars = info.split('<media:starRating count="')[1].split('"')[0]
self.views = info.split('<media:statistics views="')[1].split('"')[0]
url = CHANNEL_LIVE_URL.format(self.channel_id)
self.channel_live, self.channel_image = await is_channel_live(url, self.name, self.hass, self.session)
except Exception as error: # pylint: disable=broad-except
Expand Down Expand Up @@ -114,6 +118,8 @@ def device_state_attributes(self):
"""Attributes."""
return {'url': self.url,
'published': self.published,
'stars': self.stars,
'views': self.views,
'stream': self.stream,
'live': self.live,
'channel_is_live': self.channel_live,
Expand Down Expand Up @@ -151,3 +157,4 @@ async def is_channel_live(url, name, hass, session):
except Exception as error: # pylint: disable=broad-except
_LOGGER.debug('%s - Could not update - %s', name, error)
return live, channel_image

0 comments on commit ccc19f3

Please sign in to comment.