Improve type hints in lastfm sensor (#77657)

This commit is contained in:
epenet 2022-09-04 22:45:41 +02:00 committed by GitHub
parent be07bb7976
commit 23a579d1c9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -91,7 +91,7 @@ class LastfmSensor(SensorEntity):
"""Return the state of the sensor."""
return self._state
def update(self):
def update(self) -> None:
"""Update device state."""
self._cover = self._user.get_image()
self._playcount = self._user.get_playcount()
@ -101,10 +101,11 @@ class LastfmSensor(SensorEntity):
self._lastplayed = f"{last.track.artist} - {last.track.title}"
if top_tracks := self._user.get_top_tracks(limit=1):
top = top_tracks[0]
toptitle = re.search("', '(.+?)',", str(top))
topartist = re.search("'(.+?)',", str(top))
self._topplayed = f"{topartist.group(1)} - {toptitle.group(1)}"
top = str(top_tracks[0])
if (toptitle := re.search("', '(.+?)',", top)) and (
topartist := re.search("'(.+?)',", top)
):
self._topplayed = f"{topartist.group(1)} - {toptitle.group(1)}"
if (now_playing := self._user.get_now_playing()) is None:
self._state = STATE_NOT_SCROBBLING