diff --git a/.gitignore b/.gitignore index 6d5db1a..1ec47bd 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ __pycache__/ /build/ /.mypy_cache/ /.env/ +venv \ No newline at end of file diff --git a/aioheos/aioheoscontroller.py b/aioheos/aioheoscontroller.py index 3a57a56..61a2f74 100755 --- a/aioheos/aioheoscontroller.py +++ b/aioheos/aioheoscontroller.py @@ -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' @@ -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 @@ -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 @@ -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) @@ -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' @@ -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 = [] @@ -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}) @@ -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 }) @@ -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"]) @@ -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"]) diff --git a/aioheos/aioheosgroup.py b/aioheos/aioheosgroup.py index 59b8599..881a923 100644 --- a/aioheos/aioheosgroup.py +++ b/aioheos/aioheosgroup.py @@ -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 " diff --git a/aioheos/aioheosplayer.py b/aioheos/aioheosplayer.py index bebf99b..8c4c48f 100644 --- a/aioheos/aioheosplayer.py +++ b/aioheos/aioheosplayer.py @@ -9,7 +9,7 @@ _LOGGER = logging.getLogger(__name__) -class AioHeosPlayer(): +class AioHeosPlayer: " Asynchronous Heos Player class " def __init__(self, controller, player_json): @@ -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 diff --git a/requirements.txt b/requirements.txt index ab3eb53..10cb037 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,3 @@ -lxml aiohttp +lxml +pytz \ No newline at end of file diff --git a/setup.py b/setup.py index 2043fb2..c71b6c6 100644 --- a/setup.py +++ b/setup.py @@ -13,8 +13,9 @@ packages=['aioheos'], long_description=open('README.md').read(), install_requires=[ - 'lxml', 'aiohttp', + 'lxml', + 'pytz' ], classifiers=[ "Programming Language :: Python :: 3", diff --git a/test.py b/test.py index 812d4af..379a1fe 100755 --- a/test.py +++ b/test.py @@ -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()