Skip to content

Commit

Permalink
added like in name
Browse files Browse the repository at this point in the history
  • Loading branch information
KoljaWindeler committed Apr 10, 2021
1 parent 46dd2ca commit fd1ecb5
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
1 change: 1 addition & 0 deletions custom_components/ytube_music_player/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@
SERVICE_CALL_OFF_IS_IDLE_1X = "off_is_idle_1x"
SERVICE_CALL_PAUSED_IS_IDLE = "paused_is_idle"
SERIVCE_CALL_DEBUG_AS_ERROR = "debug_as_error"
SERVICE_CALL_LIKE_IN_NAME = "like_in_name"


CONF_RECEIVERS = 'speakers' # list of speakers (media_players)
Expand Down
2 changes: 1 addition & 1 deletion custom_components/ytube_music_player/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@
"codeowners": [
"@KoljaWindeler"
],
"version": "0.20210410.01"
"version": "0.20210410.02"
}
20 changes: 17 additions & 3 deletions custom_components/ytube_music_player/media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ class yTubeMusicComponent(MediaPlayerEntity):
def __init__(self, hass, config, name_add):
self.hass = hass
self._debug_as_error = False
self._name = config.get(CONF_NAME,DOMAIN+name_add)
self._org_name = config.get(CONF_NAME,DOMAIN+name_add)
self._name = self._org_name
# confgurations can be either the full entity_id or just the name
self._select_playlist = input_select.DOMAIN+"."+config.get(CONF_SELECT_PLAYLIST, DEFAULT_SELECT_PLAYLIST).replace(input_select.DOMAIN+".","")
self._select_playMode = input_select.DOMAIN+"."+config.get(CONF_SELECT_PLAYMODE, DEFAULT_SELECT_PLAYMODE).replace(input_select.DOMAIN+".","")
Expand Down Expand Up @@ -87,6 +88,7 @@ def __init__(self, hass, config, name_add):
self._api = None
self._js = ""
self._update_needed = False
self._like_in_name = False

self._remote_player = ""
self._untrack_remote_player = None
Expand Down Expand Up @@ -445,6 +447,8 @@ async def async_turn_off_media_player(self, data=None):
self._attributes['_media_type'] = ""
self._attributes['_media_id'] = ""
self._attributes['current_track'] = 0
if(self._like_in_name):
self._name = self._org_name

self.async_schedule_update_ha_state()
if(self._remote_player == ""):
Expand Down Expand Up @@ -570,7 +574,7 @@ async def async_sync_player(self, entity_id=None, old_state=None, new_state=None
else:
self._state = STATE_OFF
self.log_me('debug',"media player got turned off")
self.turn_off()
self.async_turn_off()
elif(old_state.state == STATE_PLAYING and new_state.state == STATE_PAUSED and # workaround for SONOS (changes to PAUSED at the end of a track)
(datetime.datetime.now()-self._last_auto_advance).total_seconds() > 10 and self._x_to_idle == STATE_PAUSED):
self._allow_next = False
Expand Down Expand Up @@ -922,9 +926,13 @@ async def async_get_track(self, entity_id=None, old_state=None, new_state=None,
self._attributes['current_track'] = self._next_track_no
self._attributes['videoId'] = _track['videoId']
if('likeStatus' in _track):
self._attributes['likeStatus'] = _track['likeStatus']
self._attributes['likeStatus'] = _track['likeStatus']
if(self._like_in_name):
self._name = self._org_name + " - " + _track['likeStatus']
else:
self._attributes['likeStatus'] = ""
if(self._like_in_name):
self._name = self._org_name


""" Find the unique track id. """
Expand Down Expand Up @@ -1334,6 +1342,8 @@ async def async_call_method(self, command=None, parameters=None):
arg = 'LIKE'
await self.hass.async_add_executor_job(self._api.rate_song,self._attributes['videoId'],arg)
self._attributes['likeStatus'] = arg
if(self._like_in_name):
self._name = self._org_name + " - " + arg
self.async_schedule_update_ha_state()
self._tracks[self._next_track_no]['likeStatus'] = arg
except:
Expand Down Expand Up @@ -1389,6 +1399,10 @@ async def async_call_method(self, command=None, parameters=None):
elif(command == SERIVCE_CALL_DEBUG_AS_ERROR):
self._debug_as_error = True
self.log_me('debug',"Posting debug messages as error until restart")
elif(command == SERVICE_CALL_LIKE_IN_NAME):
self._like_in_name = True
self._name = self._org_name + " - " + self._attributes['likeStatus']
self.log_me('debug',"Showing like status in name until restart")



Expand Down

0 comments on commit fd1ecb5

Please sign in to comment.