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

View File

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