Upgrade pylast to 1.8.0 (#5991)

This commit is contained in:
Fabian Affolter 2017-02-14 13:10:38 +01:00 committed by GitHub
parent a06f89085d
commit cd9f3fa215
2 changed files with 19 additions and 11 deletions

View file

@ -13,7 +13,11 @@ from homeassistant.helpers.entity import Entity
from homeassistant.const import CONF_API_KEY
import homeassistant.helpers.config_validation as cv
REQUIREMENTS = ['pylast==1.7.0']
REQUIREMENTS = ['pylast==1.8.0']
ATTR_LAST_PLAYED = 'last_played'
ATTR_PLAY_COUNT = 'play_count'
ATTR_TOP_PLAYED = 'top_played'
CONF_USERS = 'users'
@ -28,13 +32,14 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
# pylint: disable=unused-argument
def setup_platform(hass, config, add_devices, discovery_info=None):
"""Setup the Last.fm platform."""
"""Set up the Last.fm platform."""
import pylast as lastfm
network = lastfm.LastFMNetwork(api_key=config.get(CONF_API_KEY))
add_devices(
[LastfmSensor(username,
network) for username in config.get(CONF_USERS)])
[LastfmSensor(
username, network) for username in config.get(CONF_USERS)]
)
class LastfmSensor(Entity):
@ -73,13 +78,13 @@ class LastfmSensor(Entity):
self._cover = self._user.get_image()
self._playcount = self._user.get_playcount()
last = self._user.get_recent_tracks(limit=2)[0]
self._lastplayed = "{} - {}".format(last.track.artist,
last.track.title)
self._lastplayed = "{} - {}".format(
last.track.artist, last.track.title)
top = self._user.get_top_tracks(limit=1)[0]
toptitle = re.search("', '(.+?)',", str(top))
topartist = re.search("'(.+?)',", str(top))
self._topplayed = "{} - {}".format(topartist.group(1),
toptitle.group(1))
self._topplayed = "{} - {}".format(
topartist.group(1), toptitle.group(1))
if self._user.get_now_playing() is None:
self._state = "Not Scrobbling"
return
@ -89,8 +94,11 @@ class LastfmSensor(Entity):
@property
def device_state_attributes(self):
"""Return the state attributes."""
return {'Play Count': self._playcount, 'Last Played':
self._lastplayed, 'Top Played': self._topplayed}
return {
ATTR_LAST_PLAYED: self._lastplayed,
ATTR_PLAY_COUNT: self._playcount,
ATTR_TOP_PLAYED: self._topplayed,
}
@property
def entity_picture(self):

View file

@ -485,7 +485,7 @@ pyiss==1.0.1
pyitachip2ir==0.0.5
# homeassistant.components.sensor.lastfm
pylast==1.7.0
pylast==1.8.0
# homeassistant.components.litejet
pylitejet==0.1