Skip to content

Commit

Permalink
Fix now playing update issue and removed player_id from controller
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewsayre committed Mar 14, 2019
1 parent 33e0b74 commit a3a357b
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 25 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ __pycache__/
/build/
/.mypy_cache/
/.env/
venv
26 changes: 9 additions & 17 deletions aioheos/aioheoscontroller.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
GET_GROUPS = 'group/get_groups'
SET_GROUP = 'group/set_group'

BROWSE = 'browser/browse'
BROWSE = 'browse/browse'

EVENT_PLAYER_VOLUME_CHANGED = 'event/player_volume_changed'
EVENT_PLAYER_STATE_CHANGED = 'event/player_state_changed'
Expand Down Expand Up @@ -88,7 +88,7 @@ def __init__(self, message):
self.message = message


class AioHeosController():
class AioHeosController:
"""Asynchronous Heos class."""

# ddpylint: disable=too-many-public-methods,too-many-instance-attributes
Expand All @@ -107,7 +107,6 @@ def __init__(self,
self._players = None
self._groups = None

self._player_id = None
self._upnp = None
self._reader = None
self._writer = None
Expand All @@ -122,7 +121,7 @@ async def ensure_player(self):
# timeout after 10 sec
self.request_players()
for _ in range(0, 20):
if self.player_id:
if self._players:
return
await asyncio.sleep(0.5)

Expand Down Expand Up @@ -219,8 +218,6 @@ def send_command(self, command, message=None):
"""Send command."""
msg = 'heos://' + command
if message:
if not message.get('pid'):
message['pid'] = self.player_id
msg += '?' + '&'.join("{}={}".format(key, val)
for (key, val) in message.items())
msg += '\r\n'
Expand Down Expand Up @@ -420,7 +417,6 @@ def login(self):

def _parse_players(self, payload, _message):
_players_json = payload
self._player_id = _players_json[0]['pid']
if not self._players:
self._players = []

Expand Down Expand Up @@ -484,11 +480,6 @@ def get_group(self, pid):
return group
return None

@property
def player_id(self):
" get player id "
return self._player_id

def request_player_info(self, pid):
" request player info "
self.send_command(GET_PLAYER_INFO, {'pid': pid})
Expand Down Expand Up @@ -525,13 +516,13 @@ def _parse_volume(self, _payload, message):
if self.get_group(message['pid']):
self.get_group(message['pid']).volume = float(message['level'])

def _set_play_state(self, state, pid=None):
def _set_play_state(self, state, pid):
" set play state "
if state not in ('play', 'pause', 'stop'):
AioHeosException('Not an accepted play state {}.'.format(state))

self.send_command(SET_PLAY_STATE, {
'pid': pid if pid else self.player_id,
'pid': pid,
'state': state
})

Expand All @@ -547,10 +538,10 @@ def pause(self, pid=None):
" pause "
self._set_play_state('pause', pid)

def request_now_playing_media(self, pid=None):
def request_now_playing_media(self, pid):
" get playing media "
self.send_command(GET_NOW_PLAYING_MEDIA,
{'pid': pid if pid else self.player_id})
{'pid': pid})

def _parse_now_playing_media(self, payload, message):
player = self.get_player(message["pid"])
Expand Down Expand Up @@ -679,7 +670,8 @@ def _parse_players_changed(self, _payload, _message):

def _parse_player_now_playing_changed(self, _payload, _message):
" event / now playing changed, request what changed. "
self.request_now_playing_media()
player_id = _message['pid']
self.request_now_playing_media(player_id)

def _parse_player_now_playing_progress(self, _payload, message):
player = self.get_player(message["pid"])
Expand Down
4 changes: 2 additions & 2 deletions aioheos/aioheosgroup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ class AioHeosGroup(aioheosplayer.AioHeosPlayer):
def __init__(self, controller, group_json):
group_json["pid"] = group_json["gid"]
super().__init__(controller, group_json)
_LOGGER.debug("[D] Creating group object %s for controller pid %s",
self._player_id, self._controller._player_id)
_LOGGER.debug("[D] Creating group object %s",
self._player_id)

def recreate_group(self):
" Recreate group "
Expand Down
6 changes: 3 additions & 3 deletions aioheos/aioheosplayer.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
_LOGGER = logging.getLogger(__name__)


class AioHeosPlayer():
class AioHeosPlayer:
" Asynchronous Heos Player class "

def __init__(self, controller, player_json):
Expand All @@ -32,8 +32,8 @@ def __init__(self, controller, player_json):
self._media_image_url = None
self._media_id = None
self._callback = None
_LOGGER.debug("[D] Creating player object %s for controller pid %s",
self._player_id, self._controller._player_id)
_LOGGER.debug("[D] Creating player object %s",
self._player_id)

def __lt__(self, other):
return self._player_id < other.player_id
Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
lxml
aiohttp
lxml
pytz
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@
packages=['aioheos'],
long_description=open('README.md').read(),
install_requires=[
'lxml',
'aiohttp',
'lxml',
'pytz'
],
classifiers=[
"Programming Language :: Python :: 3",
Expand Down
2 changes: 1 addition & 1 deletion test.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ async def heos_test(loop):
# host = None
host = 'HEOS-1'

heos = aioheos.AioHeosController(loop, host=host, verbose=verbose)
heos = aioheos.AioHeosController(loop, host=host)

# connect to player
await heos.connect()
Expand Down

0 comments on commit a3a357b

Please sign in to comment.