Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfixes and Unit Tests #69

Merged
merged 22 commits into from
Apr 8, 2023
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
28d2d88
Resolve error relating to #65
NeonDaniel Apr 5, 2023
3c44115
Update logging and docstrings
NeonDaniel Apr 6, 2023
9bd64d3
More unit tests and documentation/code cleanup of player playback met…
NeonDaniel Apr 6, 2023
b572e22
Add tests and documentation for pause, resume, seek, and reset methods
NeonDaniel Apr 6, 2023
351b807
Update to handle empty URI per PR feedback
NeonDaniel Apr 6, 2023
3ed9786
Resolving unit test failures
NeonDaniel Apr 6, 2023
55fdc1b
Resolving unit test failures
NeonDaniel Apr 6, 2023
cc153cd
Refactor Message arg per review
NeonDaniel Apr 6, 2023
b62aa78
Add tests for `handle_player_state_update` with handling of int state…
NeonDaniel Apr 7, 2023
3435030
Add tests for `play_next` with updated comments and logging
NeonDaniel Apr 7, 2023
38f5b3f
Cleanup and fix bugs in `handle_player_media_update` with unit test
NeonDaniel Apr 7, 2023
a0a4acc
Revert equality check per PR review
NeonDaniel Apr 7, 2023
fda0473
Add MediaEntry and Playlist tests and docstrings
NeonDaniel Apr 7, 2023
10863ba
Add MediaEntry and Playlist tests
NeonDaniel Apr 7, 2023
4191974
Complete `media` tests and docstrings
NeonDaniel Apr 7, 2023
ed55658
Ensure MediaEntry.playback is PlaybackType with unit tests
NeonDaniel Apr 7, 2023
b3e738c
Fix MessageBusClient import location
NeonDaniel Apr 7, 2023
a611375
Add logging to troubleshoot playback errors
NeonDaniel Apr 7, 2023
aef12d2
Update logging to troubleshoot
NeonDaniel Apr 7, 2023
434a28a
Refactor `NowPlaying` reset and update unit tests
NeonDaniel Apr 8, 2023
f2d1981
Update test to handle refactored reset calls
NeonDaniel Apr 8, 2023
17a1043
Update 'play_next' based on PR conversation
NeonDaniel Apr 8, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 36 additions & 12 deletions ovos_plugin_common_play/ocp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,8 @@ class OCP(OVOSAbstractApplication):
def __init__(self, bus=None, lang=None, settings=None):
# settings = settings or OCPSettings()
res_dir = join(dirname(__file__), "res")
gui = OCPMediaPlayerGUI()
super().__init__(skill_id=OCP_ID, resources_dir=res_dir,
bus=bus, lang=lang, gui=gui)
bus=bus, lang=lang, gui=OCPMediaPlayerGUI())
if settings:
LOG.debug(f"Updating settings from value passed at init")
self.settings.merge(settings)
Expand All @@ -71,20 +70,33 @@ def __init__(self, bus=None, lang=None, settings=None):
self.remove_event("mycroft.ready")
self.replace_mycroft_cps(skills_ready)
try:
# TODO: Should this just happen at install time? A user might not
# want this shortcut.
NeonDaniel marked this conversation as resolved.
Show resolved Hide resolved
create_desktop_file()
except: # permission errors and stuff
pass

def handle_ping(self, message):
"""
Handle ovos.common_play.ping Messages and emit a response
@param message: message associated with request
"""
self.bus.emit(message.reply("ovos.common_play.pong"))

def register_ocp_api_events(self):
"""
Register messagebus handlers for OCP events
"""
self.add_event("ovos.common_play.ping", self.handle_ping)
self.add_event('ovos.common_play.home', self.handle_home)
# bus api shared with intents
self.add_event("ovos.common_play.search", self.handle_play)

def handle_home(self):
def handle_home(self, message=None):
"""
Handle ovos.common_play.home Messages and show the homescreen
@param message: message associated with request
"""
# homescreen / launch from .desktop
self.gui.show_home(app_mode=True)

Expand Down Expand Up @@ -207,6 +219,10 @@ def classify_media(self, query):

# playback control intents
def handle_open(self, message):
"""
Handle open.intent
@param message: Message associated with intent match
"""
self.gui.show_home(app_mode=True)

def handle_next(self, message):
Expand All @@ -218,14 +234,23 @@ def handle_prev(self, message):
def handle_pause(self, message):
self.player.pause()

def handle_stop(self, message=None):
# will stop any playback in GUI and AudioService
try:
return self.player.stop()
except:
pass

def handle_resume(self, message):
"""Resume playback if paused"""
# TODO: Should this also handle "stopped"?
if self.player.state == PlayerState.PAUSED:
self.player.resume()
else:
LOG.info(f"Asked to resume while not paused. state={self.player.state}")
query = self.get_response("play.what")
if query:
message["utterance"] = query
message.data["utterance"] = query
self.handle_play(message)

def handle_play(self, message):
Expand Down Expand Up @@ -299,13 +324,6 @@ def _do_play(self, phrase, results, media_type=MediaType.GENERIC):
self.enclosure.mouth_reset() # TODO display music icon in mk1
self.set_context("Playing")

def handle_stop(self, message=None):
# will stop any playback in GUI and AudioService
try:
return self.player.stop()
except:
pass

# helper methods
def _search(self, phrase, utterance, media_type):
self.enclosure.mouth_think()
Expand Down Expand Up @@ -363,7 +381,13 @@ def _search(self, phrase, utterance, media_type):
LOG.debug(f"Returning {len(results)} results")
return results

def _should_resume(self, phrase):
def _should_resume(self, phrase: str) -> bool:
"""
Check if a "play" request should resume playback or be handled as a new
session.
@param phrase: Extracted playback phrase
@return: True if player should resume, False if this is a new request
"""
if self.player.state == PlayerState.PAUSED:
if not phrase.strip() or \
self.voc_match(phrase, "Resume", exact=True) or \
Expand Down
Loading